Change Exec funcs to methods with Query receiver

This commit is contained in:
Patrick O'brien 2016-09-13 19:46:32 +10:00
parent 1facccacc1
commit 91bb5ee940
5 changed files with 8 additions and 8 deletions

View file

@ -97,7 +97,7 @@ func SQLG(query string, args ...interface{}) *Query {
} }
// 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 (q *Query) ExecQuery() (sql.Result, error) {
qs, args := buildQuery(q) qs, args := buildQuery(q)
if DebugMode { if DebugMode {
fmt.Fprintln(DebugWriter, qs) fmt.Fprintln(DebugWriter, qs)
@ -107,7 +107,7 @@ func ExecQuery(q *Query) (sql.Result, error) {
} }
// ExecQueryOne executes the query for the One finisher and returns a row // ExecQueryOne executes the query for the One finisher and returns a row
func ExecQueryOne(q *Query) *sql.Row { func (q *Query) ExecQueryOne() *sql.Row {
qs, args := buildQuery(q) qs, args := buildQuery(q)
if DebugMode { if DebugMode {
fmt.Fprintln(DebugWriter, qs) fmt.Fprintln(DebugWriter, qs)
@ -117,7 +117,7 @@ func ExecQueryOne(q *Query) *sql.Row {
} }
// ExecQueryAll executes the query for the All finisher and returns multiple rows // ExecQueryAll executes the query for the All finisher and returns multiple rows
func ExecQueryAll(q *Query) (*sql.Rows, error) { func (q *Query) ExecQueryAll() (*sql.Rows, error) {
qs, args := buildQuery(q) qs, args := buildQuery(q)
if DebugMode { if DebugMode {
fmt.Fprintln(DebugWriter, qs) fmt.Fprintln(DebugWriter, qs)

View file

@ -100,7 +100,7 @@ func (q *Query) Bind(obj interface{}) error {
return err return err
} }
rows, err := ExecQueryAll(q) rows, err := q.ExecQueryAll()
if err != nil { if err != nil {
return errors.Wrap(err, "bind failed to execute query") return errors.Wrap(err, "bind failed to execute query")
} }

View file

@ -82,7 +82,7 @@ func (q {{$varNameSingular}}Query) Count() (int64, error) {
boil.SetSelect(q.Query, nil) boil.SetSelect(q.Query, nil)
boil.SetCount(q.Query) boil.SetCount(q.Query)
err := boil.ExecQueryOne(q.Query).Scan(&count) err := q.Query.ExecQueryOne().Scan(&count)
if err != nil { if err != nil {
return 0, errors.Wrap(err, "{{.PkgName}}: failed to count {{.Table.Name}} rows") return 0, errors.Wrap(err, "{{.PkgName}}: failed to count {{.Table.Name}} rows")
} }
@ -107,7 +107,7 @@ func (q {{$varNameSingular}}Query) Exists() (bool, error) {
boil.SetCount(q.Query) boil.SetCount(q.Query)
boil.SetLimit(q.Query, 1) boil.SetLimit(q.Query, 1)
err := boil.ExecQueryOne(q.Query).Scan(&count) err := q.Query.ExecQueryOne().Scan(&count)
if err != nil { if err != nil {
return false, errors.Wrap(err, "{{.PkgName}}: failed to check if {{.Table.Name}} exists") return false, errors.Wrap(err, "{{.PkgName}}: failed to check if {{.Table.Name}} exists")
} }

View file

@ -107,7 +107,7 @@ func (q {{$varNameSingular}}Query) UpdateAllP(cols M) {
func (q {{$varNameSingular}}Query) UpdateAll(cols M) error { func (q {{$varNameSingular}}Query) UpdateAll(cols M) error {
boil.SetUpdate(q.Query, cols) boil.SetUpdate(q.Query, cols)
_, err := boil.ExecQuery(q.Query) _, err := q.Query.ExecQuery()
if err != nil { if err != nil {
return errors.Wrap(err, "{{.PkgName}}: unable to update all for {{.Table.Name}}") return errors.Wrap(err, "{{.PkgName}}: unable to update all for {{.Table.Name}}")
} }

View file

@ -80,7 +80,7 @@ func (q {{$varNameSingular}}Query) DeleteAll() error {
boil.SetDelete(q.Query) boil.SetDelete(q.Query)
_, err := boil.ExecQuery(q.Query) _, err := q.Query.ExecQuery()
if err != nil { if err != nil {
return errors.Wrap(err, "{{.PkgName}}: unable to delete all from {{.Table.Name}}") return errors.Wrap(err, "{{.PkgName}}: unable to delete all from {{.Table.Name}}")
} }