Fix up the interface to raw queries.
This commit is contained in:
parent
5149df8359
commit
12967f7b66
4 changed files with 26 additions and 26 deletions
|
@ -24,7 +24,7 @@ type Interface interface {
|
|||
Close()
|
||||
|
||||
// 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.
|
||||
LeftQuote() byte
|
||||
RightQuote() byte
|
||||
|
|
|
@ -22,7 +22,7 @@ const (
|
|||
type Query struct {
|
||||
executor boil.Executor
|
||||
dialect *Dialect
|
||||
plainSQL plainSQL
|
||||
rawSQL rawSQL
|
||||
load []string
|
||||
delete bool
|
||||
update map[string]interface{}
|
||||
|
@ -71,7 +71,7 @@ type having struct {
|
|||
args []interface{}
|
||||
}
|
||||
|
||||
type plainSQL struct {
|
||||
type rawSQL struct {
|
||||
sql string
|
||||
args []interface{}
|
||||
}
|
||||
|
@ -82,20 +82,20 @@ type join struct {
|
|||
args []interface{}
|
||||
}
|
||||
|
||||
// SQL makes a plainSQL query, usually for use with bind
|
||||
func SQL(exec boil.Executor, query string, args ...interface{}) *Query {
|
||||
// Raw makes a raw query, usually for use with bind
|
||||
func Raw(exec boil.Executor, query string, args ...interface{}) *Query {
|
||||
return &Query{
|
||||
executor: exec,
|
||||
plainSQL: plainSQL{
|
||||
rawSQL: rawSQL{
|
||||
sql: query,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// SQLG makes a plainSQL query using the global boil.Executor, usually for use with bind
|
||||
func SQLG(query string, args ...interface{}) *Query {
|
||||
return SQL(boil.GetDB(), query, args...)
|
||||
// RawG makes a raw query using the global boil.Executor, usually for use with bind
|
||||
func RawG(query string, args ...interface{}) *Query {
|
||||
return Raw(boil.GetDB(), query, args...)
|
||||
}
|
||||
|
||||
// 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.
|
||||
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.
|
||||
|
|
|
@ -20,8 +20,8 @@ func buildQuery(q *Query) (string, []interface{}) {
|
|||
var args []interface{}
|
||||
|
||||
switch {
|
||||
case len(q.plainSQL.sql) != 0:
|
||||
return q.plainSQL.sql, q.plainSQL.args
|
||||
case len(q.rawSQL.sql) != 0:
|
||||
return q.rawSQL.sql, q.rawSQL.args
|
||||
case q.delete:
|
||||
buf, args = buildDeleteQuery(q)
|
||||
case len(q.update) > 0:
|
||||
|
@ -34,8 +34,8 @@ func buildQuery(q *Query) (string, []interface{}) {
|
|||
|
||||
// Cache the generated query for query object re-use
|
||||
bufStr := buf.String()
|
||||
q.plainSQL.sql = bufStr
|
||||
q.plainSQL.args = args
|
||||
q.rawSQL.sql = bufStr
|
||||
q.rawSQL.args = args
|
||||
|
||||
return bufStr, args
|
||||
}
|
||||
|
|
|
@ -36,12 +36,12 @@ func TestSetSQL(t *testing.T) {
|
|||
q := &Query{}
|
||||
SetSQL(q, "select * from thing", 5, 3)
|
||||
|
||||
if len(q.plainSQL.args) != 2 {
|
||||
t.Errorf("Expected len 2, got %d", len(q.plainSQL.args))
|
||||
if len(q.rawSQL.args) != 2 {
|
||||
t.Errorf("Expected len 2, got %d", len(q.rawSQL.args))
|
||||
}
|
||||
|
||||
if q.plainSQL.sql != "select * from thing" {
|
||||
t.Errorf("Was not expected string, got %s", q.plainSQL.sql)
|
||||
if q.rawSQL.sql != "select * from thing" {
|
||||
t.Errorf("Was not expected string, got %s", q.rawSQL.sql)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -374,11 +374,11 @@ func TestSQL(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
q := SQL(&sql.DB{}, "thing", 5)
|
||||
if q.plainSQL.sql != "thing" {
|
||||
t.Errorf("Expected %q, got %s", "thing", q.plainSQL.sql)
|
||||
if q.rawSQL.sql != "thing" {
|
||||
t.Errorf("Expected %q, got %s", "thing", q.rawSQL.sql)
|
||||
}
|
||||
if q.plainSQL.args[0].(int) != 5 {
|
||||
t.Errorf("Expected 5, got %v", q.plainSQL.args[0])
|
||||
if q.rawSQL.args[0].(int) != 5 {
|
||||
t.Errorf("Expected 5, got %v", q.rawSQL.args[0])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -386,11 +386,11 @@ func TestSQLG(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
q := SQLG("thing", 5)
|
||||
if q.plainSQL.sql != "thing" {
|
||||
t.Errorf("Expected %q, got %s", "thing", q.plainSQL.sql)
|
||||
if q.rawSQL.sql != "thing" {
|
||||
t.Errorf("Expected %q, got %s", "thing", q.rawSQL.sql)
|
||||
}
|
||||
if q.plainSQL.args[0].(int) != 5 {
|
||||
t.Errorf("Expected 5, got %v", q.plainSQL.args[0])
|
||||
if q.rawSQL.args[0].(int) != 5 {
|
||||
t.Errorf("Expected 5, got %v", q.rawSQL.args[0])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue