-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqueries.sql
68 lines (54 loc) · 1.41 KB
/
queries.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
57
58
59
60
61
62
63
64
65
66
67
68
-- name: NewUser :exec
INSERT INTO users (telegram_id, name, language)
VALUES (?, ?, ?);
-- name: GetUser :one
SELECT * FROM users WHERE telegram_id = ?;
-- name: SetUserLanguage :exec
UPDATE users
SET language = ?
WHERE telegram_id = ?;
-- name: SetUserCurDog :exec
UPDATE users
SET current_dog = ?
WHERE id = ?;
-- name: SetUserState :exec
UPDATE users
SET state = ?
WHERE id = ?;
-- name: NewDog :one
INSERT INTO dogs (name, birth_date, sex, breed)
VALUES (?, ?, ?, ?)
RETURNING id;
-- name: GetDog :one
SELECT * FROM dogs WHERE id = ?;
-- name: NewAction :exec
INSERT INTO actions (user_id, dog_id, timestamp, action_id, additional_info)
VALUES (?, ?, ?, ?, ?);
-- name: NewSubscription :exec
INSERT INTO subscriptions (dog_id, user_id, type)
VALUES (?, ?, ?);
-- name: ClearSubscriptions :exec
DELETE FROM subscriptions
WHERE user_id = ? AND dog_id = ? and type = ?;
-- name: SelectDogsSubscribers :many
SELECT * FROM users
where id in (
select user_id from subscriptions
where dog_id = ?
);
-- name: SelectUsersDogs :many
Select * FROM dogs
where id in (
select dog_id from subscriptions
where type = 'owner' and user_id = ?
);
-- name: NewInvite :exec
INSERT INTO invite_subscriptions (hash, dog_id, type)
VALUES (?, ?, ?);
-- name: GetInvite :one
SELECT * FROM invite_subscriptions
WHERE used = false AND hash = ?;
-- name: MarkInviteUsed :exec
UPDATE invite_subscriptions
SET used = true
where id = ?;