export InterpolateParams

This commit is contained in:
Alex Grintsvayg 2017-08-23 16:37:33 -04:00
parent 8837a986ee
commit 3abac13aeb
12 changed files with 19 additions and 19 deletions

View file

@ -40,7 +40,7 @@ func ({{$varNameSingular}}L) Load{{$txt.Function.Name}}(e boil.Executor, singula
) )
if boil.DebugMode { if boil.DebugMode {
qStr, err := interpolateParams(query, args...) qStr, err := InterpolateParams(query, args...)
if err != nil { if err != nil {
return err return err
} }

View file

@ -40,7 +40,7 @@ func ({{$varNameSingular}}L) Load{{$txt.Function.Name}}(e boil.Executor, singula
) )
if boil.DebugMode { if boil.DebugMode {
qStr, err := interpolateParams(query, args...) qStr, err := InterpolateParams(query, args...)
if err != nil { if err != nil {
return err return err
} }

View file

@ -49,7 +49,7 @@ func ({{$varNameSingular}}L) Load{{$txt.Function.Name}}(e boil.Executor, singula
{{end -}} {{end -}}
if boil.DebugMode { if boil.DebugMode {
qStr, err := interpolateParams(query, args...) qStr, err := InterpolateParams(query, args...)
if err != nil { if err != nil {
return err return err
} }

View file

@ -53,7 +53,7 @@ func (o *{{$txt.LocalTable.NameGo}}) Set{{$txt.Function.Name}}(exec boil.Executo
values := []interface{}{related.{{$txt.ForeignTable.ColumnNameGo}}, o.{{$dot.Table.PKey.Columns | stringMap $dot.StringFuncs.titleCase | join ", o."}}{{"}"}} values := []interface{}{related.{{$txt.ForeignTable.ColumnNameGo}}, o.{{$dot.Table.PKey.Columns | stringMap $dot.StringFuncs.titleCase | join ", o."}}{{"}"}}
if boil.DebugMode { if boil.DebugMode {
qStr, err := interpolateParams(updateQuery, values...) qStr, err := InterpolateParams(updateQuery, values...)
if err != nil { if err != nil {
return err return err
} }

View file

@ -59,7 +59,7 @@ func (o *{{$txt.LocalTable.NameGo}}) Set{{$txt.Function.Name}}(exec boil.Executo
values := []interface{}{o.{{$txt.LocalTable.ColumnNameGo}}, related.{{$foreignPKeyCols | stringMap $dot.StringFuncs.titleCase | join ", related."}}{{"}"}} values := []interface{}{o.{{$txt.LocalTable.ColumnNameGo}}, related.{{$foreignPKeyCols | stringMap $dot.StringFuncs.titleCase | join ", related."}}{{"}"}}
if boil.DebugMode { if boil.DebugMode {
qStr, err := interpolateParams(updateQuery, values...) qStr, err := InterpolateParams(updateQuery, values...)
if err != nil { if err != nil {
return err return err
} }

View file

@ -66,7 +66,7 @@ func (o *{{$txt.LocalTable.NameGo}}) Add{{$txt.Function.Name}}(exec boil.Executo
values := []interface{}{o.{{$txt.LocalTable.ColumnNameGo}}, rel.{{$foreignPKeyCols | stringMap $dot.StringFuncs.titleCase | join ", rel."}}{{"}"}} values := []interface{}{o.{{$txt.LocalTable.ColumnNameGo}}, rel.{{$foreignPKeyCols | stringMap $dot.StringFuncs.titleCase | join ", rel."}}{{"}"}}
if boil.DebugMode { if boil.DebugMode {
qStr, err := interpolateParams(updateQuery, values...) qStr, err := InterpolateParams(updateQuery, values...)
if err != nil { if err != nil {
return err return err
} }
@ -90,7 +90,7 @@ func (o *{{$txt.LocalTable.NameGo}}) Add{{$txt.Function.Name}}(exec boil.Executo
values := []interface{}{{"{"}}o.{{$txt.LocalTable.ColumnNameGo}}, rel.{{$txt.ForeignTable.ColumnNameGo}}} values := []interface{}{{"{"}}o.{{$txt.LocalTable.ColumnNameGo}}, rel.{{$txt.ForeignTable.ColumnNameGo}}}
if boil.DebugMode { if boil.DebugMode {
qStr, err := interpolateParams(query, values...) qStr, err := InterpolateParams(query, values...)
if err != nil { if err != nil {
return err return err
} }
@ -190,7 +190,7 @@ func (o *{{$txt.LocalTable.NameGo}}) Set{{$txt.Function.Name}}(exec boil.Executo
values := []interface{}{{"{"}}o.{{$txt.LocalTable.ColumnNameGo}}} values := []interface{}{{"{"}}o.{{$txt.LocalTable.ColumnNameGo}}}
{{end -}} {{end -}}
if boil.DebugMode { if boil.DebugMode {
qStr, err := interpolateParams(query, values...) qStr, err := InterpolateParams(query, values...)
if err != nil { if err != nil {
return err return err
} }
@ -269,7 +269,7 @@ func (o *{{$txt.LocalTable.NameGo}}) Remove{{$txt.Function.Name}}(exec boil.Exec
} }
if boil.DebugMode { if boil.DebugMode {
qStr, err := interpolateParams(query, values...) qStr, err := InterpolateParams(query, values...)
if err != nil { if err != nil {
return err return err
} }

View file

@ -98,7 +98,7 @@ func (o *{{$tableNameSingular}}) Insert(exec boil.Executor, whitelist ... string
vals := queries.ValuesFromMapping(value, cache.valueMapping) vals := queries.ValuesFromMapping(value, cache.valueMapping)
if boil.DebugMode { if boil.DebugMode {
qStr, err := interpolateParams(cache.query, vals...) qStr, err := InterpolateParams(cache.query, vals...)
if err != nil { if err != nil {
return err return err
} }
@ -147,7 +147,7 @@ func (o *{{$tableNameSingular}}) Insert(exec boil.Executor, whitelist ... string
} }
if boil.DebugMode { if boil.DebugMode {
qStr, err := interpolateParams(cache.retQuery, identifierCols...) qStr, err := InterpolateParams(cache.retQuery, identifierCols...)
if err != nil { if err != nil {
return err return err
} }

View file

@ -78,7 +78,7 @@ func (o *{{$tableNameSingular}}) Update(exec boil.Executor, whitelist ... string
values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)
if boil.DebugMode { if boil.DebugMode {
qStr, err := interpolateParams(cache.query, values...) qStr, err := InterpolateParams(cache.query, values...)
if err != nil { if err != nil {
return err return err
} }
@ -173,7 +173,7 @@ func (o {{$tableNameSingular}}Slice) UpdateAll(exec boil.Executor, cols M) error
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), {{if .Dialect.IndexPlaceholders}}len(colNames)+1{{else}}0{{end}}, {{$varNameSingular}}PrimaryKeyColumns, len(o))) strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), {{if .Dialect.IndexPlaceholders}}len(colNames)+1{{else}}0{{end}}, {{$varNameSingular}}PrimaryKeyColumns, len(o)))
if boil.DebugMode { if boil.DebugMode {
qStr, err := interpolateParams(sql, args...) qStr, err := InterpolateParams(sql, args...)
if err != nil { if err != nil {
return err return err
} }

View file

@ -147,7 +147,7 @@ func (o *{{$tableNameSingular}}) Upsert(exec boil.Executor, {{if eq .DriverName
} }
if boil.DebugMode { if boil.DebugMode {
qStr, err := interpolateParams(cache.query, vals...) qStr, err := InterpolateParams(cache.query, vals...)
if err != nil { if err != nil {
return err return err
} }
@ -196,7 +196,7 @@ func (o *{{$tableNameSingular}}) Upsert(exec boil.Executor, {{if eq .DriverName
} }
if boil.DebugMode { if boil.DebugMode {
qStr, err := interpolateParams(cache.retQuery, identifierCols...) qStr, err := InterpolateParams(cache.retQuery, identifierCols...)
if err != nil { if err != nil {
return err return err
} }

View file

@ -46,7 +46,7 @@ func (o *{{$tableNameSingular}}) Delete(exec boil.Executor) error {
sql := "DELETE FROM {{$schemaTable}} WHERE {{if .Dialect.IndexPlaceholders}}{{whereClause .LQ .RQ 1 .Table.PKey.Columns}}{{else}}{{whereClause .LQ .RQ 0 .Table.PKey.Columns}}{{end}}" sql := "DELETE FROM {{$schemaTable}} WHERE {{if .Dialect.IndexPlaceholders}}{{whereClause .LQ .RQ 1 .Table.PKey.Columns}}{{else}}{{whereClause .LQ .RQ 0 .Table.PKey.Columns}}{{end}}"
if boil.DebugMode { if boil.DebugMode {
qStr, err := interpolateParams(sql, args...) qStr, err := InterpolateParams(sql, args...)
if err != nil { if err != nil {
return err return err
} }
@ -142,7 +142,7 @@ func (o {{$tableNameSingular}}Slice) DeleteAll(exec boil.Executor) error {
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), {{if .Dialect.IndexPlaceholders}}1{{else}}0{{end}}, {{$varNameSingular}}PrimaryKeyColumns, len(o)) strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), {{if .Dialect.IndexPlaceholders}}1{{else}}0{{end}}, {{$varNameSingular}}PrimaryKeyColumns, len(o))
if boil.DebugMode { if boil.DebugMode {
qStr, err := interpolateParams(sql, args...) qStr, err := InterpolateParams(sql, args...)
if err != nil { if err != nil {
return err return err
} }

View file

@ -14,7 +14,7 @@ func {{$tableNameSingular}}Exists(exec boil.Executor, {{$pkArgs}}) (bool, error)
{{- end}} {{- end}}
if boil.DebugMode { if boil.DebugMode {
qStr, err := interpolateParams(sql, {{$pkNames | join ", "}}) qStr, err := InterpolateParams(sql, {{$pkNames | join ", "}})
if err != nil { if err != nil {
return false, err return false, err
} }

View file

@ -138,7 +138,7 @@ func checkMerge(tx *sql.Tx, foreignKeys []foreignKey) error {
} }
// duplicated in queries/query.go // duplicated in queries/query.go
func interpolateParams(query string, args ...interface{}) (string, error) { func InterpolateParams(query string, args ...interface{}) (string, error) {
for i := 0; i < len(args); i++ { for i := 0; i < len(args); i++ {
field := reflect.ValueOf(args[i]) field := reflect.ValueOf(args[i])