Fix up the interface to raw queries.

This commit is contained in:
Aaron L 2016-09-14 20:57:07 -07:00
parent 5149df8359
commit 12967f7b66
4 changed files with 26 additions and 26 deletions

View file

@ -24,7 +24,7 @@ type Interface interface {
Close() Close()
// Dialect helpers, these provide the values that will go into // Dialect helpers, these provide the values that will go into
// a boil.Dialect, so the query builder knows how to support // a queries.Dialect, so the query builder knows how to support
// your database driver properly. // your database driver properly.
LeftQuote() byte LeftQuote() byte
RightQuote() byte RightQuote() byte

View file

@ -22,7 +22,7 @@ const (
type Query struct { type Query struct {
executor boil.Executor executor boil.Executor
dialect *Dialect dialect *Dialect
plainSQL plainSQL rawSQL rawSQL
load []string load []string
delete bool delete bool
update map[string]interface{} update map[string]interface{}
@ -71,7 +71,7 @@ type having struct {
args []interface{} args []interface{}
} }
type plainSQL struct { type rawSQL struct {
sql string sql string
args []interface{} args []interface{}
} }
@ -82,20 +82,20 @@ type join struct {
args []interface{} args []interface{}
} }
// SQL makes a plainSQL query, usually for use with bind // Raw makes a raw query, usually for use with bind
func SQL(exec boil.Executor, query string, args ...interface{}) *Query { func Raw(exec boil.Executor, query string, args ...interface{}) *Query {
return &Query{ return &Query{
executor: exec, executor: exec,
plainSQL: plainSQL{ rawSQL: rawSQL{
sql: query, sql: query,
args: args, args: args,
}, },
} }
} }
// SQLG makes a plainSQL query using the global boil.Executor, usually for use with bind // RawG makes a raw query using the global boil.Executor, usually for use with bind
func SQLG(query string, args ...interface{}) *Query { func RawG(query string, args ...interface{}) *Query {
return SQL(boil.GetDB(), query, args...) return Raw(boil.GetDB(), query, args...)
} }
// Exec executes a query that does not need a row returned // Exec executes a query that does not need a row returned
@ -167,7 +167,7 @@ func SetDialect(q *Query, dialect *Dialect) {
// SetSQL on the query. // SetSQL on the query.
func SetSQL(q *Query, sql string, args ...interface{}) { func SetSQL(q *Query, sql string, args ...interface{}) {
q.plainSQL = plainSQL{sql: sql, args: args} q.rawSQL = rawSQL{sql: sql, args: args}
} }
// SetLoad on the query. // SetLoad on the query.

View file

@ -20,8 +20,8 @@ func buildQuery(q *Query) (string, []interface{}) {
var args []interface{} var args []interface{}
switch { switch {
case len(q.plainSQL.sql) != 0: case len(q.rawSQL.sql) != 0:
return q.plainSQL.sql, q.plainSQL.args return q.rawSQL.sql, q.rawSQL.args
case q.delete: case q.delete:
buf, args = buildDeleteQuery(q) buf, args = buildDeleteQuery(q)
case len(q.update) > 0: case len(q.update) > 0:
@ -34,8 +34,8 @@ func buildQuery(q *Query) (string, []interface{}) {
// Cache the generated query for query object re-use // Cache the generated query for query object re-use
bufStr := buf.String() bufStr := buf.String()
q.plainSQL.sql = bufStr q.rawSQL.sql = bufStr
q.plainSQL.args = args q.rawSQL.args = args
return bufStr, args return bufStr, args
} }

View file

@ -36,12 +36,12 @@ func TestSetSQL(t *testing.T) {
q := &Query{} q := &Query{}
SetSQL(q, "select * from thing", 5, 3) SetSQL(q, "select * from thing", 5, 3)
if len(q.plainSQL.args) != 2 { if len(q.rawSQL.args) != 2 {
t.Errorf("Expected len 2, got %d", len(q.plainSQL.args)) t.Errorf("Expected len 2, got %d", len(q.rawSQL.args))
} }
if q.plainSQL.sql != "select * from thing" { if q.rawSQL.sql != "select * from thing" {
t.Errorf("Was not expected string, got %s", q.plainSQL.sql) t.Errorf("Was not expected string, got %s", q.rawSQL.sql)
} }
} }
@ -374,11 +374,11 @@ func TestSQL(t *testing.T) {
t.Parallel() t.Parallel()
q := SQL(&sql.DB{}, "thing", 5) q := SQL(&sql.DB{}, "thing", 5)
if q.plainSQL.sql != "thing" { if q.rawSQL.sql != "thing" {
t.Errorf("Expected %q, got %s", "thing", q.plainSQL.sql) t.Errorf("Expected %q, got %s", "thing", q.rawSQL.sql)
} }
if q.plainSQL.args[0].(int) != 5 { if q.rawSQL.args[0].(int) != 5 {
t.Errorf("Expected 5, got %v", q.plainSQL.args[0]) t.Errorf("Expected 5, got %v", q.rawSQL.args[0])
} }
} }
@ -386,11 +386,11 @@ func TestSQLG(t *testing.T) {
t.Parallel() t.Parallel()
q := SQLG("thing", 5) q := SQLG("thing", 5)
if q.plainSQL.sql != "thing" { if q.rawSQL.sql != "thing" {
t.Errorf("Expected %q, got %s", "thing", q.plainSQL.sql) t.Errorf("Expected %q, got %s", "thing", q.rawSQL.sql)
} }
if q.plainSQL.args[0].(int) != 5 { if q.rawSQL.args[0].(int) != 5 {
t.Errorf("Expected 5, got %v", q.plainSQL.args[0]) t.Errorf("Expected 5, got %v", q.rawSQL.args[0])
} }
} }