From a890e51799119664b09c41d19f550839c83c781b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Nieto?= <jose.carlos@menteslibres.net> Date: Tue, 17 Jun 2014 14:11:32 -0500 Subject: [PATCH] Testing raw columns in Select(). --- main.go | 2 +- postgresql/database_test.go | 2 +- postgresql/result.go | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 5c243755..93ef059d 100644 --- a/main.go +++ b/main.go @@ -186,7 +186,7 @@ type Result interface { Sort(...string) Result // Defines specific fields to be returned on results on this result set. - Select(...string) Result + Select(...interface{}) Result // Sets conditions. Where(...interface{}) Result diff --git a/postgresql/database_test.go b/postgresql/database_test.go index de21b197..a6d4510d 100644 --- a/postgresql/database_test.go +++ b/postgresql/database_test.go @@ -745,7 +745,7 @@ func TestRawRelations(t *testing.T) { ).Select( "p.id", "p.title as publication_title", - "a.name AS artist_name", + db.Raw{"a.name AS artist_name"}, ) type artistPublication_t struct { diff --git a/postgresql/result.go b/postgresql/result.go index f938b71a..6fac1a37 100644 --- a/postgresql/result.go +++ b/postgresql/result.go @@ -112,12 +112,17 @@ func (self *Result) Sort(fields ...string) db.Result { } // Retrieves only the given fields. -func (self *Result) Select(fields ...string) db.Result { +func (self *Result) Select(fields ...interface{}) db.Result { self.columns = make(sqlgen.Columns, 0, len(fields)) l := len(fields) for i := 0; i < l; i++ { - self.columns = append(self.columns, sqlgen.Column{fields[i]}) + switch value := fields[i].(type) { + case db.Raw: + self.columns = append(self.columns, sqlgen.Column{value.Value}) + default: + self.columns = append(self.columns, sqlgen.Column{value}) + } } return self -- GitLab