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 (iteration *FieldIteration) SQLOptions() (*sql.Options, error) { result, err := sql.NewOptions(iteration.TypeField().Tag.Get("sql")) if err != nil { return nil, err } if len(result.Name) == 0 { result.Name = snakecase.SnakeCase(iteration.Name()) } if len(result.Type) == 0 { sqlType, err := sql.MatchType(iteration.TypeField().Type.String()) if err != nil { return nil, err } result.Type = sqlType result.Length = sql.Types[result.Type] } return result, nil }
func SQLTableNameOf(st interface{}) string { return snakecase.SnakeCase(meta.TypeNameOf(st)) }
// transform from filterCamelCase to camel_case func filterName(name string) string { return snakecase.SnakeCase(strings.TrimPrefix(name, filterPrefix)) }