Skip to content

Commit

Permalink
Merge pull request #186 from doug-martin/issue185
Browse files Browse the repository at this point in the history
Fix for #185
  • Loading branch information
doug-martin authored Dec 6, 2019
2 parents fbe8322 + b658b89 commit d39bf74
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v9.5.1

* [FIXED] Unable to execute union with order by expression [#185](https://github.com/doug-martin/goqu/issues/185)

# v9.5.0

* [ADDED] Ability to use regexp like, ilike, notlike, and notilike without a regexp [#172](https://github.com/doug-martin/goqu/issues/172)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
phony:

lint:
golangci-lint run
docker run --rm -v ${CURDIR}:/app -w /app golangci/golangci-lint:v1.21.0 golangci-lint run -v
26 changes: 26 additions & 0 deletions issues_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package goqu_test

import (
"context"
"strings"
"sync"
"testing"
"time"

"github.com/DATA-DOG/go-sqlmock"

"github.com/doug-martin/goqu/v9"
"github.com/stretchr/testify/suite"
)
Expand Down Expand Up @@ -324,6 +327,29 @@ func (gis *githubIssuesSuite) TestIssue164() {
)
}

// Test for https://github.com/doug-martin/goqu/issues/185
func (gis *githubIssuesSuite) TestIssue185() {
mDb, sqlMock, err := sqlmock.New()
gis.NoError(err)
sqlMock.ExpectQuery(
`SELECT \* FROM \(SELECT "id" FROM "table" ORDER BY "id" ASC\) AS "t1" UNION
\(SELECT \* FROM \(SELECT "id" FROM "table" ORDER BY "id" ASC\) AS "t1"\)`,
).
WillReturnRows(sqlmock.NewRows([]string{"id"}).FromCSVString("1\n2\n3\n4\n"))
db := goqu.New("mock", mDb)

ds := db.Select("id").From("table").Order(goqu.C("id").Asc()).
Union(
db.Select("id").From("table").Order(goqu.C("id").Asc()),
)

ctx := context.Background()
var i []int
gis.NoError(ds.ScanValsContext(ctx, &i))
gis.Equal([]int{1, 2, 3, 4}, i)

}

func TestGithubIssuesSuite(t *testing.T) {
suite.Run(t, new(githubIssuesSuite))
}
7 changes: 1 addition & 6 deletions select_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,7 @@ func (sd *SelectDataset) From(from ...interface{}) *SelectDataset {
// Returns a new Dataset with the current one as an source. If the current Dataset is not aliased (See Dataset#As) then
// it will automatically be aliased. See examples.
func (sd *SelectDataset) FromSelf() *SelectDataset {
builder := SelectDataset{
dialect: sd.dialect,
clauses: exp.NewSelectClauses(),
}
return builder.From(sd)

return sd.copy(exp.NewSelectClauses()).From(sd)
}

// Alias to InnerJoin. See examples.
Expand Down

0 comments on commit d39bf74

Please sign in to comment.