227 lines
6.3 KiB
Go
227 lines
6.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: subscriptions.sql
|
|
|
|
package billing
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"time"
|
|
)
|
|
|
|
const createSubscription = `-- name: CreateSubscription :one
|
|
INSERT INTO billing.subscriptions (billing_account_id, status, current_period_start, current_period_end)
|
|
VALUES ($1, $2, $3, $4)
|
|
RETURNING subscription_id, billing_account_id, status, current_period_start, current_period_end, cancel_at_period_end, canceled_at, ended_at, created_at, updated_at
|
|
`
|
|
|
|
type CreateSubscriptionParams struct {
|
|
BillingAccountID string `json:"billing_account_id"`
|
|
Status string `json:"status"`
|
|
CurrentPeriodStart sql.NullTime `json:"current_period_start"`
|
|
CurrentPeriodEnd sql.NullTime `json:"current_period_end"`
|
|
}
|
|
|
|
func (q *Queries) CreateSubscription(ctx context.Context, arg CreateSubscriptionParams) (Subscription, error) {
|
|
row := q.db.QueryRowContext(ctx, createSubscription,
|
|
arg.BillingAccountID,
|
|
arg.Status,
|
|
arg.CurrentPeriodStart,
|
|
arg.CurrentPeriodEnd,
|
|
)
|
|
var i Subscription
|
|
err := row.Scan(
|
|
&i.SubscriptionID,
|
|
&i.BillingAccountID,
|
|
&i.Status,
|
|
&i.CurrentPeriodStart,
|
|
&i.CurrentPeriodEnd,
|
|
&i.CancelAtPeriodEnd,
|
|
&i.CanceledAt,
|
|
&i.EndedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getSubscriptionByID = `-- name: GetSubscriptionByID :one
|
|
SELECT subscription_id, billing_account_id, status, current_period_start, current_period_end, cancel_at_period_end, canceled_at, ended_at, created_at, updated_at FROM billing.subscriptions
|
|
WHERE subscription_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetSubscriptionByID(ctx context.Context, subscriptionID string) (Subscription, error) {
|
|
row := q.db.QueryRowContext(ctx, getSubscriptionByID, subscriptionID)
|
|
var i Subscription
|
|
err := row.Scan(
|
|
&i.SubscriptionID,
|
|
&i.BillingAccountID,
|
|
&i.Status,
|
|
&i.CurrentPeriodStart,
|
|
&i.CurrentPeriodEnd,
|
|
&i.CancelAtPeriodEnd,
|
|
&i.CanceledAt,
|
|
&i.EndedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getSubscriptionsByBillingAccountID = `-- name: GetSubscriptionsByBillingAccountID :many
|
|
SELECT subscription_id, billing_account_id, status, current_period_start, current_period_end, cancel_at_period_end, canceled_at, ended_at, created_at, updated_at FROM billing.subscriptions
|
|
WHERE billing_account_id = $1
|
|
ORDER BY created_at DESC
|
|
`
|
|
|
|
func (q *Queries) GetSubscriptionsByBillingAccountID(ctx context.Context, billingAccountID string) ([]Subscription, error) {
|
|
rows, err := q.db.QueryContext(ctx, getSubscriptionsByBillingAccountID, billingAccountID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Subscription{}
|
|
for rows.Next() {
|
|
var i Subscription
|
|
if err := rows.Scan(
|
|
&i.SubscriptionID,
|
|
&i.BillingAccountID,
|
|
&i.Status,
|
|
&i.CurrentPeriodStart,
|
|
&i.CurrentPeriodEnd,
|
|
&i.CancelAtPeriodEnd,
|
|
&i.CanceledAt,
|
|
&i.EndedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); 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 listSubscriptions = `-- name: ListSubscriptions :many
|
|
SELECT
|
|
s.subscription_id,
|
|
s.billing_account_id,
|
|
s.status,
|
|
s.current_period_start,
|
|
s.current_period_end,
|
|
s.cancel_at_period_end,
|
|
s.canceled_at,
|
|
s.ended_at,
|
|
s.created_at,
|
|
s.updated_at,
|
|
ba.name as billing_account_name
|
|
FROM billing.subscriptions s
|
|
JOIN billing.accounts ba ON s.billing_account_id = ba.billing_account_id
|
|
ORDER BY s.created_at DESC
|
|
`
|
|
|
|
type ListSubscriptionsRow struct {
|
|
SubscriptionID string `json:"subscription_id"`
|
|
BillingAccountID string `json:"billing_account_id"`
|
|
Status string `json:"status"`
|
|
CurrentPeriodStart sql.NullTime `json:"current_period_start"`
|
|
CurrentPeriodEnd sql.NullTime `json:"current_period_end"`
|
|
CancelAtPeriodEnd bool `json:"cancel_at_period_end"`
|
|
CanceledAt sql.NullTime `json:"canceled_at"`
|
|
EndedAt sql.NullTime `json:"ended_at"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
BillingAccountName string `json:"billing_account_name"`
|
|
}
|
|
|
|
func (q *Queries) ListSubscriptions(ctx context.Context) ([]ListSubscriptionsRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, listSubscriptions)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListSubscriptionsRow{}
|
|
for rows.Next() {
|
|
var i ListSubscriptionsRow
|
|
if err := rows.Scan(
|
|
&i.SubscriptionID,
|
|
&i.BillingAccountID,
|
|
&i.Status,
|
|
&i.CurrentPeriodStart,
|
|
&i.CurrentPeriodEnd,
|
|
&i.CancelAtPeriodEnd,
|
|
&i.CanceledAt,
|
|
&i.EndedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.BillingAccountName,
|
|
); 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 updateSubscriptionStatus = `-- name: UpdateSubscriptionStatus :one
|
|
UPDATE billing.subscriptions
|
|
SET status = $2,
|
|
current_period_start = $3,
|
|
current_period_end = $4,
|
|
cancel_at_period_end = $5,
|
|
canceled_at = $6,
|
|
ended_at = $7
|
|
WHERE subscription_id = $1
|
|
RETURNING subscription_id, billing_account_id, status, current_period_start, current_period_end, cancel_at_period_end, canceled_at, ended_at, created_at, updated_at
|
|
`
|
|
|
|
type UpdateSubscriptionStatusParams struct {
|
|
SubscriptionID string `json:"subscription_id"`
|
|
Status string `json:"status"`
|
|
CurrentPeriodStart sql.NullTime `json:"current_period_start"`
|
|
CurrentPeriodEnd sql.NullTime `json:"current_period_end"`
|
|
CancelAtPeriodEnd bool `json:"cancel_at_period_end"`
|
|
CanceledAt sql.NullTime `json:"canceled_at"`
|
|
EndedAt sql.NullTime `json:"ended_at"`
|
|
}
|
|
|
|
func (q *Queries) UpdateSubscriptionStatus(ctx context.Context, arg UpdateSubscriptionStatusParams) (Subscription, error) {
|
|
row := q.db.QueryRowContext(ctx, updateSubscriptionStatus,
|
|
arg.SubscriptionID,
|
|
arg.Status,
|
|
arg.CurrentPeriodStart,
|
|
arg.CurrentPeriodEnd,
|
|
arg.CancelAtPeriodEnd,
|
|
arg.CanceledAt,
|
|
arg.EndedAt,
|
|
)
|
|
var i Subscription
|
|
err := row.Scan(
|
|
&i.SubscriptionID,
|
|
&i.BillingAccountID,
|
|
&i.Status,
|
|
&i.CurrentPeriodStart,
|
|
&i.CurrentPeriodEnd,
|
|
&i.CancelAtPeriodEnd,
|
|
&i.CanceledAt,
|
|
&i.EndedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|