321 lines
8.1 KiB
Go
321 lines
8.1 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: products.sql
|
|
|
|
package billing
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/sqlc-dev/pqtype"
|
|
)
|
|
|
|
const createProduct = `-- 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 product_id, name, description, product_type, metadata, is_active, is_public, created_at, updated_at, entitlement_set_id, lifecycle_status
|
|
`
|
|
|
|
type CreateProductParams struct {
|
|
Name string `json:"name"`
|
|
Description sql.NullString `json:"description"`
|
|
ProductType sql.NullString `json:"product_type"`
|
|
IsActive bool `json:"is_active"`
|
|
IsPublic bool `json:"is_public"`
|
|
EntitlementSetID uuid.NullUUID `json:"entitlement_set_id"`
|
|
LifecycleStatus string `json:"lifecycle_status"`
|
|
}
|
|
|
|
func (q *Queries) CreateProduct(ctx context.Context, arg CreateProductParams) (Product, error) {
|
|
row := q.db.QueryRowContext(ctx, createProduct,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.ProductType,
|
|
arg.IsActive,
|
|
arg.IsPublic,
|
|
arg.EntitlementSetID,
|
|
arg.LifecycleStatus,
|
|
)
|
|
var i Product
|
|
err := row.Scan(
|
|
&i.ProductID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ProductType,
|
|
&i.Metadata,
|
|
&i.IsActive,
|
|
&i.IsPublic,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.EntitlementSetID,
|
|
&i.LifecycleStatus,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getProductByID = `-- name: GetProductByID :one
|
|
SELECT product_id, name, description, product_type, metadata, is_active, is_public, created_at, updated_at, entitlement_set_id, lifecycle_status FROM billing.products
|
|
WHERE product_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetProductByID(ctx context.Context, productID string) (Product, error) {
|
|
row := q.db.QueryRowContext(ctx, getProductByID, productID)
|
|
var i Product
|
|
err := row.Scan(
|
|
&i.ProductID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ProductType,
|
|
&i.Metadata,
|
|
&i.IsActive,
|
|
&i.IsPublic,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.EntitlementSetID,
|
|
&i.LifecycleStatus,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getProductByName = `-- name: GetProductByName :one
|
|
SELECT product_id, name, description, product_type, metadata, is_active, is_public, created_at, updated_at, entitlement_set_id, lifecycle_status FROM billing.products
|
|
WHERE name = $1
|
|
`
|
|
|
|
func (q *Queries) GetProductByName(ctx context.Context, name string) (Product, error) {
|
|
row := q.db.QueryRowContext(ctx, getProductByName, name)
|
|
var i Product
|
|
err := row.Scan(
|
|
&i.ProductID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ProductType,
|
|
&i.Metadata,
|
|
&i.IsActive,
|
|
&i.IsPublic,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.EntitlementSetID,
|
|
&i.LifecycleStatus,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listActiveProducts = `-- name: ListActiveProducts :many
|
|
SELECT product_id, name, description, product_type, metadata, is_active, is_public, created_at, updated_at, entitlement_set_id, lifecycle_status FROM billing.products
|
|
WHERE is_active = TRUE
|
|
ORDER BY name ASC
|
|
`
|
|
|
|
func (q *Queries) ListActiveProducts(ctx context.Context) ([]Product, error) {
|
|
rows, err := q.db.QueryContext(ctx, listActiveProducts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Product{}
|
|
for rows.Next() {
|
|
var i Product
|
|
if err := rows.Scan(
|
|
&i.ProductID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ProductType,
|
|
&i.Metadata,
|
|
&i.IsActive,
|
|
&i.IsPublic,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.EntitlementSetID,
|
|
&i.LifecycleStatus,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listAllProducts = `-- name: ListAllProducts :many
|
|
SELECT product_id, name, description, product_type, metadata, is_active, is_public, created_at, updated_at, entitlement_set_id, lifecycle_status FROM billing.products
|
|
ORDER BY name ASC
|
|
`
|
|
|
|
func (q *Queries) ListAllProducts(ctx context.Context) ([]Product, error) {
|
|
rows, err := q.db.QueryContext(ctx, listAllProducts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Product{}
|
|
for rows.Next() {
|
|
var i Product
|
|
if err := rows.Scan(
|
|
&i.ProductID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ProductType,
|
|
&i.Metadata,
|
|
&i.IsActive,
|
|
&i.IsPublic,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.EntitlementSetID,
|
|
&i.LifecycleStatus,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listPublicPlanProducts = `-- name: ListPublicPlanProducts :many
|
|
SELECT p.product_id, p.name, p.description, p.product_type, p.metadata, p.is_active, p.is_public, p.created_at, p.updated_at, p.entitlement_set_id, p.lifecycle_status 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
|
|
`
|
|
|
|
// 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.
|
|
func (q *Queries) ListPublicPlanProducts(ctx context.Context) ([]Product, error) {
|
|
rows, err := q.db.QueryContext(ctx, listPublicPlanProducts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Product{}
|
|
for rows.Next() {
|
|
var i Product
|
|
if err := rows.Scan(
|
|
&i.ProductID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ProductType,
|
|
&i.Metadata,
|
|
&i.IsActive,
|
|
&i.IsPublic,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.EntitlementSetID,
|
|
&i.LifecycleStatus,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listPublicProducts = `-- name: ListPublicProducts :many
|
|
SELECT product_id, name, description, product_type, metadata, is_active, is_public, created_at, updated_at, entitlement_set_id, lifecycle_status FROM billing.products
|
|
WHERE is_active = TRUE AND is_public = TRUE
|
|
ORDER BY name ASC
|
|
`
|
|
|
|
func (q *Queries) ListPublicProducts(ctx context.Context) ([]Product, error) {
|
|
rows, err := q.db.QueryContext(ctx, listPublicProducts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Product{}
|
|
for rows.Next() {
|
|
var i Product
|
|
if err := rows.Scan(
|
|
&i.ProductID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ProductType,
|
|
&i.Metadata,
|
|
&i.IsActive,
|
|
&i.IsPublic,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.EntitlementSetID,
|
|
&i.LifecycleStatus,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateProduct = `-- 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 product_id, name, description, product_type, metadata, is_active, is_public, created_at, updated_at, entitlement_set_id, lifecycle_status
|
|
`
|
|
|
|
type UpdateProductParams struct {
|
|
ProductID string `json:"product_id"`
|
|
Name string `json:"name"`
|
|
Description sql.NullString `json:"description"`
|
|
ProductType sql.NullString `json:"product_type"`
|
|
IsActive bool `json:"is_active"`
|
|
IsPublic bool `json:"is_public"`
|
|
EntitlementSetID uuid.NullUUID `json:"entitlement_set_id"`
|
|
Metadata pqtype.NullRawMessage `json:"metadata"`
|
|
}
|
|
|
|
func (q *Queries) UpdateProduct(ctx context.Context, arg UpdateProductParams) (Product, error) {
|
|
row := q.db.QueryRowContext(ctx, updateProduct,
|
|
arg.ProductID,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.ProductType,
|
|
arg.IsActive,
|
|
arg.IsPublic,
|
|
arg.EntitlementSetID,
|
|
arg.Metadata,
|
|
)
|
|
var i Product
|
|
err := row.Scan(
|
|
&i.ProductID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ProductType,
|
|
&i.Metadata,
|
|
&i.IsActive,
|
|
&i.IsPublic,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.EntitlementSetID,
|
|
&i.LifecycleStatus,
|
|
)
|
|
return i, err
|
|
}
|