-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathquery.sql
More file actions
66 lines (49 loc) · 1.79 KB
/
query.sql
File metadata and controls
66 lines (49 loc) · 1.79 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
-- name: GetAuthor :one
SELECT * FROM authors WHERE name = ? LIMIT 1;
-- name: ListAuthors :many
SELECT *
FROM authors
ORDER BY name
LIMIT ? OFFSET ?;
-- name: CreateAuthor :exec
INSERT INTO authors (id, name, bio) VALUES (?, ?, ?);
-- name: CreateAuthorReturnId :execlastid
INSERT INTO authors (name, bio) VALUES (?, ?);
-- name: GetAuthorById :one
SELECT * FROM authors WHERE id = ? LIMIT 1;
-- name: GetAuthorByNamePattern :many
SELECT * FROM authors
WHERE name LIKE COALESCE(sqlc.narg('name_pattern'), '%');
-- name: DeleteAuthor :exec
DELETE FROM authors
WHERE name = ?;
-- name: DeleteAllAuthors :exec
DELETE FROM authors;
-- name: UpdateAuthors :execrows
UPDATE authors
SET bio = sqlc.arg('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: CreateBook :execlastid
INSERT INTO books (name, author_id) VALUES (?, ?);
-- name: ListAllAuthorsBooks :many
SELECT sqlc.embed(authors), sqlc.embed(books)
FROM authors JOIN books ON authors.id = books.author_id
ORDER BY authors.name;
-- name: GetDuplicateAuthors :many
SELECT sqlc.embed(authors1), sqlc.embed(authors2)
FROM authors authors1 JOIN authors authors2 ON authors1.name = authors2.name
WHERE authors1.id < authors2.id;
-- name: GetAuthorsByBookName :many
SELECT authors.*, sqlc.embed(books)
FROM authors JOIN books ON authors.id = books.author_id
WHERE books.name = ?;
-- name: CreateExtendedBio :exec
INSERT INTO extended.bios (author_name, name, bio_type, author_type) VALUES (?, ?, ?, ?);
-- name: GetFirstExtendedBioByType :one
SELECT * FROM extended.bios WHERE bio_type = ? LIMIT 1;
-- name: TruncateExtendedBios :exec
TRUNCATE TABLE extended.bios;