Skip to content

Commit 2448017

Browse files
authored
test: Call say_hello function (#3236)
1 parent 8d7ec15 commit 2448017

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

examples/booktest/postgresql/db_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,18 @@ func TestBooks(t *testing.T) {
150150
t.Logf("Book %d: '%s', Author: '%s', ISBN: '%s' Tags: '%v'\n", ab.BookID, ab.Title, ab.Name.String, ab.Isbn, ab.Tags)
151151
}
152152

153-
// TODO: call say_hello(varchar)
153+
// call function
154+
pgText, err := dq.SayHello(ctx, "world")
155+
if err != nil {
156+
t.Fatal(err)
157+
}
158+
str, err := pgText.Value()
159+
if err != nil {
160+
t.Fatal(err)
161+
}
162+
if str != "hello world" {
163+
t.Fatal("expected function result to be \"hello world\". actual:", str)
164+
}
154165

155166
// get book 4 and delete
156167
b5, err := dq.GetBook(ctx, b3.BookID)

examples/booktest/postgresql/query.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ WHERE book_id = $3;
5858
UPDATE books
5959
SET title = $1, tags = $2, isbn = $4
6060
WHERE book_id = $3;
61+
62+
-- name: SayHello :one
63+
select * from say_hello($1);

examples/booktest/postgresql/query.sql.go

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/booktest/postgresql/schema.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ CREATE TABLE books (
2323

2424
CREATE INDEX books_title_idx ON books(title, year);
2525

26-
CREATE FUNCTION say_hello(text) RETURNS text AS $$
26+
CREATE FUNCTION say_hello(s text) RETURNS text AS $$
2727
BEGIN
28-
RETURN CONCAT('hello ', $1);
28+
RETURN CONCAT('hello ', s);
2929
END;
3030
$$ LANGUAGE plpgsql;
3131

0 commit comments

Comments
 (0)