|
| 1 | +-- name: GetBook :one |
| 2 | +-- SELECT "id", "title", "author", "description", "created_at", "updated_at" FROM books WHERE id = $1 |
| 3 | +SELECT "id", "title", "author", "description", "created_at", "updated_at" |
| 4 | +FROM books |
| 5 | +WHERE id = $1; |
| 6 | + |
| 7 | +-- name: ListBooks :many |
| 8 | +-- SELECT "id", "title", "author", "description", "created_at", "updated_at" FROM books ORDER BY title |
| 9 | +SELECT "id", "title", "author", "description", "created_at", "updated_at" |
| 10 | +FROM books |
| 11 | +ORDER BY title; |
| 12 | + |
| 13 | +-- name: GetBooksByAuthor :many |
| 14 | +-- SELECT "id", "title", "author", "description", "created_at", "updated_at" FROM books WHERE author = $1 |
| 15 | +SELECT "id", "title", "author", "description", "created_at", "updated_at" |
| 16 | +FROM books |
| 17 | +WHERE author = $1; |
| 18 | + |
| 19 | +-- name: CreateBook :one |
| 20 | +-- INSERT INTO books ("title", "author", "description") VALUES ($1, $2, $3) RETURNING "id", "title", "author", "description", "created_at", "updated_at" |
| 21 | +INSERT INTO books ("title", "author", "description") |
| 22 | +VALUES ($1, $2, $3) |
| 23 | +RETURNING "id", "title", "author", "description", "created_at", "updated_at"; |
| 24 | + |
| 25 | +-- name: UpdateBook :one |
| 26 | +-- UPDATE books SET "title" = $1, "author" = $2, "description" = $3, "updated_at" = NOW() WHERE id = $4 RETURNING "id", "title", "author", "description", "created_at", "updated_at" |
| 27 | +UPDATE books |
| 28 | +SET "title" = $1, |
| 29 | + "author" = $2, |
| 30 | + "description" = $3, |
| 31 | + "updated_at" = NOW() |
| 32 | +WHERE id = $4 |
| 33 | +RETURNING "id", "title", "author", "description", "created_at", "updated_at"; |
| 34 | + |
| 35 | +-- name: DeleteBook :exec |
| 36 | +-- DELETE FROM books WHERE id = $1 |
| 37 | +DELETE FROM books |
| 38 | +WHERE id = $1; |
| 39 | + |
| 40 | +-- name: CreateTag :one |
| 41 | +-- INSERT INTO tags ("name") VALUES ($1) RETURNING "id", "name", "created_at", "updated_at" |
| 42 | +INSERT INTO tags ("name") |
| 43 | +VALUES ($1) |
| 44 | +RETURNING "id", "name", "created_at", "updated_at"; |
| 45 | + |
| 46 | +-- name: GetTag :one |
| 47 | +-- SELECT "id", "name", "created_at", "updated_at" FROM tags WHERE id = $1 |
| 48 | +SELECT "id", "name", "created_at", "updated_at" |
| 49 | +FROM tags |
| 50 | +WHERE id = $1; |
| 51 | + |
| 52 | +-- name: AddBookTag :exec |
| 53 | +-- INSERT INTO book_tags ("book_id", "tag_id") VALUES ($1, $2) |
| 54 | +INSERT INTO book_tags ("book_id", "tag_id") |
| 55 | +VALUES ($1, $2); |
| 56 | + |
| 57 | +-- name: AddBookTags :exec |
| 58 | +-- INSERT INTO book_tags ("book_id", "tag_id") VALUES (unnest($1::bigint[]), unnest($2::bigint[])) |
| 59 | +-- @bulk-for AddBookTag |
| 60 | +INSERT INTO book_tags ("book_id", "tag_id") |
| 61 | +VALUES (unnest($1::bigint[]), unnest($2::bigint[])); |
| 62 | + |
| 63 | +-- name: GetBookTags :many |
| 64 | +-- SELECT t."id", t."name", t."created_at", t."updated_at" FROM tags t INNER JOIN book_tags bt ON t.id = bt.tag_id WHERE bt.book_id = $1 |
| 65 | +SELECT t."id", t."name", t."created_at", t."updated_at" |
| 66 | +FROM tags t |
| 67 | +INNER JOIN book_tags bt ON t.id = bt.tag_id |
| 68 | +WHERE bt.book_id = $1; |
0 commit comments