Fix debug outputs for all templates

This commit is contained in:
Patrick O'brien 2016-08-14 02:58:18 +10:00
parent 7ae9af702f
commit 8831e8a4b9
6 changed files with 28 additions and 31 deletions

View file

@ -31,6 +31,7 @@ func {{$tableNameSingular}}Find(exec boil.Executor, {{$pkArgs}}, selectCols ...s
sql := fmt.Sprintf( sql := fmt.Sprintf(
`select %s from "{{.Table.Name}}" where {{whereClause 1 .Table.PKey.Columns}}`, sel, `select %s from "{{.Table.Name}}" where {{whereClause 1 .Table.PKey.Columns}}`, sel,
) )
q := boil.SQL(sql, {{$pkNames | join ", "}}) q := boil.SQL(sql, {{$pkNames | join ", "}})
boil.SetExecutor(q, exec) boil.SetExecutor(q, exec)

View file

@ -47,16 +47,17 @@ func (o *{{$tableNameSingular}}) Update(exec boil.Executor, whitelist ... string
query = fmt.Sprintf(`UPDATE {{.Table.Name}} SET %s WHERE %s`, strmangle.SetParamNames(wl), strmangle.WhereClause(len(wl)+1, {{$varNameSingular}}PrimaryKeyColumns)) query = fmt.Sprintf(`UPDATE {{.Table.Name}} SET %s WHERE %s`, strmangle.SetParamNames(wl), strmangle.WhereClause(len(wl)+1, {{$varNameSingular}}PrimaryKeyColumns))
values = boil.GetStructValues(o, wl...) values = boil.GetStructValues(o, wl...)
values = append(values, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}}) values = append(values, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}})
_, err = exec.Exec(query, values...)
} else {
return fmt.Errorf("{{.PkgName}}: unable to update {{.Table.Name}}, could not build whitelist")
}
if boil.DebugMode { if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, query) fmt.Fprintln(boil.DebugWriter, query)
fmt.Fprintln(boil.DebugWriter, values) fmt.Fprintln(boil.DebugWriter, values)
} }
_, err = exec.Exec(query, values...)
} else {
return fmt.Errorf("{{.PkgName}}: unable to update {{.Table.Name}}, could not build whitelist")
}
if err != nil { if err != nil {
return fmt.Errorf("{{.PkgName}}: unable to update {{.Table.Name}} row: %s", err) return fmt.Errorf("{{.PkgName}}: unable to update {{.Table.Name}} row: %s", err)
} }
@ -137,10 +138,12 @@ func (o {{$tableNameSingular}}Slice) UpdateAll(exec boil.Executor, cols M) error
strmangle.Placeholders(len(o) * len({{$varNameSingular}}PrimaryKeyColumns), len(colNames)+1, len({{$varNameSingular}}PrimaryKeyColumns)), strmangle.Placeholders(len(o) * len({{$varNameSingular}}PrimaryKeyColumns), len(colNames)+1, len({{$varNameSingular}}PrimaryKeyColumns)),
) )
q := boil.SQL(sql, args...) if boil.DebugMode {
boil.SetExecutor(q, exec) fmt.Fprintln(boil.DebugWriter, sql)
fmt.Fprintln(boil.DebugWriter, args...)
}
_, err := boil.ExecQuery(q) _, err := exec.Exec(sql, args...)
if err != nil { if err != nil {
return fmt.Errorf("{{.PkgName}}: unable to update all in {{$varNameSingular}} slice: %s", err) return fmt.Errorf("{{.PkgName}}: unable to update all in {{$varNameSingular}} slice: %s", err)
} }

View file

@ -34,17 +34,17 @@ func (o *{{$tableNameSingular}}) Upsert(exec boil.Executor, update bool, conflic
return err return err
} }
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, query)
fmt.Fprintln(boil.DebugWriter, boil.GetStructValues(o, columns.whitelist...))
}
if len(columns.returning) != 0 { if len(columns.returning) != 0 {
err = exec.QueryRow(query, boil.GetStructValues(o, columns.whitelist...)...).Scan(boil.GetStructPointers(o, columns.returning...)...) err = exec.QueryRow(query, boil.GetStructValues(o, columns.whitelist...)...).Scan(boil.GetStructPointers(o, columns.returning...)...)
} else { } else {
_, err = exec.Exec(query, {{.Table.Columns | columnNames | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}}) _, err = exec.Exec(query, {{.Table.Columns | columnNames | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}})
} }
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, query)
fmt.Fprintln(boil.DebugWriter, boil.GetStructValues(o, columns.whitelist...))
}
if err != nil { if err != nil {
return fmt.Errorf("{{.PkgName}}: unable to upsert for {{.Table.Name}}: %s", err) return fmt.Errorf("{{.PkgName}}: unable to upsert for {{.Table.Name}}: %s", err)
} }

View file

@ -116,18 +116,15 @@ func (o {{$tableNameSingular}}Slice) DeleteAll(exec boil.Executor) error {
strmangle.Placeholders(len(o) * len({{$varNameSingular}}PrimaryKeyColumns), 1, len({{$varNameSingular}}PrimaryKeyColumns)), strmangle.Placeholders(len(o) * len({{$varNameSingular}}PrimaryKeyColumns), 1, len({{$varNameSingular}}PrimaryKeyColumns)),
) )
q := boil.SQL(sql, args...)
boil.SetExecutor(q, exec)
_, err := boil.ExecQuery(q)
if err != nil {
return fmt.Errorf("{{.PkgName}}: unable to delete all from {{$varNameSingular}} slice: %s", err)
}
if boil.DebugMode { if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, sql) fmt.Fprintln(boil.DebugWriter, sql)
fmt.Fprintln(boil.DebugWriter, args) fmt.Fprintln(boil.DebugWriter, args)
} }
_, err := exec.Exec(sql, args...)
if err != nil {
return fmt.Errorf("{{.PkgName}}: unable to delete all from {{$varNameSingular}} slice: %s", err)
}
return nil return nil
} }

View file

@ -86,10 +86,5 @@ func (o *{{$tableNameSingular}}Slice) ReloadAll(exec boil.Executor) error {
*o = {{$varNamePlural}} *o = {{$varNamePlural}}
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, sql)
fmt.Fprintln(boil.DebugWriter, args)
}
return nil return nil
} }

View file

@ -7,6 +7,12 @@ func {{$tableNameSingular}}Exists(exec boil.Executor, {{$pkArgs}}) (bool, error)
var exists bool var exists bool
sql := `select exists(select 1 from "{{.Table.Name}}" where {{whereClause 1 .Table.PKey.Columns}} limit 1)` sql := `select exists(select 1 from "{{.Table.Name}}" where {{whereClause 1 .Table.PKey.Columns}} limit 1)`
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, sql)
fmt.Fprintln(boil.DebugWriter, {{$pkNames | join ", "}})
}
row := exec.QueryRow( row := exec.QueryRow(
sql, sql,
{{$pkNames | join ", "}}, {{$pkNames | join ", "}},
@ -17,11 +23,6 @@ func {{$tableNameSingular}}Exists(exec boil.Executor, {{$pkArgs}}) (bool, error)
return false, fmt.Errorf("{{.PkgName}}: unable to check if {{.Table.Name}} exists: %v", err) return false, fmt.Errorf("{{.PkgName}}: unable to check if {{.Table.Name}} exists: %v", err)
} }
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, sql)
fmt.Fprintln(boil.DebugWriter, {{$pkNames | join ", "}})
}
return exists, nil return exists, nil
} }