Add custom set returning function test.
This commit is contained in:
parent
cf0923fdd3
commit
5d2c232529
7 changed files with 76 additions and 6 deletions
|
|
@ -84,7 +84,10 @@ func TestRawStatementSelectWithArguments(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRawStatementRows(t *testing.T) {
|
||||
stmt := RawStatement(`
|
||||
|
||||
var stmt Statement
|
||||
|
||||
stmt = RawStatement(`
|
||||
SELECT actor.actor_id AS "actor.actor_id",
|
||||
actor.first_name AS "actor.first_name",
|
||||
actor.last_name AS "actor.last_name",
|
||||
|
|
|
|||
|
|
@ -141,7 +141,9 @@ RETURNING link.id AS "link.id",
|
|||
}
|
||||
|
||||
func TestRawStatementRows(t *testing.T) {
|
||||
stmt := RawStatement(`
|
||||
var stmt Statement
|
||||
|
||||
stmt = RawStatement(`
|
||||
SELECT actor.actor_id AS "actor.actor_id",
|
||||
actor.first_name AS "actor.first_name",
|
||||
actor.last_name AS "actor.last_name",
|
||||
|
|
|
|||
|
|
@ -3867,6 +3867,68 @@ ORDER BY film.film_id;
|
|||
`)
|
||||
}
|
||||
|
||||
func TestCustomSetReturningFunction(t *testing.T) {
|
||||
skipForCockroachDB(t) // no set Set-Returning Functions
|
||||
|
||||
inventoryID := IntegerColumn("inventoryID")
|
||||
filmsInStock := CTE("film_in_stock", inventoryID)
|
||||
|
||||
stmt := WITH(
|
||||
filmsInStock.AS(
|
||||
RawStatement("SELECT * FROM dvds.film_in_stock(#filmID, #storeID)",
|
||||
RawArgs{
|
||||
"#filmID": 1,
|
||||
"#storeID": 2,
|
||||
}),
|
||||
),
|
||||
)(
|
||||
SELECT(
|
||||
Inventory.AllColumns,
|
||||
).FROM(Inventory.
|
||||
INNER_JOIN(filmsInStock, Inventory.InventoryID.EQ(inventoryID)),
|
||||
),
|
||||
)
|
||||
|
||||
testutils.AssertStatementSql(t, stmt, `
|
||||
WITH film_in_stock ("inventoryID") AS (SELECT * FROM dvds.film_in_stock($1, $2)
|
||||
)
|
||||
SELECT inventory.inventory_id AS "inventory.inventory_id",
|
||||
inventory.film_id AS "inventory.film_id",
|
||||
inventory.store_id AS "inventory.store_id",
|
||||
inventory.last_update AS "inventory.last_update"
|
||||
FROM dvds.inventory
|
||||
INNER JOIN film_in_stock ON (inventory.inventory_id = film_in_stock."inventoryID");
|
||||
`)
|
||||
|
||||
var dest []model.Inventory
|
||||
|
||||
err := stmt.Query(db, &dest)
|
||||
|
||||
require.NoError(t, err)
|
||||
testutils.AssertJSON(t, dest, `
|
||||
[
|
||||
{
|
||||
"InventoryID": 5,
|
||||
"FilmID": 1,
|
||||
"StoreID": 2,
|
||||
"LastUpdate": "2006-02-15T10:09:17Z"
|
||||
},
|
||||
{
|
||||
"InventoryID": 7,
|
||||
"FilmID": 1,
|
||||
"StoreID": 2,
|
||||
"LastUpdate": "2006-02-15T10:09:17Z"
|
||||
},
|
||||
{
|
||||
"InventoryID": 8,
|
||||
"FilmID": 1,
|
||||
"StoreID": 2,
|
||||
"LastUpdate": "2006-02-15T10:09:17Z"
|
||||
}
|
||||
]
|
||||
`)
|
||||
}
|
||||
|
||||
var customer0 = model.Customer{
|
||||
CustomerID: 1,
|
||||
StoreID: 1,
|
||||
|
|
|
|||
|
|
@ -82,7 +82,10 @@ func TestRawStatementSelectWithArguments(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRawStatementRows(t *testing.T) {
|
||||
stmt := RawStatement(`
|
||||
|
||||
var stmt Statement
|
||||
|
||||
stmt = RawStatement(`
|
||||
SELECT actor.actor_id AS "actor.actor_id",
|
||||
actor.first_name AS "actor.first_name",
|
||||
actor.last_name AS "actor.last_name",
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit a4594eea9f2c58c6bbf6909005306f94624c2968
|
||||
Subproject commit 1c501acb72bea389788404988ef0130b733f9cee
|
||||
Loading…
Add table
Add a link
Reference in a new issue