good morning!!!!

Skip to content
Snippets Groups Projects
Commit a890e517 authored by José Carlos Nieto's avatar José Carlos Nieto
Browse files

Testing raw columns in Select().

parent a0dd4121
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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 {
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment