Esempio n. 1
0
File: read.go Progetto: rjp/crud
func Read(query QueryFn, scanTo interface{}, allparams []interface{}) error {
	sql, params, err := ResolveReadParams(allparams)
	if err != nil {
		return err
	}

	if !meta.IsPointer(scanTo) {
		return errors.New("A pointer has to be passed for scanning rows to.")
	}

	if meta.IsSlice(scanTo) {
		return ReadAll(query, scanTo, sql, params)
	}

	return ReadOne(query, scanTo, sql, params)
}
Esempio n. 2
0
func TestIsPointer(t *testing.T) {
	assert.True(t, meta.IsPointer(&Foo{}))
	assert.True(t, meta.IsPointer(&[]Foo{}))
	assert.False(t, meta.IsPointer(Foo{}))
	assert.False(t, meta.IsPointer(*&Foo{}))
}