From 3270668d9e4a11f1d10300db8b048e465cee7be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Nieto?= <jose.carlos@menteslibres.net> Date: Thu, 8 Oct 2015 10:14:33 -0500 Subject: [PATCH] MongoDB does not have a builder, so it returns nil when asked for one. --- mongo/database.go | 30 +++++++----------------------- mongo/database_test.go | 6 ------ mongo/result.go | 12 ++++++------ 3 files changed, 13 insertions(+), 35 deletions(-) diff --git a/mongo/database.go b/mongo/database.go index 7277cb48..6435e6e1 100644 --- a/mongo/database.go +++ b/mongo/database.go @@ -28,8 +28,8 @@ import ( "time" "gopkg.in/mgo.v2" + builder "upper.io/builder/meta" "upper.io/db" - "upper.io/db/internal/adapter" ) // Adapter holds the name of the mongodb adapter. @@ -184,17 +184,7 @@ func (s *Source) Collections() (cols []string, err error) { } // C returns a collection interface. -func (s *Source) C(names ...string) db.Collection { - if len(names) == 0 { - return &adapter.NonExistentCollection{Err: db.ErrMissingCollectionName} - } - - if len(names) > 1 { - return &adapter.NonExistentCollection{Err: db.ErrUnsupported} - } - - name := names[0] - +func (s *Source) C(name string) db.Collection { if col, ok := s.collections[name]; ok { // We can safely ignore if the collection exists or not. return col @@ -205,22 +195,12 @@ func (s *Source) C(names ...string) db.Collection { } // Collection returns a collection by name. -func (s *Source) Collection(names ...string) (db.Collection, error) { +func (s *Source) Collection(name string) (db.Collection, error) { var err error - if len(names) == 0 { - return nil, db.ErrMissingCollectionName - } - - if len(names) > 1 { - return nil, db.ErrUnsupported - } - s.collectionsMu.Lock() defer s.collectionsMu.Unlock() - name := names[0] - var col *Collection var ok bool @@ -264,3 +244,7 @@ func (s *Source) versionAtLeast(version ...int) bool { } return true } + +func (s *Source) Builder() builder.QueryBuilder { + return nil +} diff --git a/mongo/database_test.go b/mongo/database_test.go index 7144cee0..aa276b1b 100644 --- a/mongo/database_test.go +++ b/mongo/database_test.go @@ -542,12 +542,6 @@ func TestResultNonExistentCount(t *testing.T) { if total != 0 { t.Fatal("Counter should be zero") } - - _, err = sess.C("notartist", "neinnein").Find().Count() - - if err != db.ErrUnsupported { - t.Fatal("MongoDB should not allow multiple collections.", err) - } } // This test uses and result and tries to fetch items one by one. diff --git a/mongo/result.go b/mongo/result.go index 6839d39d..c212e8cd 100644 --- a/mongo/result.go +++ b/mongo/result.go @@ -32,7 +32,7 @@ import ( "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" "upper.io/db" - "upper.io/db/internal/sqlutil" + "upper.io/db/internal/debug" ) // result represents a query result. @@ -106,7 +106,7 @@ func (r *result) All(dst interface{}) (err error) { start = time.Now().UnixNano() defer func() { end = time.Now().UnixNano() - sqlutil.Log(r.debugQuery(fmt.Sprintf("find(%s)", mustJSON(r.queryChunks.Conditions))), nil, err, start, end) + debug.Log(r.debugQuery(fmt.Sprintf("find(%s)", mustJSON(r.queryChunks.Conditions))), nil, err, start, end) }() } @@ -141,7 +141,7 @@ func (r *result) One(dst interface{}) (err error) { start = time.Now().UnixNano() defer func() { end = time.Now().UnixNano() - sqlutil.Log(r.debugQuery(fmt.Sprintf("findOne(%s)", mustJSON(r.queryChunks.Conditions))), nil, err, start, end) + debug.Log(r.debugQuery(fmt.Sprintf("findOne(%s)", mustJSON(r.queryChunks.Conditions))), nil, err, start, end) }() } @@ -184,7 +184,7 @@ func (r *result) Remove() (err error) { start = time.Now().UnixNano() defer func() { end = time.Now().UnixNano() - sqlutil.Log(r.debugQuery(fmt.Sprintf("remove(%s)", mustJSON(r.queryChunks.Conditions))), nil, err, start, end) + debug.Log(r.debugQuery(fmt.Sprintf("remove(%s)", mustJSON(r.queryChunks.Conditions))), nil, err, start, end) }() } @@ -215,7 +215,7 @@ func (r *result) Update(src interface{}) (err error) { start = time.Now().UnixNano() defer func() { end = time.Now().UnixNano() - sqlutil.Log(r.debugQuery(fmt.Sprintf("update(%s, %s)", mustJSON(r.queryChunks.Conditions), mustJSON(updateSet))), nil, err, start, end) + debug.Log(r.debugQuery(fmt.Sprintf("update(%s, %s)", mustJSON(r.queryChunks.Conditions), mustJSON(updateSet))), nil, err, start, end) }() } @@ -271,7 +271,7 @@ func (r *result) Count() (total uint64, err error) { start = time.Now().UnixNano() defer func() { end = time.Now().UnixNano() - sqlutil.Log(r.debugQuery(fmt.Sprintf("find(%s).count()", mustJSON(r.queryChunks.Conditions))), nil, err, start, end) + debug.Log(r.debugQuery(fmt.Sprintf("find(%s).count()", mustJSON(r.queryChunks.Conditions))), nil, err, start, end) }() } -- GitLab