Skip to content

Commit a29f7e4

Browse files
committed
loopdb: add reservation sqlc code
1 parent 1a75a53 commit a29f7e4

File tree

6 files changed

+375
-0
lines changed

6 files changed

+375
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DROP TABLE IF EXISTS reservation_updates;
2+
DROP TABLE IF EXISTS reservations;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
-- reservations contains all the information about a reservation.
2+
CREATE TABLE IF NOT EXISTS reservations (
3+
-- id is the auto incrementing primary key.
4+
id INTEGER PRIMARY KEY,
5+
6+
-- reservation_id is the unique identifier for the reservation.
7+
reservation_id BLOB NOT NULL UNIQUE,
8+
9+
-- client_pubkey is the public key of the client.
10+
client_pubkey BLOB NOT NULL,
11+
12+
-- server_pubkey is the public key of the server.
13+
server_pubkey BLOB NOT NULL,
14+
15+
-- expiry is the absolute expiry height of the reservation.
16+
expiry INTEGER NOT NULL,
17+
18+
-- value is the value of the reservation.
19+
value BIGINT NOT NULL,
20+
21+
-- client_key_family is the key family of the client.
22+
client_key_family INTEGER NOT NULL,
23+
24+
-- client_key_index is the key index of the client.
25+
client_key_index INTEGER NOT NULL,
26+
27+
-- initiation_height is the height at which the reservation was initiated.
28+
initiation_height INTEGER NOT NULL,
29+
30+
-- tx_hash is the hash of the transaction that created the reservation.
31+
tx_hash BLOB,
32+
33+
-- out_index is the index of the output that created the reservation.
34+
out_index INTEGER,
35+
36+
-- confirmation_height is the height at which the reservation was confirmed.
37+
confirmation_height INTEGER
38+
);
39+
40+
CREATE INDEX IF NOT EXISTS reservations_reservation_id_idx ON reservations(reservation_id);
41+
42+
-- reservation_updates contains all the updates to a reservation.
43+
CREATE TABLE IF NOT EXISTS reservation_updates (
44+
-- id is the auto incrementing primary key.
45+
id INTEGER PRIMARY KEY,
46+
47+
-- reservation_id is the unique identifier for the reservation.
48+
reservation_id BLOB NOT NULL REFERENCES reservations(reservation_id),
49+
50+
-- update_state is the state of the reservation at the time of the update.
51+
update_state TEXT NOT NULL,
52+
53+
-- update_timestamp is the timestamp of the update.
54+
update_timestamp TIMESTAMP NOT NULL
55+
);
56+

loopdb/sqlc/models.go

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

loopdb/sqlc/querier.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
-- name: CreateReservation :exec
2+
INSERT INTO reservations (
3+
reservation_id,
4+
client_pubkey,
5+
server_pubkey,
6+
expiry,
7+
value,
8+
client_key_family,
9+
client_key_index,
10+
initiation_height
11+
) VALUES (
12+
$1,
13+
$2,
14+
$3,
15+
$4,
16+
$5,
17+
$6,
18+
$7,
19+
$8
20+
);
21+
22+
-- name: UpdateReservation :exec
23+
UPDATE reservations
24+
SET
25+
tx_hash = $2,
26+
out_index = $3,
27+
confirmation_height = $4
28+
WHERE
29+
reservations.reservation_id = $1;
30+
31+
-- name: InsertReservationUpdate :exec
32+
INSERT INTO reservation_updates (
33+
reservation_id,
34+
update_state,
35+
update_timestamp
36+
) VALUES (
37+
$1,
38+
$2,
39+
$3
40+
);
41+
42+
-- name: GetReservation :one
43+
SELECT
44+
*
45+
FROM
46+
reservations
47+
WHERE
48+
reservation_id = $1;
49+
50+
-- name: GetReservations :many
51+
SELECT
52+
*
53+
FROM
54+
reservations
55+
ORDER BY
56+
id ASC;
57+
58+
-- name: GetReservationUpdates :many
59+
SELECT
60+
reservation_updates.*
61+
FROM
62+
reservation_updates
63+
WHERE
64+
reservation_id = $1
65+
ORDER BY
66+
id ASC;

0 commit comments

Comments
 (0)