func TestIsSlice(t *testing.T) { assert.False(t, meta.IsSlice(123)) assert.False(t, meta.IsSlice("yo")) assert.False(t, meta.IsSlice(Foo{})) assert.True(t, meta.IsSlice(FooSlice{})) assert.True(t, meta.IsSlice(&FooSlice{})) assert.True(t, meta.IsSlice(FooPTRSlice{})) assert.True(t, meta.IsSlice(&FooPTRSlice{})) }
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) }
func NewTable(any interface{}) (*Table, error) { if meta.IsSlice(any) { any = meta.CreateElement(any).Interface() } fields, err := GetFieldsOf(any) if err != nil { return nil, err } SetDefaultPK(fields) name := meta.TypeNameOf(any) return &Table{ Name: name, SQLName: snakecase.SnakeCase(name), Fields: fields, }, nil }