Rewrite Find using normal sql
This commit is contained in:
parent
444153222b
commit
44cf647d05
2 changed files with 18 additions and 6 deletions
|
@ -51,6 +51,16 @@ type join struct {
|
||||||
args []interface{}
|
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
|
// ExecQuery executes a query that does not need a row returned
|
||||||
func ExecQuery(q *Query) (sql.Result, error) {
|
func ExecQuery(q *Query) (sql.Result, error) {
|
||||||
qs, args := buildQuery(q)
|
qs, args := buildQuery(q)
|
||||||
|
|
|
@ -24,13 +24,15 @@ func {{$tableNameSingular}}FindGP({{$pkArgs}}, selectCols ...string) *{{$tableNa
|
||||||
func {{$tableNameSingular}}Find(exec boil.Executor, {{$pkArgs}}, selectCols ...string) (*{{$tableNameSingular}}, error) {
|
func {{$tableNameSingular}}Find(exec boil.Executor, {{$pkArgs}}, selectCols ...string) (*{{$tableNameSingular}}, error) {
|
||||||
{{$varNameSingular}} := &{{$tableNameSingular}}{}
|
{{$varNameSingular}} := &{{$tableNameSingular}}{}
|
||||||
|
|
||||||
mods := []qm.QueryMod{
|
sel := "*"
|
||||||
qm.Select(selectCols...),
|
if len(selectCols) > 0 {
|
||||||
qm.From("{{.Table.Name}}"),
|
sel = strings.Join(strmangle.IdentQuoteSlice(selectCols), ",")
|
||||||
qm.Where(`{{whereClause .Table.PKey.Columns 1}}`, {{$pkNames | join ", "}}),
|
|
||||||
}
|
}
|
||||||
|
sql := fmt.Sprintf(
|
||||||
q := NewQuery(exec, mods...)
|
`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}})
|
err := q.Bind({{$varNameSingular}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue