change database, add queries
This commit is contained in:
+16
-1
@@ -3,4 +3,19 @@
|
|||||||
SELECT * FROM albums WHERE id = $1;
|
SELECT * FROM albums WHERE id = $1;
|
||||||
|
|
||||||
-- name: GetAllAlbums :many
|
-- 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;
|
||||||
@@ -7,3 +7,12 @@ SELECT * FROM artists;
|
|||||||
|
|
||||||
-- name: CreateArtist :one
|
-- name: CreateArtist :one
|
||||||
INSERT INTO artists (id, name, genre, bio, artist_image_url) VALUES ($1, $2, $3, $4, $5) RETURNING id;
|
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 || '%';
|
||||||
@@ -1,4 +1,23 @@
|
|||||||
-- user_albums.sql
|
-- 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
|
-- name: UpdateUserAlbumStatus :exec
|
||||||
INSERT INTO user_albums (user_id, album_id, album_owned, album_want,
|
INSERT INTO user_albums (user_id, album_id, album_owned, album_want,
|
||||||
is_vinyl, is_cd) VALUES ($1, $2, $3, $4, $5, $6)
|
is_vinyl, is_cd) VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
|
|||||||
+17
-2
@@ -1,9 +1,24 @@
|
|||||||
-- users.sql
|
-- 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
|
-- name: GetUsernameByID :one
|
||||||
SELECT user_name FROM users WHERE id = $1;
|
SELECT user_name FROM users WHERE id = $1;
|
||||||
|
|
||||||
-- name: CheckUserExistsByEmail :one
|
-- name: CheckUserExistsByEmail :one
|
||||||
SELECT id FROM users WHERE user_mail = $1;
|
SELECT id FROM users WHERE user_mail = $1;
|
||||||
|
|
||||||
-- name: CreateUser :one
|
-- name: GetUserByID :one
|
||||||
INSERT INTO users (id, user_name, user_mail, password) VALUES ($1, $2, $3, $4) RETURNING id;
|
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
|
||||||
@@ -3,7 +3,9 @@ CREATE TABLE IF NOT EXISTS users (
|
|||||||
user_name VARCHAR(255) NOT NULL,
|
user_name VARCHAR(255) NOT NULL,
|
||||||
user_mail VARCHAR(255) NOT NULL UNIQUE,
|
user_mail VARCHAR(255) NOT NULL UNIQUE,
|
||||||
password VARCHAR(255) NOT NULL,
|
password VARCHAR(255) NOT NULL,
|
||||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
session_token VARCHAR(255),
|
||||||
|
session_expiry TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS albums (
|
CREATE TABLE IF NOT EXISTS albums (
|
||||||
@@ -25,6 +27,7 @@ CREATE TABLE IF NOT EXISTS artists (
|
|||||||
CREATE TABLE IF NOT EXISTS user_albums (
|
CREATE TABLE IF NOT EXISTS user_albums (
|
||||||
user_id UUID,
|
user_id UUID,
|
||||||
album_id UUID,
|
album_id UUID,
|
||||||
|
date_added TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
album_owned BOOLEAN NOT NULL DEFAULT FALSE,
|
album_owned BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
album_want BOOLEAN NOT NULL DEFAULT FALSE,
|
album_want BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
is_vinyl BOOLEAN NOT NULL DEFAULT FALSE,
|
is_vinyl BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
|||||||
Reference in New Issue
Block a user