-- name: GetPowderById :one
select powders.id   as id,
       powders.name as name,
       powders.created_at,
       powders.photo,
       meta,
       m.id         as manufacturer_id,
       m.name       as manufacturer_name,
       m.url        as manufacturer_url
from powders
         join manufacturers m on m.id = powders.manufacturer_id
where powders.id = $1;

-- name: GetPowders :many
select powders.id   as id,
       powders.name as name,
       powders.created_at,
       meta,
       m.id         as manufacturer_id,
       m.name       as manufacturer_name,
       m.url        as manufacturer_url
from powders
         join manufacturers m on m.id = powders.manufacturer_id
order by powders.name desc;

-- name: DeletePowder :exec
DELETE
FROM powders
WHERE id = $1;

-- name: InsertPowder :exec
insert into powders (id, name, manufacturer_id, meta, photo)
values ($1, $2, $3, $4, $5);

-- name: UpdatePowder :exec
update powders
set name            = $1,
    manufacturer_id = $2,
    meta            = $3,
    photo           = $4
where id = $5;