-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathquery.sql
More file actions
36 lines (30 loc) · 758 Bytes
/
query.sql
File metadata and controls
36 lines (30 loc) · 758 Bytes
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
-- name: FindAllPlayers :many
SELECT * FROM player
ORDER BY level DESC;
-- name: InsertItem :one
INSERT INTO item (id, name, value)
VALUES (uuid_generate_v4(), $1, $2)
RETURNING *;
-- name: FindItemByID :one
SELECT * FROM item
WHERE id = $1;
-- name: GetInventoryAndPlayer :many
SELECT player.*, item.*
FROM inventory
JOIN player ON player.id = player_id
JOIN item ON item.id = item_id;
-- name: GetInventoryItem :one
SELECT item.*
FROM inventory
JOIN item ON item.id = item_id
WHERE player_id = $1
AND item_id = $2;
-- name: RemoveInventoryItem :execrows
DELETE FROM inventory
WHERE player_id = $1
AND item_id = $2;
-- name: IncrPlayerGold :one
UPDATE player
SET gold = gold + sqlc.arg(amount)::int
WHERE id = sqlc.arg(player_id)::bigint
RETURNING *;