36 lines
639 B
MySQL
36 lines
639 B
MySQL
|
-- name: CreateProduct :one
|
||
|
INSERT INTO products (
|
||
|
merchant_id,
|
||
|
name,
|
||
|
selling_price,
|
||
|
purchase_price,
|
||
|
stock
|
||
|
) VALUES (
|
||
|
$1, $2, $3, $4, $5
|
||
|
)
|
||
|
RETURNING *;
|
||
|
|
||
|
-- name: UpdateProductStock :one
|
||
|
UPDATE products
|
||
|
SET stock = $1
|
||
|
WHERE id = $2
|
||
|
RETURNING stock;
|
||
|
|
||
|
-- name: GetProduct :one
|
||
|
SELECT * FROM products
|
||
|
WHERE id = $1;
|
||
|
|
||
|
-- name: ListProducts :many
|
||
|
SELECT * FROM products
|
||
|
ORDER BY index_id
|
||
|
LIMIT $1
|
||
|
OFFSET $2;
|
||
|
|
||
|
-- name: UpdateProduct :one
|
||
|
UPDATE products
|
||
|
SET name = $2, selling_price = $3, purchase_price = $4, stock = $5, updated_at = $6
|
||
|
WHERE id = $1
|
||
|
RETURNING *;
|
||
|
|
||
|
-- name: DeleteProduct :exec
|
||
|
DELETE FROM products WHERE id = $1;
|