change database, add queries

This commit is contained in:
zardzul
2026-03-14 18:18:10 +01:00
parent 3ffd7cfc8d
commit 433c7b4085
5 changed files with 65 additions and 4 deletions
+16 -1
View File
@@ -3,4 +3,19 @@
SELECT * FROM albums WHERE id = $1;
-- name: GetAllAlbums :many
SELECT * FROM albums;
SELECT * FROM albums;
-- name: CreateAlbum :one
INSERT INTO albums (id, name, artist, release_date, album_art_url) VALUES ($1, $2, $3, $4, $5) RETURNING id;
-- name: UpdateAlbum :exec
UPDATE albums SET name = $2, artist = $3, release_date = $4, album_art_url = $5 WHERE id = $1;
-- name: DeleteAlbum :exec
DELETE FROM albums WHERE id = $1;
-- name: SearchAlbums :many
SELECT * FROM albums WHERE name ILIKE '%' || $1 || '%' OR artist ILIKE '%' || $1 || '%';
-- name: GetAlbumsByArtist :many
SELECT * FROM albums WHERE artist = $1;
+9
View File
@@ -7,3 +7,12 @@ SELECT * FROM artists;
-- name: CreateArtist :one
INSERT INTO artists (id, name, genre, bio, artist_image_url) VALUES ($1, $2, $3, $4, $5) RETURNING id;
-- name: UpdateArtist :exec
UPDATE artists SET name = $2, genre = $3, bio = $4, artist_image_url = $5 WHERE id = $1;
-- name: DeleteArtist :exec
DELETE FROM artists WHERE id = $1;
-- name: SearchArtists :many
SELECT * FROM artists WHERE name ILIKE '%' || $1 || '%' OR genre ILIKE '%' || $1 || '%';
+19
View File
@@ -1,4 +1,23 @@
-- user_albums.sql
-- name: GetUserAlbums :many
SELECT ua.*, a.name AS album_name, a.artist AS album_artist, a.release_date, a.album_art_url
FROM user_albums ua
JOIN albums a ON ua.album_id = a.id
WHERE ua.user_id = $1;
-- name: GetUserAlbum :one
SELECT ua.*, a.name AS album_name, a.artist AS album_artist, a.release_date, a.album_art_url
FROM user_albums ua
JOIN albums a ON ua.album_id = a.id
WHERE ua.user_id = $1 AND ua.album_id = $2;
-- name: AddUserAlbum :exec
INSERT INTO user_albums (user_id, album_id, album_owned, album_want,
is_vinyl, is_cd) VALUES ($1, $2, $3, $4, $5, $6);
-- name: RemoveUserAlbum :exec
DELETE FROM user_albums WHERE user_id = $1 AND album_id = $2;
-- name: UpdateUserAlbumStatus :exec
INSERT INTO user_albums (user_id, album_id, album_owned, album_want,
is_vinyl, is_cd) VALUES ($1, $2, $3, $4, $5, $6)
+17 -2
View File
@@ -1,9 +1,24 @@
-- users.sql
-- name: CreateUser :one
INSERT INTO users (id, user_name, user_mail, password) VALUES ($1, $2, $3, $4) RETURNING id;
-- name: UpdateUser :exec
UPDATE users SET user_name = $2, user_mail = $3, password = $4 WHERE id = $1;
-- name: GetUsernameByID :one
SELECT user_name FROM users WHERE id = $1;
-- name: CheckUserExistsByEmail :one
SELECT id FROM users WHERE user_mail = $1;
-- name: CreateUser :one
INSERT INTO users (id, user_name, user_mail, password) VALUES ($1, $2, $3, $4) RETURNING id;
-- name: GetUserByID :one
SELECT id, user_name, user_mail, created_at FROM users WHERE id = $1;
-- name: LoginUser :one
SELECT id, user_name, user_mail FROM users WHERE user_mail = $1 AND password = $2;
-- name: UpdateUserSession :exec
UPDATE users SET session_token = $2, session_expiry = $3 WHERE id = $1;
-- name: logoutUser :exec
-- This is a placeholder for logout functionality, which typically involves token invalidation or session management rather