-- name: GetPrimers :many
SELECT primers.id         as id,
       primers.name       as name,
       primers.meta       as meta,
       primers.created_at as created_at,
       m.id               as manufacturer_id,
       m.name             as manufacturer_name,
       m.url              as manufacturer_url
FROM primers
         join manufacturers m on m.id = primers.manufacturer_id
ORDER BY primers.name desc;

-- name: GetPrimerById :one
SELECT primers.id         as id,
       primers.name       as name,
       primers.meta       as meta,
       primers.photo      as photo,
       primers.created_at as created_at,
       m.id               as manufacturer_id,
       m.name             as manufacturer_name,
       m.url              as manufacturer_url
FROM primers
         join manufacturers m on m.id = primers.manufacturer_id
WHERE primers.id = $1;

-- name: InsertPrimer :exec
INSERT INTO primers (id, name, manufacturer_id, meta, photo)
VALUES ($1, $2, $3, $4, $5);

-- name: DeletePrimer :exec
DELETE
FROM primers
WHERE id = $1;

-- name: UpdatePrimer :exec
UPDATE primers
SET name            = $1,
    manufacturer_id = $2,
    meta            = $3,
    photo           = $4
WHERE id = $5;
