-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from doug-martin/issue177
[FIXED] WITH clause without a RETURNING clause will panic [#177]
- Loading branch information
Showing
8 changed files
with
57 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -328,6 +328,44 @@ func (gis *githubIssuesSuite) TestIssue164() { | |
) | ||
} | ||
|
||
// Test for https://github.com/doug-martin/goqu/issues/177 | ||
func (gis *githubIssuesSuite) TestIssue177() { | ||
ds := goqu.Dialect("postgres"). | ||
From("ins1"). | ||
With("ins1", | ||
goqu.Dialect("postgres"). | ||
Insert("account"). | ||
Rows(goqu.Record{"email": "[email protected]", "status": "active", "uuid": "XXX-XXX-XXXX"}). | ||
Returning("*"), | ||
). | ||
With("ins2", | ||
goqu.Dialect("postgres"). | ||
Insert("account_user"). | ||
Cols("account_id", "user_id"). | ||
FromQuery(goqu.Dialect("postgres"). | ||
From("ins1"). | ||
Select( | ||
"id", | ||
goqu.V(1001), | ||
), | ||
), | ||
). | ||
Select("*") | ||
sql, args, err := ds.ToSQL() | ||
gis.NoError(err) | ||
gis.Equal(`WITH ins1 AS (`+ | ||
`INSERT INTO "account" ("email", "status", "uuid") VALUES ('[email protected]', 'active', 'XXX-XXX-XXXX') RETURNING *),`+ | ||
` ins2 AS (INSERT INTO "account_user" ("account_id", "user_id") SELECT "id", 1001 FROM "ins1")`+ | ||
` SELECT * FROM "ins1"`, sql) | ||
gis.Len(args, 0) | ||
|
||
sql, args, err = ds.Prepared(true).ToSQL() | ||
gis.NoError(err) | ||
gis.Equal(`WITH ins1 AS (INSERT INTO "account" ("email", "status", "uuid") VALUES ($1, $2, $3) RETURNING *), ins2`+ | ||
` AS (INSERT INTO "account_user" ("account_id", "user_id") SELECT "id", $4 FROM "ins1") SELECT * FROM "ins1"`, sql) | ||
gis.Equal(args, []interface{}{"[email protected]", "active", "XXX-XXX-XXXX", int64(1001)}) | ||
} | ||
|
||
// Test for https://github.com/doug-martin/goqu/issues/183 | ||
func (gis *githubIssuesSuite) TestIssue184() { | ||
expectedErr := fmt.Errorf("an error") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters