Skip to content

Commit 4f29960

Browse files
committed
Add custom function call test.
1 parent 911cab3 commit 4f29960

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

tests/mysql/delete_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,5 @@ USING dvds.rental
116116
WHERE (staff.staff_id != ?) AND (rental.rental_id < ?);
117117
`)
118118

119-
testutils.AssertExec(t, stmt, tx, 42)
119+
testutils.AssertExec(t, stmt, tx)
120120
}

tests/postgres/select_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,3 +2541,41 @@ FROM dvds.staff;
25412541
err := stmt.Query(db, &struct{}{})
25422542
require.NoError(t, err)
25432543
}
2544+
2545+
func GET_FILM_COUNT(lenFrom, lenTo IntegerExpression) IntegerExpression {
2546+
return IntExp(Func("dvds.get_film_count", lenFrom, lenTo))
2547+
}
2548+
2549+
func TestCustomFunctionCall(t *testing.T) {
2550+
stmt := SELECT(
2551+
GET_FILM_COUNT(Int(100), Int(120)).AS("film_count"),
2552+
)
2553+
2554+
testutils.AssertDebugStatementSql(t, stmt, `
2555+
SELECT dvds.get_film_count(100, 120) AS "film_count";
2556+
`)
2557+
2558+
var dest struct {
2559+
FilmCount int
2560+
}
2561+
2562+
err := stmt.Query(db, &dest)
2563+
require.NoError(t, err)
2564+
require.Equal(t, dest.FilmCount, 165)
2565+
2566+
stmt2 := SELECT(
2567+
Raw("dvds.get_film_count(#1, #2)", RawArgs{"#1": 100, "#2": 120}).AS("film_count"),
2568+
)
2569+
2570+
err = stmt2.Query(db, &dest)
2571+
require.NoError(t, err)
2572+
require.Equal(t, dest.FilmCount, 165)
2573+
2574+
stmt3 := RawStatement(`
2575+
SELECT dvds.get_film_count(#1, #2) AS "film_count";`, RawArgs{"#1": 100, "#2": 120},
2576+
)
2577+
2578+
err = stmt3.Query(db, &dest)
2579+
require.NoError(t, err)
2580+
require.Equal(t, dest.FilmCount, 165)
2581+
}

tests/testdata

0 commit comments

Comments
 (0)