284 lines
6.6 KiB
Go
284 lines
6.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: campaigns.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
const getCampaignBySlug = `-- name: GetCampaignBySlug :one
|
|
SELECT c.id, c.slug, c.title, c.category, c.summary, c.art,
|
|
o.name, o.initials, o.location, o.blurb,
|
|
COALESCE(o.avatar_url, '') AS avatar_url,
|
|
c.goal_amount, c.ends_at, c.status::text AS status,
|
|
COALESCE(p.total, 0)::int AS raised,
|
|
COALESCE(p.backers, 0)::int AS backers,
|
|
(SELECT COUNT(*) FROM campaign_updates u WHERE u.campaign_id = c.id)::int AS updates,
|
|
(SELECT COUNT(*) FROM comments m WHERE m.campaign_id = c.id)::int AS comments
|
|
FROM campaigns c
|
|
JOIN owners o ON o.id = c.owner_id
|
|
LEFT JOIN (
|
|
SELECT campaign_id, SUM(amount) AS total, COUNT(*) AS backers
|
|
FROM pledges
|
|
WHERE status = ANY($1::pledge_status[])
|
|
GROUP BY campaign_id
|
|
) p ON p.campaign_id = c.id
|
|
WHERE c.slug = $2 AND c.status = ANY($3::campaign_status[])
|
|
`
|
|
|
|
type GetCampaignBySlugParams struct {
|
|
Counted []string
|
|
Slug string
|
|
Public []string
|
|
}
|
|
|
|
type GetCampaignBySlugRow struct {
|
|
ID string
|
|
Slug string
|
|
Title string
|
|
Category string
|
|
Summary string
|
|
Art string
|
|
Name string
|
|
Initials string
|
|
Location string
|
|
Blurb string
|
|
AvatarUrl string
|
|
GoalAmount int
|
|
EndsAt time.Time
|
|
Status string
|
|
Raised int
|
|
Backers int
|
|
Updates int
|
|
Comments int
|
|
}
|
|
|
|
func (q *Queries) GetCampaignBySlug(ctx context.Context, arg GetCampaignBySlugParams) (GetCampaignBySlugRow, error) {
|
|
row := q.db.QueryRow(ctx, getCampaignBySlug, arg.Counted, arg.Slug, arg.Public)
|
|
var i GetCampaignBySlugRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Slug,
|
|
&i.Title,
|
|
&i.Category,
|
|
&i.Summary,
|
|
&i.Art,
|
|
&i.Name,
|
|
&i.Initials,
|
|
&i.Location,
|
|
&i.Blurb,
|
|
&i.AvatarUrl,
|
|
&i.GoalAmount,
|
|
&i.EndsAt,
|
|
&i.Status,
|
|
&i.Raised,
|
|
&i.Backers,
|
|
&i.Updates,
|
|
&i.Comments,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listCampaigns = `-- name: ListCampaigns :many
|
|
|
|
SELECT c.slug, c.title, c.category, c.summary, c.art,
|
|
o.name, o.initials, o.location, o.blurb,
|
|
COALESCE(o.avatar_url, '') AS avatar_url,
|
|
c.goal_amount, c.ends_at, c.status::text AS status,
|
|
COALESCE(p.total, 0)::int AS raised,
|
|
COALESCE(p.backers, 0)::int AS backers
|
|
FROM campaigns c
|
|
JOIN owners o ON o.id = c.owner_id
|
|
LEFT JOIN (
|
|
SELECT campaign_id, SUM(amount) AS total, COUNT(*) AS backers
|
|
FROM pledges
|
|
WHERE status = ANY($1::pledge_status[])
|
|
GROUP BY campaign_id
|
|
) p ON p.campaign_id = c.id
|
|
WHERE c.status = ANY($2::campaign_status[])
|
|
ORDER BY c.status ASC, c.ends_at ASC
|
|
`
|
|
|
|
type ListCampaignsParams struct {
|
|
Counted []string
|
|
Public []string
|
|
}
|
|
|
|
type ListCampaignsRow struct {
|
|
Slug string
|
|
Title string
|
|
Category string
|
|
Summary string
|
|
Art string
|
|
Name string
|
|
Initials string
|
|
Location string
|
|
Blurb string
|
|
AvatarUrl string
|
|
GoalAmount int
|
|
EndsAt time.Time
|
|
Status string
|
|
Raised int
|
|
Backers int
|
|
}
|
|
|
|
// Queries behind the public campaign pages.
|
|
//
|
|
// The raised amount and the backer count are derived from the pledge rows on
|
|
// every read and stored nowhere, which is why each of these carries the
|
|
// counted-status list as a parameter rather than reading a column.
|
|
func (q *Queries) ListCampaigns(ctx context.Context, arg ListCampaignsParams) ([]ListCampaignsRow, error) {
|
|
rows, err := q.db.Query(ctx, listCampaigns, arg.Counted, arg.Public)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListCampaignsRow
|
|
for rows.Next() {
|
|
var i ListCampaignsRow
|
|
if err := rows.Scan(
|
|
&i.Slug,
|
|
&i.Title,
|
|
&i.Category,
|
|
&i.Summary,
|
|
&i.Art,
|
|
&i.Name,
|
|
&i.Initials,
|
|
&i.Location,
|
|
&i.Blurb,
|
|
&i.AvatarUrl,
|
|
&i.GoalAmount,
|
|
&i.EndsAt,
|
|
&i.Status,
|
|
&i.Raised,
|
|
&i.Backers,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listStorySections = `-- name: ListStorySections :many
|
|
SELECT heading, body
|
|
FROM story_sections
|
|
WHERE campaign_id = $1
|
|
ORDER BY position ASC
|
|
`
|
|
|
|
type ListStorySectionsRow struct {
|
|
Heading string
|
|
Body []string
|
|
}
|
|
|
|
func (q *Queries) ListStorySections(ctx context.Context, campaignID string) ([]ListStorySectionsRow, error) {
|
|
rows, err := q.db.Query(ctx, listStorySections, campaignID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListStorySectionsRow
|
|
for rows.Next() {
|
|
var i ListStorySectionsRow
|
|
if err := rows.Scan(&i.Heading, &i.Body); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listTiers = `-- name: ListTiers :many
|
|
SELECT t.id, t.type::text AS type, t.price, t.list_price, t.title, t.includes,
|
|
t.inventory_limit, t.estimated_delivery, t.featured,
|
|
COALESCE(p.backers, 0)::int AS backers
|
|
FROM reward_tiers t
|
|
LEFT JOIN (
|
|
SELECT pl.tier_id, COUNT(*) AS backers
|
|
FROM pledges pl
|
|
WHERE pl.campaign_id = $1
|
|
AND pl.status = ANY($2::pledge_status[])
|
|
GROUP BY pl.tier_id
|
|
) p ON p.tier_id = t.id
|
|
WHERE t.campaign_id = $1
|
|
ORDER BY t.position ASC
|
|
`
|
|
|
|
type ListTiersParams struct {
|
|
CampaignID string
|
|
Counted []string
|
|
}
|
|
|
|
type ListTiersRow struct {
|
|
ID string
|
|
Type string
|
|
Price int
|
|
ListPrice *int
|
|
Title string
|
|
Includes []string
|
|
InventoryLimit *int
|
|
EstimatedDelivery *time.Time
|
|
Featured bool
|
|
Backers int
|
|
}
|
|
|
|
func (q *Queries) ListTiers(ctx context.Context, arg ListTiersParams) ([]ListTiersRow, error) {
|
|
rows, err := q.db.Query(ctx, listTiers, arg.CampaignID, arg.Counted)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListTiersRow
|
|
for rows.Next() {
|
|
var i ListTiersRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Type,
|
|
&i.Price,
|
|
&i.ListPrice,
|
|
&i.Title,
|
|
&i.Includes,
|
|
&i.InventoryLimit,
|
|
&i.EstimatedDelivery,
|
|
&i.Featured,
|
|
&i.Backers,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const platformStats = `-- name: PlatformStats :one
|
|
SELECT (SELECT COUNT(*) FROM campaigns WHERE status = 'AKTIV')::int AS active_count,
|
|
(SELECT COUNT(*) FROM pledges
|
|
WHERE status = ANY($1::pledge_status[]))::int AS backers
|
|
`
|
|
|
|
type PlatformStatsRow struct {
|
|
ActiveCount int
|
|
Backers int
|
|
}
|
|
|
|
func (q *Queries) PlatformStats(ctx context.Context, counted []string) (PlatformStatsRow, error) {
|
|
row := q.db.QueryRow(ctx, platformStats, counted)
|
|
var i PlatformStatsRow
|
|
err := row.Scan(&i.ActiveCount, &i.Backers)
|
|
return i, err
|
|
}
|