-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathquery.sql
More file actions
70 lines (54 loc) · 1.78 KB
/
query.sql
File metadata and controls
70 lines (54 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
-- name: GetAuthor :one
SELECT * FROM authors
WHERE name = ? LIMIT 1;
-- name: ListAuthors :many
SELECT *
FROM authors
ORDER BY name
LIMIT sqlc.arg('limit') OFFSET sqlc.arg('offset');
-- name: CreateAuthor :exec
INSERT INTO authors (id, name, bio) VALUES (?, ?, ?);
-- name: CreateAuthorReturnId :execlastid
INSERT INTO authors (name, bio) VALUES (?, ?) RETURNING id;
-- name: GetAuthorById :one
SELECT * FROM authors -- test rest of line comment
WHERE id = ? LIMIT 1;
-- name: GetAuthorByIdWithMultipleNamedParam :one
SELECT * FROM authors WHERE id = sqlc.arg('id_arg') AND id = sqlc.arg('id_arg') LIMIT sqlc.narg('take');
-- name: GetAuthorByNamePattern :many
SELECT * FROM authors
WHERE name LIKE COALESCE(sqlc.narg('name_pattern'), '%');
-- name: UpdateAuthors :execrows
UPDATE authors
SET bio = ?
WHERE bio IS NOT NULL;
-- name: GetAuthorsByIds :many
SELECT * FROM authors WHERE id IN (sqlc.slice('ids'));
-- name: GetAuthorsByIdsAndNames :many
SELECT * FROM authors WHERE id IN (sqlc.slice('ids')) AND name IN (sqlc.slice('names'));
-- name: DeleteAuthor :exec
DELETE FROM authors
WHERE name = ?;
-- name: CreateBook :execlastid
INSERT INTO books (name, author_id) VALUES (?, ?) RETURNING id;
-- name: ListAllAuthorsBooks :many
SELECT
sqlc.embed(authors),
sqlc.embed(books)
FROM authors INNER JOIN books ON authors.id = books.author_id
ORDER BY authors.name;
-- name: GetDuplicateAuthors :many
SELECT
sqlc.embed(authors1),
sqlc.embed(authors2)
FROM authors AS authors1
INNER JOIN authors AS authors2 ON authors1.name = authors2.name
WHERE authors1.id < authors2.id;
-- name: GetAuthorsByBookName :many
SELECT
authors.*,
sqlc.embed(books)
FROM authors INNER JOIN books ON authors.id = books.author_id
WHERE books.name = ?;
-- name: DeleteAllAuthors :exec
DELETE FROM authors;