-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtap.sql
56 lines (43 loc) · 940 Bytes
/
tap.sql
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
-- CRUD
-- name: GetAllTaps :many
SELECT *
FROM tap;
-- name: GetTapByID :one
SELECT *
FROM tap
WHERE id = $1;
-- name: CreateTap :one
INSERT INTO tap (order_id, order_created_at, name, category)
VALUES ($1, $2, $3, $4)
RETURNING *;
-- name: UpdateTap :one
UPDATE tap
SET order_id = $1, order_created_at = $2, name = $3, category = $4
WHERE id = $5
RETURNING *;
-- name: DeleteTap :execrows
DELETE FROM tap
WHERE id = $1;
-- Other
-- name: GetTapByOrderID :one
SELECT *
FROM tap
WHERE order_id = $1;
-- name: GetTapByCategory :many
SELECT *
FROM tap
WHERE category = $1;
-- name: GetLastOrderByOrderID :one
SELECT *
FROM tap
ORDER BY order_id DESC
LIMIT 1;
-- name: GetOrderCount :many
SELECT category, COUNT(*)
FROM tap
GROUP BY category;
-- name: GetOrderCountByCategorySinceOrderID :many
SELECT category, COUNT(*), MAX(order_created_at)::TIMESTAMP AS latest_order_created_at
FROM tap
WHERE order_id >= $1
GROUP BY category;