Skip to content

Commit ea27f08

Browse files
Defined SQL queries for sqlc
1 parent 1f06e9e commit ea27f08

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

db/queries/sessions.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- name: CreateSession :one
2+
INSERT INTO sessions_archive (
3+
id, username, ip, user_agent, status,
4+
created_at, last_active_at, expiry
5+
) VALUES (
6+
$1, $2, $3, $4, $5, $6, $7, $8
7+
) RETURNING *;
8+
9+
-- name: GetSession :one
10+
SELECT * FROM sessions_archive
11+
WHERE id = $1;
12+
13+
-- name: GetSessionByUsername :many
14+
SELECT * FROM sessions_archive
15+
WHERE username = $1
16+
ORDER BY created_at DESC;
17+
18+
-- name: DeleteSession :exec
19+
DELETE FROM sessions_archive WHERE id = $1;

db/queries/transactions.sql

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
-- name: CreateTransaction :one
2+
INSERT INTO transactions_archive (
3+
id, session_id, status, output, created_at
4+
) VALUES (
5+
$1, $2, $3, $4, $5
6+
) RETURNING *;
7+
8+
-- name: GetTransaction :one
9+
SELECT * FROM transactions_archive
10+
WHERE id = $1;
11+
12+
-- name: GetTransactionsBySession :many
13+
SELECT * FROM transactions_archive
14+
WHERE session_id = $1
15+
ORDER BY created_at DESC;
16+
17+
-- name: GetSuccessfulTransactions :many
18+
SELECT * FROM transactions_archive
19+
WHERE session_id = $1 AND status = 'success'
20+
ORDER BY created_at DESC;
21+
22+
-- name: GetFailedTransactions :many
23+
SELECT * FROM transactions_archive
24+
WHERE session_id = $1 AND status = 'failure'
25+
ORDER BY created_at DESC;
26+
27+
-- name: DeleteTransaction :exec
28+
DELETE FROM transactions_archive WHERE id = $1;
29+
30+
-- name: DeleteTransactionsBySession :exec
31+
DELETE FROM transactions_archive WHERE session_id = $1;
32+
33+
-- name: CountTransactionsByStatus :one
34+
SELECT COUNT(*) FROM transactions_archive
35+
WHERE session_id = $1 AND status = $2;

0 commit comments

Comments
 (0)