M1/#292: artist queries (upsert/get/list)

This commit is contained in:
2026-04-19 02:31:27 +00:00
parent a243357ce6
commit 7c46d8358f
+20
View File
@@ -0,0 +1,20 @@
-- name: UpsertArtist :one
-- Insert or update by mbid when present; otherwise by (name, sort_name).
-- Callers pass the canonical sort_name; scanner is responsible for derivation.
INSERT INTO artists (name, sort_name, mbid)
VALUES ($1, $2, $3)
ON CONFLICT (mbid) WHERE mbid IS NOT NULL
DO UPDATE SET
name = EXCLUDED.name,
sort_name = EXCLUDED.sort_name,
updated_at = now()
RETURNING *;
-- name: GetArtistByID :one
SELECT * FROM artists WHERE id = $1;
-- name: GetArtistByName :one
SELECT * FROM artists WHERE name = $1 LIMIT 1;
-- name: ListArtists :many
SELECT * FROM artists ORDER BY sort_name;