From 02c28e8119540cbda2a2beccaf36310bc526fc8b Mon Sep 17 00:00:00 2001 From: Yusuf Ganiyu Date: Fri, 8 Apr 2022 12:15:13 +0100 Subject: [PATCH 1/2] Added updated query to postgresql docs --- docs/tutorials/getting-started-postgresql.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/tutorials/getting-started-postgresql.md b/docs/tutorials/getting-started-postgresql.md index 4a4943d3bc..5fa3d0710e 100644 --- a/docs/tutorials/getting-started-postgresql.md +++ b/docs/tutorials/getting-started-postgresql.md @@ -55,6 +55,12 @@ INSERT INTO authors ( ) RETURNING *; +-- name: UpdateAuthor :exec +UPDATE authors +set name = $2, + bio = $3 +WHERE id = $1; + -- name: DeleteAuthor :exec DELETE FROM authors WHERE id = $1; From 373e11a3cbf05573e3ac3d5bb128c7c4a93134c5 Mon Sep 17 00:00:00 2001 From: Yusuf Ganiyu Date: Fri, 8 Apr 2022 12:24:29 +0100 Subject: [PATCH 2/2] Updated the UPDATE query to postgresql docs for exec or returning record --- docs/tutorials/getting-started-postgresql.md | 22 +++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/tutorials/getting-started-postgresql.md b/docs/tutorials/getting-started-postgresql.md index 5fa3d0710e..873e9ad2cb 100644 --- a/docs/tutorials/getting-started-postgresql.md +++ b/docs/tutorials/getting-started-postgresql.md @@ -55,16 +55,28 @@ INSERT INTO authors ( ) RETURNING *; +-- name: DeleteAuthor :exec +DELETE FROM authors +WHERE id = $1; +``` + +For SQL UPDATE if you do not want to return the updated record to the user, add this to the `query.sql` file: +```sql -- name: UpdateAuthor :exec UPDATE authors set name = $2, - bio = $3 -WHERE id = $1; - --- name: DeleteAuthor :exec -DELETE FROM authors +bio = $3 WHERE id = $1; ``` +Otherwise, to return the updated record back to the user, add this to the `query.sql` file: +```sql +-- name: UpdateAuthor :one +UPDATE authors +set name = $2, +bio = $3 +WHERE id = $1 +RETURNING *; +``` You are now ready to generate code. Run the `generate` command. You shouldn't see any errors or output.