-- name: OrderCreate :one
insert into orders (status_name, user_id)
values ($1, $2)
returning id;

-- name: OrderAddItem :exec
insert into order_items (order_id, sku, count)
select $1, $2, $3;

-- name: OrderSetStatus :execrows
update orders
set status_name = $2
where id = $1;

-- name: OrderGetByID :many
select
  o.id as order_id,
  o.status_name as status,
  o.user_id,
  oi.sku,
  oi.count
from orders o
left join order_items oi on oi.order_id = o.id
where o.id = $1
order by oi.id;