From 0f776f8b982d65b0e31b5277b874419e7927eded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Nieto?= <jose.carlos@menteslibres.net> Date: Tue, 3 Nov 2015 22:21:58 -0600 Subject: [PATCH] wip: Updating other adapters to recent changes. --- db_test.go | 10 +++++----- mongo/collection.go | 7 ++++--- mongo/database_test.go | 2 +- mysql/database.go | 2 +- mysql/database_test.go | 15 ++++++--------- ql/database_test.go | 12 ++++++------ sqlite/database_test.go | 12 ++++++------ 7 files changed, 29 insertions(+), 31 deletions(-) diff --git a/db_test.go b/db_test.go index 045d363e..f389fc15 100644 --- a/db_test.go +++ b/db_test.go @@ -730,11 +730,11 @@ func TestFibonacci(t *testing.T) { // Testing sort by function. switch wrapper { case `postgresql`: - res = res.Sort(db.Raw{`RANDOM()`}) + res = res.Sort(db.Raw(`RANDOM()`)) case `sqlite`: - res = res.Sort(db.Raw{`RANDOM()`}) + res = res.Sort(db.Raw(`RANDOM()`)) case `mysql`: - res = res.Sort(db.Raw{`RAND()`}) + res = res.Sort(db.Raw(`RAND()`)) } total, err = res.Count() @@ -752,9 +752,9 @@ func TestFibonacci(t *testing.T) { switch wrapper { case `mongo`: - whereIn = db.Cond{"input": db.Func{"$in", []int{3, 5, 6, 7}}} + whereIn = db.Cond{"input": db.Func("$in", 3, 5, 6, 7)} default: - whereIn = db.Cond{"input": db.Func{"IN", []int{3, 5, 6, 7}}} + whereIn = db.Cond{"input": db.Func("IN", 3, 5, 6, 7)} } res = col.Find(whereIn).Sort("input") diff --git a/mongo/collection.go b/mongo/collection.go index fdd7685e..c5fa1d69 100644 --- a/mongo/collection.go +++ b/mongo/collection.go @@ -30,6 +30,7 @@ import ( "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" + builder "upper.io/builder/meta" "upper.io/db" ) @@ -106,8 +107,8 @@ func compileStatement(cond db.Cond) bson.M { } switch value := value.(type) { - case db.Func: - conds[chunks[0]] = bson.M{value.Name: value.Args} + case builder.Function: + conds[chunks[0]] = bson.M{value.Name(): value.Arguments()} default: if op == "" { conds[chunks[0]] = value @@ -154,7 +155,7 @@ func (col *Collection) compileConditions(term interface{}) interface{} { case db.Cond: return compileStatement(t) case db.Constrainer: - return compileStatement(t.Constraint()) + return compileStatement(t.Constraints()) } return nil } diff --git a/mongo/database_test.go b/mongo/database_test.go index aa276b1b..6380d8cd 100644 --- a/mongo/database_test.go +++ b/mongo/database_test.go @@ -849,7 +849,7 @@ func TestFunction(t *testing.T) { t.Fatalf("One: %q", err) } - res = artist.Find(db.Cond{"_id": db.Func{"$nin", []int{0, -1}}}) + res = artist.Find(db.Cond{"_id": db.Func("$nin", 0, -1)}) if err = res.One(&rowS); err != nil { t.Fatalf("One: %q", err) diff --git a/mysql/database.go b/mysql/database.go index 1091ce5d..473afeaa 100644 --- a/mysql/database.go +++ b/mysql/database.go @@ -170,7 +170,7 @@ func (d *database) PopulateSchema() (err error) { d.NewSchema() - q := d.Builder().Select(db.Raw{"DATABASE() AS name"}) + q := d.Builder().Select(db.Raw("DATABASE() AS name")) var dbName string diff --git a/mysql/database_test.go b/mysql/database_test.go index 7877b3b7..14ec3244 100644 --- a/mysql/database_test.go +++ b/mysql/database_test.go @@ -105,7 +105,7 @@ type itemWithKey struct { SomeVal string `db:"some_val"` } -func (item itemWithKey) Constraint() db.Cond { +func (item itemWithKey) Constraints() db.Cond { cond := db.Cond{ "code": item.Code, "user_id": item.UserID, @@ -491,14 +491,11 @@ func TestGroup(t *testing.T) { } } - // db.Func{"COUNT", 1}, - // db.Func{"SUM", `value`}, - // Testing GROUP BY res := stats.Find().Select( `numeric`, - db.Raw{`COUNT(1) AS counter`}, - db.Raw{`SUM(value) AS total`}, + db.Raw(`COUNT(1) AS counter`), + db.Raw(`SUM(value) AS total`), ).Group(`numeric`) var results []map[string]interface{} @@ -825,7 +822,7 @@ func TestFunction(t *testing.T) { } // Testing conditions - res = artist.Find(db.Cond{"id": db.Func{"NOT IN", []int{0, -1}}}) + res = artist.Find(db.Cond{"id NOT": db.Func("IN", 0, -1)}) if err = res.One(&rowStruct); err != nil { t.Fatal(err) @@ -841,7 +838,7 @@ func TestFunction(t *testing.T) { // Testing DISTINCT (function) res = artist.Find().Select( - db.Func{`DISTINCT`, `name`}, + db.Func(`DISTINCT`, `name`), ) if err = res.One(&rowMap); err != nil { @@ -858,7 +855,7 @@ func TestFunction(t *testing.T) { // Testing DISTINCT (raw) res = artist.Find().Select( - db.Raw{`DISTINCT(name)`}, + db.Raw("DISTINCT(name)"), ) if err = res.One(&rowMap); err != nil { diff --git a/ql/database_test.go b/ql/database_test.go index b23d55c4..242a0aaf 100644 --- a/ql/database_test.go +++ b/ql/database_test.go @@ -83,7 +83,7 @@ type itemWithKey struct { SomeVal string `db:"some_val"` } -func (item itemWithKey) Constraint() db.Cond { +func (item itemWithKey) Constraints() db.Cond { cond := db.Cond{ "id()": item.ID, } @@ -311,8 +311,8 @@ func TestGroup(t *testing.T) { // Testing GROUP BY res := stats.Find().Select( `numeric`, - db.Raw{`count(1) AS counter`}, - db.Raw{`sum(value) AS total`}, + db.Raw(`count(1) AS counter`), + db.Raw(`sum(value) AS total`), ).Group(`numeric`) var results []map[string]interface{} @@ -639,7 +639,7 @@ func TestFunction(t *testing.T) { } // Testing conditions - res = artist.Find(db.Cond{"id()": db.Func{"NOT IN", []int{0, -1}}}) + res = artist.Find(db.Cond{"id() NOT": db.Func("IN", 0, -1)}) if err = res.One(&rowStruct); err != nil { t.Fatal(err) @@ -655,7 +655,7 @@ func TestFunction(t *testing.T) { // Testing DISTINCT (function) res = artist.Find().Select( - db.Func{`DISTINCT`, `name`}, + db.Func(`DISTINCT`, `name`), ) if err = res.One(&rowMap); err != nil { @@ -672,7 +672,7 @@ func TestFunction(t *testing.T) { // Testing DISTINCT (raw) res = artist.Find().Select( - db.Raw{`DISTINCT(name)`}, + db.Raw(`DISTINCT(name)`), ) if err = res.One(&rowMap); err != nil { diff --git a/sqlite/database_test.go b/sqlite/database_test.go index 8561af48..4368cc9d 100644 --- a/sqlite/database_test.go +++ b/sqlite/database_test.go @@ -99,7 +99,7 @@ type itemWithKey struct { SomeVal string `db:"some_val"` } -func (item itemWithKey) Constraint() db.Cond { +func (item itemWithKey) Constraints() db.Cond { cond := db.Cond{ "code": item.Code, "user_id": item.UserID, @@ -450,8 +450,8 @@ func TestGroup(t *testing.T) { // Testing GROUP BY res := stats.Find().Select( `numeric`, - db.Raw{`COUNT(1) AS counter`}, - db.Raw{`SUM(value) AS total`}, + db.Raw(`COUNT(1) AS counter`), + db.Raw(`SUM(value) AS total`), ).Group(`numeric`) var results []map[string]interface{} @@ -778,7 +778,7 @@ func TestFunction(t *testing.T) { } // Testing conditions - res = artist.Find(db.Cond{"id": db.Func{"NOT IN", []int{0, -1}}}) + res = artist.Find(db.Cond{"id NOT": db.Func("IN", 0, -1)}) if err = res.One(&rowStruct); err != nil { t.Fatal(err) @@ -794,7 +794,7 @@ func TestFunction(t *testing.T) { // Testing DISTINCT (function) res = artist.Find().Select( - db.Func{`DISTINCT`, `name`}, + db.Func(`DISTINCT`, `name`), ) if err = res.One(&rowMap); err != nil { @@ -811,7 +811,7 @@ func TestFunction(t *testing.T) { // Testing DISTINCT (raw) res = artist.Find().Select( - db.Raw{`DISTINCT(name)`}, + db.Raw(`DISTINCT(name)`), ) if err = res.One(&rowMap); err != nil { -- GitLab