diff --git a/postgresql/collection.go b/postgresql/collection.go index 47e3404199d89a469c4a81b3808332673e2a190a..cbbf386dd7d7734eed6adf249fae2a83a4dfb0b1 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 2813dce7d028b7fe6d5766741b871fba54a58ed2..701254201b61a46ab7d9dbe81facb3f36853f340 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.") + } }