naise_pos/db/query/product.sql

50 lines
842 B
MySQL
Raw Permalink Normal View History

2023-03-05 23:35:41 +07:00
-- name: CreateProduct :one
INSERT INTO products (
merchant_id,
name,
selling_price,
2023-03-22 13:40:18 +07:00
product_type_id,
2023-03-05 23:35:41 +07:00
purchase_price,
2023-03-16 20:37:20 +07:00
product_category_id,
2023-04-05 14:04:49 +07:00
image,
2023-03-05 23:35:41 +07:00
stock
) VALUES (
2023-04-05 14:04:49 +07:00
$1, $2, $3, $4, $5, $6, $7, $8
2023-03-05 23:35:41 +07:00
)
RETURNING *;
2023-03-06 15:15:11 +07:00
-- name: GetStockForUpdateStock :one
SELECT * FROM products
WHERE id = $1
LIMIT 1
FOR NO KEY UPDATE;
-- name: UpdateProductStock :exec
2023-03-05 23:35:41 +07:00
UPDATE products
SET stock = $1
2023-03-06 15:15:11 +07:00
WHERE id = $2;
2023-03-05 23:35:41 +07:00
-- name: GetProduct :one
SELECT * FROM products
WHERE id = $1;
-- name: ListProducts :many
SELECT * FROM products
2023-03-15 15:00:36 +07:00
WHERE merchant_id = $1
2023-03-05 23:35:41 +07:00
ORDER BY index_id
2023-03-15 15:00:36 +07:00
LIMIT $2
OFFSET $3;
2023-03-05 23:35:41 +07:00
-- name: UpdateProduct :one
UPDATE products
2023-04-05 14:04:49 +07:00
SET name = $2,
selling_price = $3,
purchase_price = $4,
product_category_id = $5,
image = $6,
updated_at = $7
2023-03-05 23:35:41 +07:00
WHERE id = $1
RETURNING *;
-- name: DeleteProduct :exec
DELETE FROM products WHERE id = $1;