From 12967f7b663d6c2cf24f526884a2142e7f39f5f9 Mon Sep 17 00:00:00 2001 From: Aaron L Date: Wed, 14 Sep 2016 20:57:07 -0700 Subject: [PATCH] Fix up the interface to raw queries. --- bdb/interface.go | 2 +- queries/query.go | 18 +++++++++--------- queries/query_builders.go | 8 ++++---- queries/query_test.go | 24 ++++++++++++------------ 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/bdb/interface.go b/bdb/interface.go index ab32c8c..0cfee73 100644 --- a/bdb/interface.go +++ b/bdb/interface.go @@ -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 diff --git a/queries/query.go b/queries/query.go index 2a22be1..81237a8 100644 --- a/queries/query.go +++ b/queries/query.go @@ -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. diff --git a/queries/query_builders.go b/queries/query_builders.go index 0937bdc..8997eaa 100644 --- a/queries/query_builders.go +++ b/queries/query_builders.go @@ -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 } diff --git a/queries/query_test.go b/queries/query_test.go index 08778f6..97f8a9d 100644 --- a/queries/query_test.go +++ b/queries/query_test.go @@ -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]) } }