35 lines
968 B
SQL
35 lines
968 B
SQL
-- name: ListAttributes :many
|
|||
|
|
SELECT * FROM attributes
|
||
|
|
WHERE company_id = $1
|
||
|
|
ORDER BY name;
|
||
|
|
|
||
|
|
-- name: GetAttribute :one
|
||
|
|
SELECT * FROM attributes
|
||
|
|
WHERE id = $1 AND company_id = $2
|
||
|
|
LIMIT 1;
|
||
|
|
|
||
|
|
-- name: CreateAttribute :one
|
||
|
|
INSERT INTO attributes (company_id, attribute_key, name, value_type, unit, example, parent_key)
|
||
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||
|
|
RETURNING *;
|
||
|
|
|
||
|
|
-- name: UpdateAttribute :one
|
||
|
|
UPDATE attributes
|
||
|
|
SET name = COALESCE($3, name),
|
||
|
|
value_type = COALESCE($4, value_type),
|
||
|
|
unit = COALESCE($5, unit),
|
||
|
|
example = COALESCE($6, example),
|
||
|
|
updated_at = now()
|
||
|
|
WHERE id = $1 AND company_id = $2
|
||
|
|
RETURNING *;
|
||
|
|
|
||
|
|
-- name: DeleteAttribute :exec
|
||
|
|
DELETE FROM attributes WHERE id = $1 AND company_id = $2;
|
||
|
|
|
||
|
|
-- name: ListCategoryAttributes :many
|
||
|
|
SELECT ca.*, a.attribute_key, a.name AS attribute_name, a.value_type
|
||
|
|
FROM category_attributes ca
|
||
|
|
JOIN attributes a ON a.id = ca.attribute_id
|
||
|
|
WHERE ca.company_id = $1 AND ca.category_unique_id = $2
|
||
|
|
ORDER BY a.name;
|