// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: classification_sync.sql package dbgen import ( "context" "time" ) const claimClassificationSyncResult = `-- name: ClaimClassificationSyncResult :one UPDATE classification_sync_results SET status = 'syncing', attempts = attempts + 1, next_attempt_at = NULL, updated_at = CURRENT_TIMESTAMP WHERE id = ( SELECT candidate.id FROM classification_sync_results AS candidate JOIN accounts AS account ON account.id = candidate.account_id WHERE candidate.status IN ('pending', 'failed') AND candidate.attempts < 10 AND account.enabled = 1 AND account.desired_presence <> 'offline' AND account.deleted_at IS NULL AND (candidate.next_attempt_at IS NULL OR julianday(candidate.next_attempt_at) IS NULL OR julianday(candidate.next_attempt_at) <= julianday('now')) ORDER BY candidate.id LIMIT 1 ) AND status IN ('pending', 'failed') AND attempts < 10 RETURNING id, account_id, inbox_id, event_id, phase, status, conversation_kinds, customer_colors, attempts, next_attempt_at, last_error_code, last_error_message, created_at, updated_at ` func (q *Queries) ClaimClassificationSyncResult(ctx context.Context) (*ClassificationSyncResult, error) { row := q.db.QueryRowContext(ctx, claimClassificationSyncResult) var i ClassificationSyncResult err := row.Scan( &i.ID, &i.AccountID, &i.InboxID, &i.EventID, &i.Phase, &i.Status, &i.ConversationKinds, &i.CustomerColors, &i.Attempts, &i.NextAttemptAt, &i.LastErrorCode, &i.LastErrorMessage, &i.CreatedAt, &i.UpdatedAt, ) return &i, err } const claimClassificationSyncResultByID = `-- name: ClaimClassificationSyncResultByID :one UPDATE classification_sync_results SET status = 'syncing', attempts = attempts + 1, next_attempt_at = NULL, updated_at = CURRENT_TIMESTAMP WHERE classification_sync_results.id = ? AND classification_sync_results.status IN ('pending', 'failed') AND classification_sync_results.attempts < 10 AND EXISTS ( SELECT 1 FROM accounts AS account WHERE account.id = classification_sync_results.account_id AND account.enabled = 1 AND account.desired_presence <> 'offline' AND account.deleted_at IS NULL ) AND (classification_sync_results.next_attempt_at IS NULL OR julianday(classification_sync_results.next_attempt_at) IS NULL OR julianday(classification_sync_results.next_attempt_at) <= julianday('now')) RETURNING id, account_id, inbox_id, event_id, phase, status, conversation_kinds, customer_colors, attempts, next_attempt_at, last_error_code, last_error_message, created_at, updated_at ` func (q *Queries) ClaimClassificationSyncResultByID(ctx context.Context, id int64) (*ClassificationSyncResult, error) { row := q.db.QueryRowContext(ctx, claimClassificationSyncResultByID, id) var i ClassificationSyncResult err := row.Scan( &i.ID, &i.AccountID, &i.InboxID, &i.EventID, &i.Phase, &i.Status, &i.ConversationKinds, &i.CustomerColors, &i.Attempts, &i.NextAttemptAt, &i.LastErrorCode, &i.LastErrorMessage, &i.CreatedAt, &i.UpdatedAt, ) return &i, err } const completeClassificationSyncResult = `-- name: CompleteClassificationSyncResult :exec UPDATE classification_sync_results SET status = 'succeeded', phase = 'report', next_attempt_at = NULL, last_error_code = NULL, last_error_message = NULL, updated_at = CURRENT_TIMESTAMP WHERE id = ? AND status = 'syncing' ` func (q *Queries) CompleteClassificationSyncResult(ctx context.Context, id int64) error { _, err := q.db.ExecContext(ctx, completeClassificationSyncResult, id) return err } const failClassificationSyncResult = `-- name: FailClassificationSyncResult :exec UPDATE classification_sync_results SET status = 'failed', next_attempt_at = ?, last_error_code = ?, last_error_message = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ? AND status = 'syncing' ` type FailClassificationSyncResultParams struct { NextAttemptAt *time.Time `json:"next_attempt_at"` LastErrorCode *string `json:"last_error_code"` LastErrorMessage *string `json:"last_error_message"` ID int64 `json:"id"` } func (q *Queries) FailClassificationSyncResult(ctx context.Context, arg FailClassificationSyncResultParams) error { _, err := q.db.ExecContext(ctx, failClassificationSyncResult, arg.NextAttemptAt, arg.LastErrorCode, arg.LastErrorMessage, arg.ID, ) return err } const getClassificationSyncResult = `-- name: GetClassificationSyncResult :one SELECT id, account_id, inbox_id, event_id, phase, status, conversation_kinds, customer_colors, attempts, next_attempt_at, last_error_code, last_error_message, created_at, updated_at FROM classification_sync_results WHERE account_id = ? AND event_id = ? LIMIT 1 ` type GetClassificationSyncResultParams struct { AccountID int64 `json:"account_id"` EventID string `json:"event_id"` } func (q *Queries) GetClassificationSyncResult(ctx context.Context, arg GetClassificationSyncResultParams) (*ClassificationSyncResult, error) { row := q.db.QueryRowContext(ctx, getClassificationSyncResult, arg.AccountID, arg.EventID) var i ClassificationSyncResult err := row.Scan( &i.ID, &i.AccountID, &i.InboxID, &i.EventID, &i.Phase, &i.Status, &i.ConversationKinds, &i.CustomerColors, &i.Attempts, &i.NextAttemptAt, &i.LastErrorCode, &i.LastErrorMessage, &i.CreatedAt, &i.UpdatedAt, ) return &i, err } const insertClassificationSyncResult = `-- name: InsertClassificationSyncResult :one INSERT INTO classification_sync_results ( account_id, inbox_id, event_id, phase, status ) VALUES (?, ?, ?, 'read', 'pending') ON CONFLICT(account_id, event_id) DO NOTHING RETURNING id, account_id, inbox_id, event_id, phase, status, conversation_kinds, customer_colors, attempts, next_attempt_at, last_error_code, last_error_message, created_at, updated_at ` type InsertClassificationSyncResultParams struct { AccountID int64 `json:"account_id"` InboxID int64 `json:"inbox_id"` EventID string `json:"event_id"` } func (q *Queries) InsertClassificationSyncResult(ctx context.Context, arg InsertClassificationSyncResultParams) (*ClassificationSyncResult, error) { row := q.db.QueryRowContext(ctx, insertClassificationSyncResult, arg.AccountID, arg.InboxID, arg.EventID) var i ClassificationSyncResult err := row.Scan( &i.ID, &i.AccountID, &i.InboxID, &i.EventID, &i.Phase, &i.Status, &i.ConversationKinds, &i.CustomerColors, &i.Attempts, &i.NextAttemptAt, &i.LastErrorCode, &i.LastErrorMessage, &i.CreatedAt, &i.UpdatedAt, ) return &i, err } const recoverClassificationSyncResult = `-- name: RecoverClassificationSyncResult :exec UPDATE classification_sync_results SET status = 'pending', attempts = CASE WHEN attempts > 0 THEN attempts - 1 ELSE 0 END, next_attempt_at = NULL, updated_at = CURRENT_TIMESTAMP WHERE id = ? AND status = 'syncing' ` func (q *Queries) RecoverClassificationSyncResult(ctx context.Context, id int64) error { _, err := q.db.ExecContext(ctx, recoverClassificationSyncResult, id) return err } const recoverClassificationSyncResults = `-- name: RecoverClassificationSyncResults :execrows UPDATE classification_sync_results SET status = 'pending', attempts = CASE WHEN attempts > 0 THEN attempts - 1 ELSE 0 END, next_attempt_at = NULL, updated_at = CURRENT_TIMESTAMP WHERE status = 'syncing' ` func (q *Queries) RecoverClassificationSyncResults(ctx context.Context) (int64, error) { result, err := q.db.ExecContext(ctx, recoverClassificationSyncResults) if err != nil { return 0, err } return result.RowsAffected() } const resetClassificationSyncResult = `-- name: ResetClassificationSyncResult :exec UPDATE classification_sync_results SET status = 'pending', attempts = 0, next_attempt_at = NULL, last_error_code = NULL, last_error_message = NULL, updated_at = CURRENT_TIMESTAMP WHERE account_id = ? AND event_id = ? AND status = 'failed' ` type ResetClassificationSyncResultParams struct { AccountID int64 `json:"account_id"` EventID string `json:"event_id"` } func (q *Queries) ResetClassificationSyncResult(ctx context.Context, arg ResetClassificationSyncResultParams) error { _, err := q.db.ExecContext(ctx, resetClassificationSyncResult, arg.AccountID, arg.EventID) return err } const setClassificationSyncResultCatalog = `-- name: SetClassificationSyncResultCatalog :exec UPDATE classification_sync_results SET phase = 'report', conversation_kinds = ?, customer_colors = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ? AND status = 'syncing' ` type SetClassificationSyncResultCatalogParams struct { ConversationKinds string `json:"conversation_kinds"` CustomerColors string `json:"customer_colors"` ID int64 `json:"id"` } func (q *Queries) SetClassificationSyncResultCatalog(ctx context.Context, arg SetClassificationSyncResultCatalogParams) error { _, err := q.db.ExecContext(ctx, setClassificationSyncResultCatalog, arg.ConversationKinds, arg.CustomerColors, arg.ID) return err }