Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Field = map[string]func(*Source, reflect.StructField, int) string{ "%Name": getName, "%Type": getType, "%With": func(src *Source, field reflect.StructField, index int) string { if field.Name == "Id" { return fmt.Sprintf("PRIMARY KEY %s", field.Tag.Get("with")) } return field.Tag.Get("with") }, "%Tags": func(src *Source, field reflect.StructField, index int) string { return fmt.Sprintf("%v", field.Tag) }, "%Value": func(src *Source, field reflect.StructField, index int) string { if src.V.Field(index).Kind() == reflect.Struct { table := registry.Tables[strcase.SnakeCase(strings.ReplaceAll(field.Name, "Fk", ""))] tableValue := reflect.ValueOf(table) return fmt.Sprintf("%v", tableValue.FieldByName("Id")) } if src.V.Field(index).Kind() == reflect.String { return fmt.Sprintf("%q", src.V.Field(index).Interface()) } if field.Tag.Get("type") == "timestamp" { return fmt.Sprintf("FROM_UNIXTIME(%v)", src.V.Field(index).Interface()) } return fmt.Sprintf("%v", src.V.Field(index).Interface()) }, "%RawName": func(src *Source, field reflect.StructField, index int) string { return field.Name }, "%Variable": func(src *Source, field reflect.StructField, index int) string { return field.Type.Name() }, "%SQLType": func(src *Source, field reflect.StructField, index int) string { t := getType(src, field, index) t = strings.ReplaceAll(t, "boolean", "tinyint(1)") return t }, "%SQLName": func(src *Source, field reflect.StructField, index int) string { name := getName(src, field, index) switch getType(src, field, index) { case "timestamp": return fmt.Sprintf("UNIX_TIMESTAMP(%s)", name) } return name }, }
All available field formattings.
Functions ¶
func GetSQLWith ¶
Replace all keywords with how they are stored in the actual database.
Types ¶
type Source ¶
Represents source of a certain variable.
func (Source) DefinedFields ¶
Get all fields that were explicitly specified.
func (Source) FieldsContain ¶
Check if formatted fields contain the specified value.
func (*Source) FormatField ¶
Formats the field based on source.Format.
Click to show internal directories.
Click to hide internal directories.