Rewrite Find using normal sql

This commit is contained in:
Aaron L 2016-08-07 23:36:11 -07:00
parent 444153222b
commit 44cf647d05
2 changed files with 18 additions and 6 deletions

View file

@ -51,6 +51,16 @@ type join struct {
args []interface{}
}
// SQL makes a plainSQL query, usually for use with bind
func SQL(query string, args ...interface{}) *Query {
return &Query{
plainSQL: plainSQL{
sql: query,
args: args,
},
}
}
// ExecQuery executes a query that does not need a row returned
func ExecQuery(q *Query) (sql.Result, error) {
qs, args := buildQuery(q)

View file

@ -24,13 +24,15 @@ func {{$tableNameSingular}}FindGP({{$pkArgs}}, selectCols ...string) *{{$tableNa
func {{$tableNameSingular}}Find(exec boil.Executor, {{$pkArgs}}, selectCols ...string) (*{{$tableNameSingular}}, error) {
{{$varNameSingular}} := &{{$tableNameSingular}}{}
mods := []qm.QueryMod{
qm.Select(selectCols...),
qm.From("{{.Table.Name}}"),
qm.Where(`{{whereClause .Table.PKey.Columns 1}}`, {{$pkNames | join ", "}}),
sel := "*"
if len(selectCols) > 0 {
sel = strings.Join(strmangle.IdentQuoteSlice(selectCols), ",")
}
q := NewQuery(exec, mods...)
sql := fmt.Sprintf(
`select %s from "{{.Table.Name}}" where {{whereClause .Table.PKey.Columns 1}}`, sel,
)
q := boil.SQL(sql, {{$pkNames | join ", "}})
boil.SetExecutor(q, exec)
err := q.Bind({{$varNameSingular}})
if err != nil {