Skip to content

Commit

Permalink
Rename 'toPrimitive' function to be more descriptive
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico De Giuli committed Aug 16, 2022
1 parent 3674e02 commit ee0ed02
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
10 changes: 5 additions & 5 deletions boilingcore/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,11 @@ var templateFunctions = template.FuncMap{
"whereClause": strmangle.WhereClause,

// Alias and text helping
"aliasCols": func(ta TableAlias) func(string) string { return ta.Column },
"usesPrimitives": usesPrimitives,
"isPrimitive": isPrimitive,
"isNullPrimitive": isNullPrimitive,
"toPrimitive": toPrimitive,
"aliasCols": func(ta TableAlias) func(string) string { return ta.Column },
"usesPrimitives": usesPrimitives,
"isPrimitive": isPrimitive,
"isNullPrimitive": isNullPrimitive,
"convertNullToPrimitive": convertNullToPrimitive,
"splitLines": func(a string) []string {
if a == "" {
return nil
Expand Down
5 changes: 2 additions & 3 deletions boilingcore/text_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,11 @@ func isNullPrimitive(typ string) bool {
return false
}

// toPrimitive takes a type name and returns the underlying primitive type name X if it is a `null.X`,
// convertNullToPrimitive takes a type name and returns the underlying primitive type name X if it is a `null.X`,
// otherwise it returns the input value unchanged
func toPrimitive(typ string) string {
func convertNullToPrimitive(typ string) string {
if isNullPrimitive(typ) {
return strings.ToLower(strings.Split(typ, ".")[1])
}
return typ
}

4 changes: 2 additions & 2 deletions templates/main/00_struct.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ func (w {{$name}}) LTE(x {{.Type}}) qm.QueryMod { return qmhelper.Where(w.field,
func (w {{$name}}) GT(x {{.Type}}) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) }
func (w {{$name}}) GTE(x {{.Type}}) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) }
{{if or (isPrimitive .Type) (isNullPrimitive .Type) (isEnumDBType .DBType) -}}
func (w {{$name}}) IN(slice []{{toPrimitive .Type}}) qm.QueryMod {
func (w {{$name}}) IN(slice []{{convertNullToPrimitive .Type}}) qm.QueryMod {
values := make([]interface{}, 0, len(slice))
for _, value := range slice {
values = append(values, value)
}
return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...)
}
func (w {{$name}}) NIN(slice []{{toPrimitive .Type}}) qm.QueryMod {
func (w {{$name}}) NIN(slice []{{convertNullToPrimitive .Type}}) qm.QueryMod {
values := make([]interface{}, 0, len(slice))
for _, value := range slice {
values = append(values, value)
Expand Down

0 comments on commit ee0ed02

Please sign in to comment.