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 }
func TestGetTypeNameOf(t *testing.T) { assert.Equal(t, meta.TypeNameOf(Foo{}), "Foo") assert.Equal(t, meta.TypeNameOf(FooSlice{}), "FooSlice") assert.Equal(t, meta.TypeNameOf(&FooPTRSlice{}), "FooPTRSlice") }
func SQLTableNameOf(st interface{}) string { return snakecase.SnakeCase(meta.TypeNameOf(st)) }