naise_pos/db/query/product.sql
2023-04-05 14:04:49 +07:00

50 lines
842 B
SQL

-- name: CreateProduct :one
INSERT INTO products (
merchant_id,
name,
selling_price,
product_type_id,
purchase_price,
product_category_id,
image,
stock
) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8
)
RETURNING *;
-- name: GetStockForUpdateStock :one
SELECT * FROM products
WHERE id = $1
LIMIT 1
FOR NO KEY UPDATE;
-- name: UpdateProductStock :exec
UPDATE products
SET stock = $1
WHERE id = $2;
-- name: GetProduct :one
SELECT * FROM products
WHERE id = $1;
-- name: ListProducts :many
SELECT * FROM products
WHERE merchant_id = $1
ORDER BY index_id
LIMIT $2
OFFSET $3;
-- name: UpdateProduct :one
UPDATE products
SET name = $2,
selling_price = $3,
purchase_price = $4,
product_category_id = $5,
image = $6,
updated_at = $7
WHERE id = $1
RETURNING *;
-- name: DeleteProduct :exec
DELETE FROM products WHERE id = $1;