move queries to db folder, change database to better accommodate musicbrainz api data
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
-- albums.sql
|
||||
-- name: GetAlbumByID :one
|
||||
SELECT * FROM albums WHERE id = $1;
|
||||
|
||||
-- name: GetAllAlbums :many
|
||||
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;
|
||||
@@ -1,18 +0,0 @@
|
||||
-- artists.sql
|
||||
-- name: GetArtistByID :one
|
||||
SELECT * FROM artists WHERE id = $1;
|
||||
|
||||
-- name: GetAllArtists :many
|
||||
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 || '%';
|
||||
@@ -1,28 +0,0 @@
|
||||
-- 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)
|
||||
ON CONFLICT (user_id, album_id) DO UPDATE SET
|
||||
album_owned = EXCLUDED.album_owned,
|
||||
album_want = EXCLUDED.album_want,
|
||||
is_vinyl = EXCLUDED.is_vinyl,
|
||||
is_cd = EXCLUDED.is_cd;
|
||||
@@ -1,17 +0,0 @@
|
||||
-- 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: GetUserByID :one
|
||||
SELECT id, user_name, user_mail, created_at FROM users WHERE id = $1;
|
||||
|
||||
-- name: GetUserAuthByEmail :one
|
||||
SELECT id, user_name, user_mail, password
|
||||
FROM users
|
||||
WHERE user_mail = $1;
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
{
|
||||
"engine": "postgresql",
|
||||
"schema": "../db/db.sql",
|
||||
"queries": "./queries/",
|
||||
"queries": "../db/queries/",
|
||||
"gen": {
|
||||
"go": {
|
||||
"package": "sqlc",
|
||||
|
||||
Reference in New Issue
Block a user