From 2ff97d673df45cbf74093522389bb0a7d8db580b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Nieto?= <jose.carlos@menteslibres.net> Date: Tue, 10 Jun 2014 18:26:48 -0500 Subject: [PATCH] Tests for raw statements. --- postgresql/collection.go | 4 ++++ postgresql/database_test.go | 17 +++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/postgresql/collection.go b/postgresql/collection.go index 47e34041..cbbf386d 100644 --- a/postgresql/collection.go +++ b/postgresql/collection.go @@ -132,6 +132,10 @@ func whereValues(term interface{}) (where sqlgen.Where, args []interface{}) { or = append(or, k...) } where = append(where, or) + case db.Raw: + if s, ok := t.Value.(string); ok == true { + where = append(where, sqlgen.Raw{s}) + } case db.Cond: k, v := conditionValues(t) args = append(args, v...) diff --git a/postgresql/database_test.go b/postgresql/database_test.go index 2813dce7..70125420 100644 --- a/postgresql/database_test.go +++ b/postgresql/database_test.go @@ -33,7 +33,6 @@ package postgresql import ( "database/sql" "flag" - "fmt" "menteslibres.net/gosexy/to" "os" "reflect" @@ -733,19 +732,18 @@ func TestRawRelations(t *testing.T) { review.Append(review_t{ PublicationId: foundationId.(uint64), Name: "Edr Pls", - Comments: "The Foundation series made me fell in love with Isaac Asimov.", + Comments: "The Foundation series made me fall in love with Isaac Asimov.", Created: time.Now(), }) - // select * from publication p, artist a where p.author_id = a.id; - + // Exec'ing a raw query. var artistPublication db.Collection if artistPublication, err = sess.Collection(`artist AS a, publication AS p`); err != nil { t.Fatalf(err.Error()) } res := artistPublication.Find( - db.Raw{"a.id = p.author_id"}, + db.Raw{`a.id = p.author_id`}, ).Select( "p.id", "p.title as publication_title", @@ -754,16 +752,19 @@ func TestRawRelations(t *testing.T) { type artistPublication_t struct { Id uint64 `db:"id"` - PublicationTitle string `id:"publication_title"` - ArtistName string `id:"artist_name"` + PublicationTitle string `db:"publication_title"` + ArtistName string `db:"artist_name"` } all := []artistPublication_t{} + if err = res.All(&all); err != nil { t.Fatalf(err.Error()) } - fmt.Printf("all: %v\n", all) + if len(all) != 9 { + t.Fatalf("Expecting some rows.") + } } -- GitLab