func TestCreateElement(t *testing.T) { assert.Equal(t, meta.DirectTypeOf(meta.CreateElement([]Foo{}).Interface()).String(), "meta_test.Foo") assert.Equal(t, meta.DirectTypeOf(meta.CreateElement([]*Foo{}).Interface()).String(), "*meta_test.Foo") assert.Equal(t, meta.DirectTypeOf(meta.CreateElement(&[]Foo{}).Interface()).String(), "meta_test.Foo") assert.Equal(t, meta.DirectTypeOf(meta.CreateElement(&[]*Foo{}).Interface()).String(), "*meta_test.Foo") assert.Equal(t, meta.DirectTypeOf(meta.CreateElement(FooPTRSlice{}).Interface()).String(), "*meta_test.Foo") assert.Equal(t, meta.DirectTypeOf(meta.CreateElement(&FooPTRSlice{}).Interface()).String(), "*meta_test.Foo") assert.Equal(t, meta.DirectTypeOf(meta.CreateElement([]string{}).Interface()).String(), "string") }
func (scan *Scan) All(rows *sql.Rows) error { writeTo := meta.Addressable(scan.To) for rows.Next() { record := meta.CreateElement(scan.To) if err := scan.Scan(rows, record); err != nil { return err } meta.Push(writeTo, record) } return nil }
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 }