示例#1
0
文件: read.go 项目: 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)
}
示例#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{}))
}