Files
member-console/internal/entitlements/pool_provision_ladders.sql.go

260 lines
7.3 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
// source: pool_provision_ladders.sql
package entitlements
import (
"context"
"database/sql"
"time"
)
const countActiveAttachmentsByLadder = `-- name: CountActiveAttachmentsByLadder :one
SELECT COUNT(*) FROM entitlements.pool_provision_ladders
WHERE plan_ladder_id = $1 AND status = 'active'
`
func (q *Queries) CountActiveAttachmentsByLadder(ctx context.Context, planLadderID string) (int64, error) {
row := q.db.QueryRowContext(ctx, countActiveAttachmentsByLadder, planLadderID)
var count int64
err := row.Scan(&count)
return count, err
}
const countActiveAttachmentsByTier = `-- name: CountActiveAttachmentsByTier :one
SELECT COUNT(*) FROM entitlements.pool_provision_ladders
WHERE plan_ladder_id = $1 AND product_id = $2 AND status = 'active'
`
type CountActiveAttachmentsByTierParams struct {
PlanLadderID string `json:"plan_ladder_id"`
ProductID string `json:"product_id"`
}
func (q *Queries) CountActiveAttachmentsByTier(ctx context.Context, arg CountActiveAttachmentsByTierParams) (int64, error) {
row := q.db.QueryRowContext(ctx, countActiveAttachmentsByTier, arg.PlanLadderID, arg.ProductID)
var count int64
err := row.Scan(&count)
return count, err
}
const createPoolProvisionLadder = `-- name: CreatePoolProvisionLadder :one
INSERT INTO entitlements.pool_provision_ladders
(provision_id, plan_ladder_id, product_id, pool_id, status, activated_at, ended_at)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING provision_id, plan_ladder_id, pool_id, status, activated_at, ended_at, created_at, updated_at, product_id
`
type CreatePoolProvisionLadderParams struct {
ProvisionID string `json:"provision_id"`
PlanLadderID string `json:"plan_ladder_id"`
ProductID string `json:"product_id"`
PoolID string `json:"pool_id"`
Status string `json:"status"`
ActivatedAt time.Time `json:"activated_at"`
EndedAt sql.NullTime `json:"ended_at"`
}
func (q *Queries) CreatePoolProvisionLadder(ctx context.Context, arg CreatePoolProvisionLadderParams) (PoolProvisionLadder, error) {
row := q.db.QueryRowContext(ctx, createPoolProvisionLadder,
arg.ProvisionID,
arg.PlanLadderID,
arg.ProductID,
arg.PoolID,
arg.Status,
arg.ActivatedAt,
arg.EndedAt,
)
var i PoolProvisionLadder
err := row.Scan(
&i.ProvisionID,
&i.PlanLadderID,
&i.PoolID,
&i.Status,
&i.ActivatedAt,
&i.EndedAt,
&i.CreatedAt,
&i.UpdatedAt,
&i.ProductID,
)
return i, err
}
const endPoolProvisionLadder = `-- name: EndPoolProvisionLadder :one
UPDATE entitlements.pool_provision_ladders
SET status = 'ended',
ended_at = $1::TIMESTAMPTZ
WHERE provision_id = $2 AND plan_ladder_id = $3
RETURNING provision_id, plan_ladder_id, pool_id, status, activated_at, ended_at, created_at, updated_at, product_id
`
type EndPoolProvisionLadderParams struct {
EndedAt time.Time `json:"ended_at"`
ProvisionID string `json:"provision_id"`
PlanLadderID string `json:"plan_ladder_id"`
}
func (q *Queries) EndPoolProvisionLadder(ctx context.Context, arg EndPoolProvisionLadderParams) (PoolProvisionLadder, error) {
row := q.db.QueryRowContext(ctx, endPoolProvisionLadder, arg.EndedAt, arg.ProvisionID, arg.PlanLadderID)
var i PoolProvisionLadder
err := row.Scan(
&i.ProvisionID,
&i.PlanLadderID,
&i.PoolID,
&i.Status,
&i.ActivatedAt,
&i.EndedAt,
&i.CreatedAt,
&i.UpdatedAt,
&i.ProductID,
)
return i, err
}
const getActiveAttachmentsByPool = `-- name: GetActiveAttachmentsByPool :many
SELECT provision_id, plan_ladder_id, pool_id, status, activated_at, ended_at, created_at, updated_at, product_id FROM entitlements.pool_provision_ladders
WHERE pool_id = $1 AND status = 'active'
ORDER BY activated_at DESC
`
func (q *Queries) GetActiveAttachmentsByPool(ctx context.Context, poolID string) ([]PoolProvisionLadder, error) {
rows, err := q.db.QueryContext(ctx, getActiveAttachmentsByPool, poolID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []PoolProvisionLadder{}
for rows.Next() {
var i PoolProvisionLadder
if err := rows.Scan(
&i.ProvisionID,
&i.PlanLadderID,
&i.PoolID,
&i.Status,
&i.ActivatedAt,
&i.EndedAt,
&i.CreatedAt,
&i.UpdatedAt,
&i.ProductID,
); 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 getActiveLadderAttachmentByPoolLadder = `-- name: GetActiveLadderAttachmentByPoolLadder :one
SELECT provision_id, plan_ladder_id, pool_id, status, activated_at, ended_at, created_at, updated_at, product_id FROM entitlements.pool_provision_ladders
WHERE pool_id = $1 AND plan_ladder_id = $2 AND status = 'active'
LIMIT 1
`
type GetActiveLadderAttachmentByPoolLadderParams struct {
PoolID string `json:"pool_id"`
PlanLadderID string `json:"plan_ladder_id"`
}
func (q *Queries) GetActiveLadderAttachmentByPoolLadder(ctx context.Context, arg GetActiveLadderAttachmentByPoolLadderParams) (PoolProvisionLadder, error) {
row := q.db.QueryRowContext(ctx, getActiveLadderAttachmentByPoolLadder, arg.PoolID, arg.PlanLadderID)
var i PoolProvisionLadder
err := row.Scan(
&i.ProvisionID,
&i.PlanLadderID,
&i.PoolID,
&i.Status,
&i.ActivatedAt,
&i.EndedAt,
&i.CreatedAt,
&i.UpdatedAt,
&i.ProductID,
)
return i, err
}
const getLadderAttachmentsByPool = `-- name: GetLadderAttachmentsByPool :many
SELECT provision_id, plan_ladder_id, pool_id, status, activated_at, ended_at, created_at, updated_at, product_id FROM entitlements.pool_provision_ladders
WHERE pool_id = $1
ORDER BY activated_at DESC
`
func (q *Queries) GetLadderAttachmentsByPool(ctx context.Context, poolID string) ([]PoolProvisionLadder, error) {
rows, err := q.db.QueryContext(ctx, getLadderAttachmentsByPool, poolID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []PoolProvisionLadder{}
for rows.Next() {
var i PoolProvisionLadder
if err := rows.Scan(
&i.ProvisionID,
&i.PlanLadderID,
&i.PoolID,
&i.Status,
&i.ActivatedAt,
&i.EndedAt,
&i.CreatedAt,
&i.UpdatedAt,
&i.ProductID,
); 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 getLadderAttachmentsByProvision = `-- name: GetLadderAttachmentsByProvision :many
SELECT provision_id, plan_ladder_id, pool_id, status, activated_at, ended_at, created_at, updated_at, product_id FROM entitlements.pool_provision_ladders
WHERE provision_id = $1
ORDER BY activated_at ASC
`
func (q *Queries) GetLadderAttachmentsByProvision(ctx context.Context, provisionID string) ([]PoolProvisionLadder, error) {
rows, err := q.db.QueryContext(ctx, getLadderAttachmentsByProvision, provisionID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []PoolProvisionLadder{}
for rows.Next() {
var i PoolProvisionLadder
if err := rows.Scan(
&i.ProvisionID,
&i.PlanLadderID,
&i.PoolID,
&i.Status,
&i.ActivatedAt,
&i.EndedAt,
&i.CreatedAt,
&i.UpdatedAt,
&i.ProductID,
); 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
}