331 lines
11 KiB
Go
331 lines
11 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: schedule_task.sql
|
|
|
|
package generated
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const countScheduleTasks = `-- name: CountScheduleTasks :one
|
|
SELECT COUNT(*)
|
|
FROM schedule_tasks
|
|
WHERE tenant_id = $1
|
|
AND deleted_at IS NULL
|
|
AND ($2::text IS NULL OR status = $2)
|
|
AND ($3::bigint IS NULL OR prompt_rule_id = $3)
|
|
`
|
|
|
|
type CountScheduleTasksParams struct {
|
|
TenantID int64 `json:"tenant_id"`
|
|
Status pgtype.Text `json:"status"`
|
|
PromptRuleID pgtype.Int8 `json:"prompt_rule_id"`
|
|
}
|
|
|
|
func (q *Queries) CountScheduleTasks(ctx context.Context, arg CountScheduleTasksParams) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countScheduleTasks, arg.TenantID, arg.Status, arg.PromptRuleID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createScheduleTask = `-- name: CreateScheduleTask :one
|
|
INSERT INTO schedule_tasks (tenant_id, workspace_id, prompt_rule_id, brand_id, name, cron_expr,
|
|
auto_publish, publish_account_ids, cover_asset_url, cover_image_asset_id,
|
|
start_at, end_at, next_run_at)
|
|
VALUES ($1, $2, $3, $4, $5,
|
|
$6, $7, $8, $9,
|
|
$10, $11, $12,
|
|
$13)
|
|
RETURNING id, created_at
|
|
`
|
|
|
|
type CreateScheduleTaskParams struct {
|
|
TenantID int64 `json:"tenant_id"`
|
|
WorkspaceID pgtype.Int8 `json:"workspace_id"`
|
|
PromptRuleID pgtype.Int8 `json:"prompt_rule_id"`
|
|
BrandID pgtype.Int8 `json:"brand_id"`
|
|
Name string `json:"name"`
|
|
CronExpr string `json:"cron_expr"`
|
|
AutoPublish bool `json:"auto_publish"`
|
|
PublishAccountIds []byte `json:"publish_account_ids"`
|
|
CoverAssetUrl pgtype.Text `json:"cover_asset_url"`
|
|
CoverImageAssetID pgtype.Int8 `json:"cover_image_asset_id"`
|
|
StartAt pgtype.Timestamptz `json:"start_at"`
|
|
EndAt pgtype.Timestamptz `json:"end_at"`
|
|
NextRunAt pgtype.Timestamptz `json:"next_run_at"`
|
|
}
|
|
|
|
type CreateScheduleTaskRow struct {
|
|
ID int64 `json:"id"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
}
|
|
|
|
func (q *Queries) CreateScheduleTask(ctx context.Context, arg CreateScheduleTaskParams) (CreateScheduleTaskRow, error) {
|
|
row := q.db.QueryRow(ctx, createScheduleTask,
|
|
arg.TenantID,
|
|
arg.WorkspaceID,
|
|
arg.PromptRuleID,
|
|
arg.BrandID,
|
|
arg.Name,
|
|
arg.CronExpr,
|
|
arg.AutoPublish,
|
|
arg.PublishAccountIds,
|
|
arg.CoverAssetUrl,
|
|
arg.CoverImageAssetID,
|
|
arg.StartAt,
|
|
arg.EndAt,
|
|
arg.NextRunAt,
|
|
)
|
|
var i CreateScheduleTaskRow
|
|
err := row.Scan(&i.ID, &i.CreatedAt)
|
|
return i, err
|
|
}
|
|
|
|
const getScheduleTaskByID = `-- name: GetScheduleTaskByID :one
|
|
SELECT st.id, st.tenant_id, st.workspace_id, st.prompt_rule_id, st.brand_id, st.name,
|
|
st.cron_expr, st.auto_publish, st.publish_account_ids, st.cover_asset_url, st.cover_image_asset_id,
|
|
st.start_at, st.end_at,
|
|
st.next_run_at, st.status, st.created_at, st.updated_at,
|
|
pr.name AS prompt_rule_name,
|
|
b.name AS brand_name
|
|
FROM schedule_tasks st
|
|
LEFT JOIN prompt_rules pr ON pr.id = st.prompt_rule_id
|
|
LEFT JOIN brands b ON b.id = st.brand_id
|
|
WHERE st.id = $1 AND st.tenant_id = $2 AND st.deleted_at IS NULL
|
|
`
|
|
|
|
type GetScheduleTaskByIDParams struct {
|
|
ID int64 `json:"id"`
|
|
TenantID int64 `json:"tenant_id"`
|
|
}
|
|
|
|
type GetScheduleTaskByIDRow struct {
|
|
ID int64 `json:"id"`
|
|
TenantID int64 `json:"tenant_id"`
|
|
WorkspaceID pgtype.Int8 `json:"workspace_id"`
|
|
PromptRuleID pgtype.Int8 `json:"prompt_rule_id"`
|
|
BrandID pgtype.Int8 `json:"brand_id"`
|
|
Name string `json:"name"`
|
|
CronExpr string `json:"cron_expr"`
|
|
AutoPublish bool `json:"auto_publish"`
|
|
PublishAccountIds []byte `json:"publish_account_ids"`
|
|
CoverAssetUrl pgtype.Text `json:"cover_asset_url"`
|
|
CoverImageAssetID pgtype.Int8 `json:"cover_image_asset_id"`
|
|
StartAt pgtype.Timestamptz `json:"start_at"`
|
|
EndAt pgtype.Timestamptz `json:"end_at"`
|
|
NextRunAt pgtype.Timestamptz `json:"next_run_at"`
|
|
Status string `json:"status"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
PromptRuleName pgtype.Text `json:"prompt_rule_name"`
|
|
BrandName pgtype.Text `json:"brand_name"`
|
|
}
|
|
|
|
func (q *Queries) GetScheduleTaskByID(ctx context.Context, arg GetScheduleTaskByIDParams) (GetScheduleTaskByIDRow, error) {
|
|
row := q.db.QueryRow(ctx, getScheduleTaskByID, arg.ID, arg.TenantID)
|
|
var i GetScheduleTaskByIDRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.TenantID,
|
|
&i.WorkspaceID,
|
|
&i.PromptRuleID,
|
|
&i.BrandID,
|
|
&i.Name,
|
|
&i.CronExpr,
|
|
&i.AutoPublish,
|
|
&i.PublishAccountIds,
|
|
&i.CoverAssetUrl,
|
|
&i.CoverImageAssetID,
|
|
&i.StartAt,
|
|
&i.EndAt,
|
|
&i.NextRunAt,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.PromptRuleName,
|
|
&i.BrandName,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listScheduleTasks = `-- name: ListScheduleTasks :many
|
|
SELECT st.id, st.tenant_id, st.workspace_id, st.prompt_rule_id, st.brand_id, st.name,
|
|
st.cron_expr, st.auto_publish, st.publish_account_ids, st.cover_asset_url, st.cover_image_asset_id,
|
|
st.start_at, st.end_at,
|
|
st.next_run_at, st.status, st.created_at, st.updated_at,
|
|
pr.name AS prompt_rule_name,
|
|
b.name AS brand_name
|
|
FROM schedule_tasks st
|
|
LEFT JOIN prompt_rules pr ON pr.id = st.prompt_rule_id
|
|
LEFT JOIN brands b ON b.id = st.brand_id
|
|
WHERE st.tenant_id = $1
|
|
AND st.deleted_at IS NULL
|
|
AND ($2::text IS NULL OR st.status = $2)
|
|
AND ($3::bigint IS NULL OR st.prompt_rule_id = $3)
|
|
ORDER BY st.created_at DESC
|
|
LIMIT $5 OFFSET $4
|
|
`
|
|
|
|
type ListScheduleTasksParams struct {
|
|
TenantID int64 `json:"tenant_id"`
|
|
Status pgtype.Text `json:"status"`
|
|
PromptRuleID pgtype.Int8 `json:"prompt_rule_id"`
|
|
PageOffset int32 `json:"page_offset"`
|
|
PageSize int32 `json:"page_size"`
|
|
}
|
|
|
|
type ListScheduleTasksRow struct {
|
|
ID int64 `json:"id"`
|
|
TenantID int64 `json:"tenant_id"`
|
|
WorkspaceID pgtype.Int8 `json:"workspace_id"`
|
|
PromptRuleID pgtype.Int8 `json:"prompt_rule_id"`
|
|
BrandID pgtype.Int8 `json:"brand_id"`
|
|
Name string `json:"name"`
|
|
CronExpr string `json:"cron_expr"`
|
|
AutoPublish bool `json:"auto_publish"`
|
|
PublishAccountIds []byte `json:"publish_account_ids"`
|
|
CoverAssetUrl pgtype.Text `json:"cover_asset_url"`
|
|
CoverImageAssetID pgtype.Int8 `json:"cover_image_asset_id"`
|
|
StartAt pgtype.Timestamptz `json:"start_at"`
|
|
EndAt pgtype.Timestamptz `json:"end_at"`
|
|
NextRunAt pgtype.Timestamptz `json:"next_run_at"`
|
|
Status string `json:"status"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
PromptRuleName pgtype.Text `json:"prompt_rule_name"`
|
|
BrandName pgtype.Text `json:"brand_name"`
|
|
}
|
|
|
|
func (q *Queries) ListScheduleTasks(ctx context.Context, arg ListScheduleTasksParams) ([]ListScheduleTasksRow, error) {
|
|
rows, err := q.db.Query(ctx, listScheduleTasks,
|
|
arg.TenantID,
|
|
arg.Status,
|
|
arg.PromptRuleID,
|
|
arg.PageOffset,
|
|
arg.PageSize,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListScheduleTasksRow
|
|
for rows.Next() {
|
|
var i ListScheduleTasksRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.TenantID,
|
|
&i.WorkspaceID,
|
|
&i.PromptRuleID,
|
|
&i.BrandID,
|
|
&i.Name,
|
|
&i.CronExpr,
|
|
&i.AutoPublish,
|
|
&i.PublishAccountIds,
|
|
&i.CoverAssetUrl,
|
|
&i.CoverImageAssetID,
|
|
&i.StartAt,
|
|
&i.EndAt,
|
|
&i.NextRunAt,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.PromptRuleName,
|
|
&i.BrandName,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const softDeleteScheduleTask = `-- name: SoftDeleteScheduleTask :exec
|
|
UPDATE schedule_tasks SET deleted_at = NOW(), updated_at = NOW()
|
|
WHERE id = $1 AND tenant_id = $2 AND deleted_at IS NULL
|
|
`
|
|
|
|
type SoftDeleteScheduleTaskParams struct {
|
|
ID int64 `json:"id"`
|
|
TenantID int64 `json:"tenant_id"`
|
|
}
|
|
|
|
func (q *Queries) SoftDeleteScheduleTask(ctx context.Context, arg SoftDeleteScheduleTaskParams) error {
|
|
_, err := q.db.Exec(ctx, softDeleteScheduleTask, arg.ID, arg.TenantID)
|
|
return err
|
|
}
|
|
|
|
const updateScheduleTask = `-- name: UpdateScheduleTask :exec
|
|
UPDATE schedule_tasks
|
|
SET prompt_rule_id = $1, brand_id = $2,
|
|
name = $3, cron_expr = $4,
|
|
workspace_id = $5,
|
|
auto_publish = $6,
|
|
publish_account_ids = $7,
|
|
cover_asset_url = $8,
|
|
cover_image_asset_id = $9,
|
|
start_at = $10, end_at = $11,
|
|
next_run_at = $12, updated_at = NOW()
|
|
WHERE id = $13 AND tenant_id = $14 AND deleted_at IS NULL
|
|
`
|
|
|
|
type UpdateScheduleTaskParams struct {
|
|
PromptRuleID pgtype.Int8 `json:"prompt_rule_id"`
|
|
BrandID pgtype.Int8 `json:"brand_id"`
|
|
Name string `json:"name"`
|
|
CronExpr string `json:"cron_expr"`
|
|
WorkspaceID pgtype.Int8 `json:"workspace_id"`
|
|
AutoPublish bool `json:"auto_publish"`
|
|
PublishAccountIds []byte `json:"publish_account_ids"`
|
|
CoverAssetUrl pgtype.Text `json:"cover_asset_url"`
|
|
CoverImageAssetID pgtype.Int8 `json:"cover_image_asset_id"`
|
|
StartAt pgtype.Timestamptz `json:"start_at"`
|
|
EndAt pgtype.Timestamptz `json:"end_at"`
|
|
NextRunAt pgtype.Timestamptz `json:"next_run_at"`
|
|
ID int64 `json:"id"`
|
|
TenantID int64 `json:"tenant_id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateScheduleTask(ctx context.Context, arg UpdateScheduleTaskParams) error {
|
|
_, err := q.db.Exec(ctx, updateScheduleTask,
|
|
arg.PromptRuleID,
|
|
arg.BrandID,
|
|
arg.Name,
|
|
arg.CronExpr,
|
|
arg.WorkspaceID,
|
|
arg.AutoPublish,
|
|
arg.PublishAccountIds,
|
|
arg.CoverAssetUrl,
|
|
arg.CoverImageAssetID,
|
|
arg.StartAt,
|
|
arg.EndAt,
|
|
arg.NextRunAt,
|
|
arg.ID,
|
|
arg.TenantID,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const updateScheduleTaskStatus = `-- name: UpdateScheduleTaskStatus :exec
|
|
UPDATE schedule_tasks SET status = $1, updated_at = NOW()
|
|
WHERE id = $2 AND tenant_id = $3 AND deleted_at IS NULL
|
|
`
|
|
|
|
type UpdateScheduleTaskStatusParams struct {
|
|
Status string `json:"status"`
|
|
ID int64 `json:"id"`
|
|
TenantID int64 `json:"tenant_id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateScheduleTaskStatus(ctx context.Context, arg UpdateScheduleTaskStatusParams) error {
|
|
_, err := q.db.Exec(ctx, updateScheduleTaskStatus, arg.Status, arg.ID, arg.TenantID)
|
|
return err
|
|
}
|