Skip to content

test: Call say_hello function for test #3236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion examples/booktest/postgresql/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,18 @@ func TestBooks(t *testing.T) {
t.Logf("Book %d: '%s', Author: '%s', ISBN: '%s' Tags: '%v'\n", ab.BookID, ab.Title, ab.Name.String, ab.Isbn, ab.Tags)
}

// TODO: call say_hello(varchar)
// call function
pgText, err := dq.SayHello(ctx, "world")
if err != nil {
t.Fatal(err)
}
str, err := pgText.Value()
if err != nil {
t.Fatal(err)
}
if str != "hello world" {
t.Fatal("expected function result to be \"hello world\". actual:", str)
}

// get book 4 and delete
b5, err := dq.GetBook(ctx, b3.BookID)
Expand Down
3 changes: 3 additions & 0 deletions examples/booktest/postgresql/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ WHERE book_id = $3;
UPDATE books
SET title = $1, tags = $2, isbn = $4
WHERE book_id = $3;

-- name: SayHello :one
select * from say_hello($1);
11 changes: 11 additions & 0 deletions examples/booktest/postgresql/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/booktest/postgresql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ CREATE TABLE books (

CREATE INDEX books_title_idx ON books(title, year);

CREATE FUNCTION say_hello(text) RETURNS text AS $$
CREATE FUNCTION say_hello(s text) RETURNS text AS $$
BEGIN
RETURN CONCAT('hello ', $1);
RETURN CONCAT('hello ', s);
END;
$$ LANGUAGE plpgsql;

Expand Down