Skip to content

Commit

Permalink
Fix for #185
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Martin authored and Douglas Martin committed Dec 6, 2019
1 parent fbe8322 commit 343bfe9
Show file tree
Hide file tree
Showing 6 changed files with 36 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
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ services:
- "POSTGRES_DB=goqupostgres"
expose:
- "5432"
ports:
- "5435:5432"

mysql:
image: "mysql:${MYSQL_VERSION}"
Expand All @@ -16,6 +18,8 @@ services:
- "MYSQL_ALLOW_EMPTY_PASSWORD=yes"
expose:
- "3306"
ports:
- "3306:3306"

goqu:
image: "golang:${GO_VERSION}"
Expand Down
1 change: 1 addition & 0 deletions go.test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash

set -e

echo "" > coverage.txt

go test -race -coverprofile=coverage.txt -coverpkg=./... ./...
25 changes: 25 additions & 0 deletions issues_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package goqu_test

import (
"context"
"github.com/DATA-DOG/go-sqlmock"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -324,6 +326,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 343bfe9

Please sign in to comment.