Created a base to build on

This commit is contained in:
2025-12-22 21:19:31 +01:00
parent a1e33bd403
commit 47a9719eeb
20 changed files with 1590 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
ALTER TABLE users
DROP COLUMN email,
DROP COLUMN password_hash;

View File

@@ -0,0 +1,3 @@
ALTER TABLE users
ADD COLUMN email TEXT NOT NULL UNIQUE,
ADD COLUMN password_hash TEXT NOT NULL;

67
db/query.sql Normal file
View File

@@ -0,0 +1,67 @@
-- name: GetUser :one
SELECT * FROM users
WHERE id = $1 LIMIT 1;
-- name: ListUsers :many
SELECT * FROM users
ORDER BY name;
-- name: CreateUser :one
INSERT INTO users (
name, bio
) VALUES (
$1, $2
)
RETURNING *;
-- name: DeleteUser :exec
DELETE FROM users
WHERE id = $1;
-- name: CreatePlatform :one
INSERT INTO platform (
name
) VALUES (
$1
)
RETURNING *;
-- name: ListPlatforms :many
SELECT * FROM platform
ORDER BY name;
-- name: CreateGame :one
INSERT INTO game (
name, platform_id, score, release_year, finished
) VALUES (
$1, $2, $3, $4, $5
)
RETURNING *;
-- name: GetGame :one
SELECT * FROM game
WHERE id = $1 LIMIT 1;
-- name: ListGames :many
SELECT * FROM game
ORDER BY name;
-- name: UpdateGame :one
UPDATE game
SET name = $2, platform_id = $3, score = $4, release_year = $5, finished = $6
WHERE id = $1
RETURNING *;
-- name: DeleteGame :exec
DELETE FROM game
WHERE id = $1;
-- name: UpdatePlatform :one
UPDATE platform
SET name = $2
WHERE id = $1
RETURNING *;
-- name: DeletePlatform :exec
DELETE FROM platform
WHERE id = $1;

21
db/schema.sql Normal file
View File

@@ -0,0 +1,21 @@
CREATE TABLE users (
id BIGSERIAL PRIMARY KEY,
name text NOT NULL,
email text NOT NULL UNIQUE,
password_hash text NOT NULL,
bio text
);
CREATE TABLE platform (
id BIGSERIAL PRIMARY KEY,
name text NOT NULL
);
CREATE TABLE game (
id BIGSERIAL PRIMARY KEY,
name text NOT NULL,
platform_id BIGINT NOT NULL REFERENCES platform(id),
score INT NOT NULL,
release_year DATE NOT NULL,
finished DATE
);