Files
geo/server/internal/tenant/repository/generated/workspace.sql.go
T

239 lines
7.5 KiB
Go
Raw Normal View History

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: workspace.sql
package generated
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
2026-05-20 15:37:25 +08:00
const countArticlesByTenantAndBrand = `-- name: CountArticlesByTenantAndBrand :one
SELECT COUNT(*) FROM articles
2026-05-20 15:37:25 +08:00
WHERE tenant_id = $1 AND brand_id = $2 AND deleted_at IS NULL
`
2026-05-20 15:37:25 +08:00
type CountArticlesByTenantAndBrandParams struct {
TenantID int64 `json:"tenant_id"`
BrandID int64 `json:"brand_id"`
}
func (q *Queries) CountArticlesByTenantAndBrand(ctx context.Context, arg CountArticlesByTenantAndBrandParams) (int64, error) {
row := q.db.QueryRow(ctx, countArticlesByTenantAndBrand, arg.TenantID, arg.BrandID)
var count int64
err := row.Scan(&count)
return count, err
}
const countBrandsByTenant = `-- name: CountBrandsByTenant :one
SELECT COUNT(*) FROM brands
WHERE tenant_id = $1 AND deleted_at IS NULL
`
func (q *Queries) CountBrandsByTenant(ctx context.Context, tenantID int64) (int64, error) {
row := q.db.QueryRow(ctx, countBrandsByTenant, tenantID)
var count int64
err := row.Scan(&count)
return count, err
}
2026-05-20 15:37:25 +08:00
const countPublishedArticlesByTenantAndBrand = `-- name: CountPublishedArticlesByTenantAndBrand :one
SELECT COUNT(*) FROM articles
2026-05-20 15:37:25 +08:00
WHERE tenant_id = $1 AND brand_id = $2 AND publish_status = 'success' AND deleted_at IS NULL
`
2026-05-20 15:37:25 +08:00
type CountPublishedArticlesByTenantAndBrandParams struct {
TenantID int64 `json:"tenant_id"`
BrandID int64 `json:"brand_id"`
}
func (q *Queries) CountPublishedArticlesByTenantAndBrand(ctx context.Context, arg CountPublishedArticlesByTenantAndBrandParams) (int64, error) {
row := q.db.QueryRow(ctx, countPublishedArticlesByTenantAndBrand, arg.TenantID, arg.BrandID)
var count int64
err := row.Scan(&count)
return count, err
}
const getActivePlanForTenant = `-- name: GetActivePlanForTenant :one
SELECT p.plan_code, p.name AS plan_name, p.quota_policy_json,
s.start_at, s.end_at
FROM tenant_plan_subscriptions s
JOIN plans p ON p.id = s.plan_id
WHERE s.tenant_id = $1 AND s.status = 'active' AND s.deleted_at IS NULL
AND s.end_at > NOW()
LIMIT 1
`
type GetActivePlanForTenantRow struct {
PlanCode string `json:"plan_code"`
PlanName string `json:"plan_name"`
QuotaPolicyJson []byte `json:"quota_policy_json"`
StartAt pgtype.Timestamptz `json:"start_at"`
EndAt pgtype.Timestamptz `json:"end_at"`
}
func (q *Queries) GetActivePlanForTenant(ctx context.Context, tenantID int64) (GetActivePlanForTenantRow, error) {
row := q.db.QueryRow(ctx, getActivePlanForTenant, tenantID)
var i GetActivePlanForTenantRow
err := row.Scan(
&i.PlanCode,
&i.PlanName,
&i.QuotaPolicyJson,
&i.StartAt,
&i.EndAt,
)
return i, err
}
const getQuotaSummary = `-- name: GetQuotaSummary :one
SELECT COALESCE(
(SELECT balance_after FROM tenant_quota_ledgers
WHERE tenant_id = $1 AND quota_type = 'article_generation'
ORDER BY created_at DESC LIMIT 1), 0
)::INT AS balance
`
func (q *Queries) GetQuotaSummary(ctx context.Context, tenantID int64) (int32, error) {
row := q.db.QueryRow(ctx, getQuotaSummary, tenantID)
var balance int32
err := row.Scan(&balance)
return balance, err
}
2026-05-20 15:37:25 +08:00
const getRecentArticlesByBrand = `-- name: GetRecentArticlesByBrand :many
SELECT a.id, a.brand_id, a.generate_status, a.publish_status, a.source_type, a.created_at,
av.title, av.markdown_content, av.word_count, av.source_label,
t.template_name,
COALESCE(
NULLIF(gt.input_params_json ->> 'generation_mode', ''),
CASE WHEN a.source_type = 'custom_generation' THEN 'instant'::TEXT ELSE NULL::TEXT END
) AS generation_mode
FROM articles a
LEFT JOIN article_versions av ON av.id = a.current_version_id
LEFT JOIN article_templates t ON t.id = a.template_id
LEFT JOIN LATERAL (
SELECT input_params_json
FROM generation_tasks
WHERE article_id = a.id
ORDER BY created_at DESC
LIMIT 1
) gt ON true
2026-05-20 15:37:25 +08:00
WHERE a.tenant_id = $1 AND a.brand_id = $2 AND a.deleted_at IS NULL
ORDER BY a.created_at DESC
LIMIT 10
`
2026-05-20 15:37:25 +08:00
type GetRecentArticlesByBrandParams struct {
TenantID int64 `json:"tenant_id"`
BrandID int64 `json:"brand_id"`
}
type GetRecentArticlesByBrandRow struct {
ID int64 `json:"id"`
2026-05-20 15:37:25 +08:00
BrandID int64 `json:"brand_id"`
GenerateStatus string `json:"generate_status"`
PublishStatus string `json:"publish_status"`
SourceType string `json:"source_type"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
Title pgtype.Text `json:"title"`
MarkdownContent pgtype.Text `json:"markdown_content"`
WordCount pgtype.Int4 `json:"word_count"`
SourceLabel pgtype.Text `json:"source_label"`
TemplateName pgtype.Text `json:"template_name"`
GenerationMode interface{} `json:"generation_mode"`
}
2026-05-20 15:37:25 +08:00
func (q *Queries) GetRecentArticlesByBrand(ctx context.Context, arg GetRecentArticlesByBrandParams) ([]GetRecentArticlesByBrandRow, error) {
rows, err := q.db.Query(ctx, getRecentArticlesByBrand, arg.TenantID, arg.BrandID)
if err != nil {
return nil, err
}
defer rows.Close()
2026-05-20 15:37:25 +08:00
var items []GetRecentArticlesByBrandRow
for rows.Next() {
2026-05-20 15:37:25 +08:00
var i GetRecentArticlesByBrandRow
if err := rows.Scan(
&i.ID,
2026-05-20 15:37:25 +08:00
&i.BrandID,
&i.GenerateStatus,
&i.PublishStatus,
&i.SourceType,
&i.CreatedAt,
&i.Title,
&i.MarkdownContent,
&i.WordCount,
&i.SourceLabel,
&i.TemplateName,
&i.GenerationMode,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listKolCardsForTenant = `-- name: ListKolCardsForTenant :many
SELECT sp.id AS subscription_prompt_id, sp.granted_at,
GREATEST(p.updated_at, k.updated_at)::timestamptz AS updated_at,
p.name AS prompt_name, p.platform_hint,
k.name AS package_name, k.cover_url AS package_cover,
pf.display_name AS kol_display_name
FROM kol_subscription_prompts sp
JOIN kol_prompts p ON p.id = sp.prompt_id AND p.deleted_at IS NULL
JOIN kol_packages k ON k.id = sp.package_id AND k.deleted_at IS NULL
JOIN kol_profiles pf ON pf.id = k.kol_profile_id
WHERE sp.tenant_id = $1::bigint
AND sp.status = 'active'
AND p.status = 'active'
AND p.published_revision_no IS NOT NULL
ORDER BY GREATEST(p.updated_at, k.updated_at)::timestamptz DESC, sp.granted_at DESC
LIMIT 8
`
type ListKolCardsForTenantRow struct {
SubscriptionPromptID int64 `json:"subscription_prompt_id"`
GrantedAt pgtype.Timestamptz `json:"granted_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
PromptName string `json:"prompt_name"`
PlatformHint pgtype.Text `json:"platform_hint"`
PackageName string `json:"package_name"`
PackageCover pgtype.Text `json:"package_cover"`
KolDisplayName string `json:"kol_display_name"`
}
func (q *Queries) ListKolCardsForTenant(ctx context.Context, tenantID int64) ([]ListKolCardsForTenantRow, error) {
rows, err := q.db.Query(ctx, listKolCardsForTenant, tenantID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListKolCardsForTenantRow
for rows.Next() {
var i ListKolCardsForTenantRow
if err := rows.Scan(
&i.SubscriptionPromptID,
&i.GrantedAt,
&i.UpdatedAt,
&i.PromptName,
&i.PlatformHint,
&i.PackageName,
&i.PackageCover,
&i.KolDisplayName,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}