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

189 lines
5.2 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: audit.sql
package generated
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const createAuditLog = `-- name: CreateAuditLog :exec
INSERT INTO audit_logs (
operator_id,
tenant_id,
module,
action,
resource_type,
resource_id,
request_id,
before_json,
after_json,
result,
error_message
)
VALUES ($1, $2, $3, $4,
$5, $6, $7,
$8, $9, $10, $11)
`
type CreateAuditLogParams struct {
OperatorID int64 `json:"operator_id"`
TenantID pgtype.Int8 `json:"tenant_id"`
Module string `json:"module"`
Action string `json:"action"`
ResourceType pgtype.Text `json:"resource_type"`
ResourceID pgtype.Int8 `json:"resource_id"`
RequestID pgtype.Text `json:"request_id"`
BeforeJson []byte `json:"before_json"`
AfterJson []byte `json:"after_json"`
Result pgtype.Text `json:"result"`
ErrorMessage pgtype.Text `json:"error_message"`
}
func (q *Queries) CreateAuditLog(ctx context.Context, arg CreateAuditLogParams) error {
_, err := q.db.Exec(ctx, createAuditLog,
arg.OperatorID,
arg.TenantID,
arg.Module,
arg.Action,
arg.ResourceType,
arg.ResourceID,
arg.RequestID,
arg.BeforeJson,
arg.AfterJson,
arg.Result,
arg.ErrorMessage,
)
return err
}
const createGenerationTask = `-- name: CreateGenerationTask :one
INSERT INTO generation_tasks (tenant_id, operator_id, article_id, quota_reservation_id, task_type, request_hash, input_params_json, status)
VALUES ($1, $2, $3, $4,
$5, $6, $7, 'queued')
RETURNING id
`
type CreateGenerationTaskParams struct {
TenantID int64 `json:"tenant_id"`
OperatorID pgtype.Int8 `json:"operator_id"`
ArticleID pgtype.Int8 `json:"article_id"`
QuotaReservationID pgtype.Int8 `json:"quota_reservation_id"`
TaskType string `json:"task_type"`
RequestHash pgtype.Text `json:"request_hash"`
InputParamsJson []byte `json:"input_params_json"`
}
func (q *Queries) CreateGenerationTask(ctx context.Context, arg CreateGenerationTaskParams) (int64, error) {
row := q.db.QueryRow(ctx, createGenerationTask,
arg.TenantID,
arg.OperatorID,
arg.ArticleID,
arg.QuotaReservationID,
arg.TaskType,
arg.RequestHash,
arg.InputParamsJson,
)
var id int64
err := row.Scan(&id)
return id, err
}
const createTaskRecord = `-- name: CreateTaskRecord :one
INSERT INTO task_records (tenant_id, operator_id, task_type, resource_type, resource_id, status)
VALUES ($1, $2, $3,
$4, $5, $6)
RETURNING id
`
type CreateTaskRecordParams struct {
TenantID int64 `json:"tenant_id"`
OperatorID pgtype.Int8 `json:"operator_id"`
TaskType string `json:"task_type"`
ResourceType string `json:"resource_type"`
ResourceID int64 `json:"resource_id"`
Status string `json:"status"`
}
func (q *Queries) CreateTaskRecord(ctx context.Context, arg CreateTaskRecordParams) (int64, error) {
row := q.db.QueryRow(ctx, createTaskRecord,
arg.TenantID,
arg.OperatorID,
arg.TaskType,
arg.ResourceType,
arg.ResourceID,
arg.Status,
)
var id int64
err := row.Scan(&id)
return id, err
}
const updateGenerationTaskStatus = `-- name: UpdateGenerationTaskStatus :exec
UPDATE generation_tasks SET status = $1::text, error_message = $2,
started_at = $3,
completed_at = $4,
lease_token = CASE WHEN $1::text IN ('completed', 'failed') THEN NULL ELSE lease_token END,
lease_owner = CASE WHEN $1::text IN ('completed', 'failed') THEN NULL ELSE lease_owner END,
lease_expires_at = CASE WHEN $1::text IN ('completed', 'failed') THEN NULL ELSE lease_expires_at END,
updated_at = NOW()
WHERE id = $5 AND tenant_id = $6
`
type UpdateGenerationTaskStatusParams struct {
Status string `json:"status"`
ErrorMessage pgtype.Text `json:"error_message"`
StartedAt pgtype.Timestamptz `json:"started_at"`
CompletedAt pgtype.Timestamptz `json:"completed_at"`
ID int64 `json:"id"`
TenantID int64 `json:"tenant_id"`
}
func (q *Queries) UpdateGenerationTaskStatus(ctx context.Context, arg UpdateGenerationTaskStatusParams) error {
_, err := q.db.Exec(ctx, updateGenerationTaskStatus,
arg.Status,
arg.ErrorMessage,
arg.StartedAt,
arg.CompletedAt,
arg.ID,
arg.TenantID,
)
return err
}
const updateTaskRecordStatus = `-- name: UpdateTaskRecordStatus :exec
UPDATE task_records
SET status = $1,
error_message = $2,
updated_at = NOW()
WHERE tenant_id = $3
AND task_type = $4
AND resource_type = $5
AND resource_id = $6
`
type UpdateTaskRecordStatusParams struct {
Status string `json:"status"`
ErrorMessage pgtype.Text `json:"error_message"`
TenantID int64 `json:"tenant_id"`
TaskType string `json:"task_type"`
ResourceType string `json:"resource_type"`
ResourceID int64 `json:"resource_id"`
}
func (q *Queries) UpdateTaskRecordStatus(ctx context.Context, arg UpdateTaskRecordStatusParams) error {
_, err := q.db.Exec(ctx, updateTaskRecordStatus,
arg.Status,
arg.ErrorMessage,
arg.TenantID,
arg.TaskType,
arg.ResourceType,
arg.ResourceID,
)
return err
}