diff --git a/postgres/statement.go b/postgres/statement.go index be645c9f..178c48cd 100644 --- a/postgres/statement.go +++ b/postgres/statement.go @@ -5,6 +5,6 @@ import ( ) // RawStatement creates new sql statements from raw query and optional map of named arguments -func RawStatement(rawQuery string, namedArguments ...RawArgs) Statement { +func RawStatement(rawQuery string, namedArguments ...RawArgs) jet.SerializerStatement { return jet.RawStatement(Dialect, rawQuery, namedArguments...) } diff --git a/sqlite/statement.go b/sqlite/statement.go index 3e837cff..a7901e39 100644 --- a/sqlite/statement.go +++ b/sqlite/statement.go @@ -5,6 +5,6 @@ import ( ) // RawStatement creates new sql statements from raw query and optional map of named arguments -func RawStatement(rawQuery string, namedArguments ...RawArgs) Statement { +func RawStatement(rawQuery string, namedArguments ...RawArgs) jet.SerializerStatement { return jet.RawStatement(Dialect, rawQuery, namedArguments...) } diff --git a/tests/mysql/raw_statement_test.go b/tests/mysql/raw_statement_test.go index 71ebbed9..ca155a7c 100644 --- a/tests/mysql/raw_statement_test.go +++ b/tests/mysql/raw_statement_test.go @@ -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", diff --git a/tests/postgres/raw_statements_test.go b/tests/postgres/raw_statements_test.go index 9d7dd358..b81a9832 100644 --- a/tests/postgres/raw_statements_test.go +++ b/tests/postgres/raw_statements_test.go @@ -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", diff --git a/tests/postgres/select_test.go b/tests/postgres/select_test.go index 6ecc1984..d39987d6 100644 --- a/tests/postgres/select_test.go +++ b/tests/postgres/select_test.go @@ -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, diff --git a/tests/sqlite/raw_statement_test.go b/tests/sqlite/raw_statement_test.go index f79076bb..674fad34 100644 --- a/tests/sqlite/raw_statement_test.go +++ b/tests/sqlite/raw_statement_test.go @@ -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", diff --git a/tests/testdata b/tests/testdata index a4594eea..1c501acb 160000 --- a/tests/testdata +++ b/tests/testdata @@ -1 +1 @@ -Subproject commit a4594eea9f2c58c6bbf6909005306f94624c2968 +Subproject commit 1c501acb72bea389788404988ef0130b733f9cee