Files
member-console/internal/billing/queries/products.sql

44 lines
1.3 KiB
SQL

-- name: GetProductByID :one
SELECT * FROM billing.products
WHERE product_id = $1;
-- name: GetProductByName :one
SELECT * FROM billing.products
WHERE name = $1;
-- name: ListActiveProducts :many
SELECT * FROM billing.products
WHERE is_active = TRUE
ORDER BY name ASC;
-- name: ListPublicProducts :many
SELECT * FROM billing.products
WHERE is_active = TRUE AND is_public = TRUE
ORDER BY name ASC;
-- name: ListPublicPlanProducts :many
-- Plan products are those attached to a ladder via plan_ladder_tiers
-- (Doc 31 Amendment #3). product_type is NULL for plans; kind is
-- derived structurally.
SELECT p.* FROM billing.products p
WHERE p.is_active = TRUE AND p.is_public = TRUE
AND EXISTS (
SELECT 1 FROM billing.plan_ladder_tiers t WHERE t.product_id = p.product_id
)
ORDER BY p.name ASC;
-- name: ListAllProducts :many
SELECT * FROM billing.products
ORDER BY name ASC;
-- name: CreateProduct :one
INSERT INTO billing.products (name, description, product_type, is_active, is_public, entitlement_set_id, lifecycle_status)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING *;
-- name: UpdateProduct :one
UPDATE billing.products
SET name = $2, description = $3, product_type = $4, is_active = $5, is_public = $6, entitlement_set_id = $7, metadata = $8
WHERE product_id = $1
RETURNING *;