Files
gochat/channels/shangwutong/db/generated/accounts.sql.go
T

667 lines
19 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: accounts.sql
package dbgen
import (
"context"
)
const applyAccountSession = `-- name: ApplyAccountSession :one
UPDATE accounts SET
password = COALESCE(pending_password, password),
pending_password = NULL,
credential_state = 'applied',
applied_config_version = config_version,
config_sync_status = 'applied',
base_url = ?,
site_id = ?,
login_name = ?,
ma_token = ?,
actual_presence = ?,
connection_status = 'connected',
failure_count = 0,
last_error_code = NULL,
last_error_message = NULL,
last_login_at = CURRENT_TIMESTAMP,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
RETURNING id, gochat_account_id, gochat_inbox_id, gochat_inbox_identifier, config_version, applied_config_version, config_sync_status, session_id, username, password, pending_password, credential_state, enabled, desired_presence, actual_presence, connection_status, base_url, site_id, login_name, ma_token, maxwordid, maxotick, maxtmpid, gochat_hmac_token, gochat_webhook_secret, failure_count, last_error_code, last_error_message, last_login_at, last_heartbeat_at, last_config_sync_at, deleted_at, created_at, updated_at
`
type ApplyAccountSessionParams struct {
BaseUrl *string `json:"base_url"`
SiteID *string `json:"site_id"`
LoginName *string `json:"login_name"`
MaToken *string `json:"ma_token"`
ActualPresence string `json:"actual_presence"`
ID int64 `json:"id"`
}
func (q *Queries) ApplyAccountSession(ctx context.Context, arg ApplyAccountSessionParams) (*Account, error) {
row := q.db.QueryRowContext(ctx, applyAccountSession,
arg.BaseUrl,
arg.SiteID,
arg.LoginName,
arg.MaToken,
arg.ActualPresence,
arg.ID,
)
var i Account
err := row.Scan(
&i.ID,
&i.GochatAccountID,
&i.GochatInboxID,
&i.GochatInboxIdentifier,
&i.ConfigVersion,
&i.AppliedConfigVersion,
&i.ConfigSyncStatus,
&i.SessionID,
&i.Username,
&i.Password,
&i.PendingPassword,
&i.CredentialState,
&i.Enabled,
&i.DesiredPresence,
&i.ActualPresence,
&i.ConnectionStatus,
&i.BaseUrl,
&i.SiteID,
&i.LoginName,
&i.MaToken,
&i.Maxwordid,
&i.Maxotick,
&i.Maxtmpid,
&i.GochatHmacToken,
&i.GochatWebhookSecret,
&i.FailureCount,
&i.LastErrorCode,
&i.LastErrorMessage,
&i.LastLoginAt,
&i.LastHeartbeatAt,
&i.LastConfigSyncAt,
&i.DeletedAt,
&i.CreatedAt,
&i.UpdatedAt,
)
return &i, err
}
const clearAccountSession = `-- name: ClearAccountSession :exec
UPDATE accounts SET
ma_token = NULL,
actual_presence = 'offline',
connection_status = 'relogin_required',
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
`
func (q *Queries) ClearAccountSession(ctx context.Context, id int64) error {
_, err := q.db.ExecContext(ctx, clearAccountSession, id)
return err
}
const createAccount = `-- name: CreateAccount :one
INSERT INTO accounts (
gochat_account_id, gochat_inbox_id, gochat_inbox_identifier,
config_version, session_id, username, password, enabled,
desired_presence, gochat_hmac_token, gochat_webhook_secret,
last_config_sync_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
RETURNING id, gochat_account_id, gochat_inbox_id, gochat_inbox_identifier, config_version, applied_config_version, config_sync_status, session_id, username, password, pending_password, credential_state, enabled, desired_presence, actual_presence, connection_status, base_url, site_id, login_name, ma_token, maxwordid, maxotick, maxtmpid, gochat_hmac_token, gochat_webhook_secret, failure_count, last_error_code, last_error_message, last_login_at, last_heartbeat_at, last_config_sync_at, deleted_at, created_at, updated_at
`
type CreateAccountParams struct {
GochatAccountID int64 `json:"gochat_account_id"`
GochatInboxID int64 `json:"gochat_inbox_id"`
GochatInboxIdentifier string `json:"gochat_inbox_identifier"`
ConfigVersion int64 `json:"config_version"`
SessionID string `json:"session_id"`
Username string `json:"username"`
Password string `json:"password"`
Enabled int64 `json:"enabled"`
DesiredPresence string `json:"desired_presence"`
GochatHmacToken string `json:"gochat_hmac_token"`
GochatWebhookSecret string `json:"gochat_webhook_secret"`
}
func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (*Account, error) {
row := q.db.QueryRowContext(ctx, createAccount,
arg.GochatAccountID,
arg.GochatInboxID,
arg.GochatInboxIdentifier,
arg.ConfigVersion,
arg.SessionID,
arg.Username,
arg.Password,
arg.Enabled,
arg.DesiredPresence,
arg.GochatHmacToken,
arg.GochatWebhookSecret,
)
var i Account
err := row.Scan(
&i.ID,
&i.GochatAccountID,
&i.GochatInboxID,
&i.GochatInboxIdentifier,
&i.ConfigVersion,
&i.AppliedConfigVersion,
&i.ConfigSyncStatus,
&i.SessionID,
&i.Username,
&i.Password,
&i.PendingPassword,
&i.CredentialState,
&i.Enabled,
&i.DesiredPresence,
&i.ActualPresence,
&i.ConnectionStatus,
&i.BaseUrl,
&i.SiteID,
&i.LoginName,
&i.MaToken,
&i.Maxwordid,
&i.Maxotick,
&i.Maxtmpid,
&i.GochatHmacToken,
&i.GochatWebhookSecret,
&i.FailureCount,
&i.LastErrorCode,
&i.LastErrorMessage,
&i.LastLoginAt,
&i.LastHeartbeatAt,
&i.LastConfigSyncAt,
&i.DeletedAt,
&i.CreatedAt,
&i.UpdatedAt,
)
return &i, err
}
const getAccountByID = `-- name: GetAccountByID :one
SELECT id, gochat_account_id, gochat_inbox_id, gochat_inbox_identifier, config_version, applied_config_version, config_sync_status, session_id, username, password, pending_password, credential_state, enabled, desired_presence, actual_presence, connection_status, base_url, site_id, login_name, ma_token, maxwordid, maxotick, maxtmpid, gochat_hmac_token, gochat_webhook_secret, failure_count, last_error_code, last_error_message, last_login_at, last_heartbeat_at, last_config_sync_at, deleted_at, created_at, updated_at FROM accounts WHERE id = ? LIMIT 1
`
func (q *Queries) GetAccountByID(ctx context.Context, id int64) (*Account, error) {
row := q.db.QueryRowContext(ctx, getAccountByID, id)
var i Account
err := row.Scan(
&i.ID,
&i.GochatAccountID,
&i.GochatInboxID,
&i.GochatInboxIdentifier,
&i.ConfigVersion,
&i.AppliedConfigVersion,
&i.ConfigSyncStatus,
&i.SessionID,
&i.Username,
&i.Password,
&i.PendingPassword,
&i.CredentialState,
&i.Enabled,
&i.DesiredPresence,
&i.ActualPresence,
&i.ConnectionStatus,
&i.BaseUrl,
&i.SiteID,
&i.LoginName,
&i.MaToken,
&i.Maxwordid,
&i.Maxotick,
&i.Maxtmpid,
&i.GochatHmacToken,
&i.GochatWebhookSecret,
&i.FailureCount,
&i.LastErrorCode,
&i.LastErrorMessage,
&i.LastLoginAt,
&i.LastHeartbeatAt,
&i.LastConfigSyncAt,
&i.DeletedAt,
&i.CreatedAt,
&i.UpdatedAt,
)
return &i, err
}
const getAccountByInboxID = `-- name: GetAccountByInboxID :one
SELECT id, gochat_account_id, gochat_inbox_id, gochat_inbox_identifier, config_version, applied_config_version, config_sync_status, session_id, username, password, pending_password, credential_state, enabled, desired_presence, actual_presence, connection_status, base_url, site_id, login_name, ma_token, maxwordid, maxotick, maxtmpid, gochat_hmac_token, gochat_webhook_secret, failure_count, last_error_code, last_error_message, last_login_at, last_heartbeat_at, last_config_sync_at, deleted_at, created_at, updated_at FROM accounts WHERE gochat_inbox_id = ? LIMIT 1
`
func (q *Queries) GetAccountByInboxID(ctx context.Context, gochatInboxID int64) (*Account, error) {
row := q.db.QueryRowContext(ctx, getAccountByInboxID, gochatInboxID)
var i Account
err := row.Scan(
&i.ID,
&i.GochatAccountID,
&i.GochatInboxID,
&i.GochatInboxIdentifier,
&i.ConfigVersion,
&i.AppliedConfigVersion,
&i.ConfigSyncStatus,
&i.SessionID,
&i.Username,
&i.Password,
&i.PendingPassword,
&i.CredentialState,
&i.Enabled,
&i.DesiredPresence,
&i.ActualPresence,
&i.ConnectionStatus,
&i.BaseUrl,
&i.SiteID,
&i.LoginName,
&i.MaToken,
&i.Maxwordid,
&i.Maxotick,
&i.Maxtmpid,
&i.GochatHmacToken,
&i.GochatWebhookSecret,
&i.FailureCount,
&i.LastErrorCode,
&i.LastErrorMessage,
&i.LastLoginAt,
&i.LastHeartbeatAt,
&i.LastConfigSyncAt,
&i.DeletedAt,
&i.CreatedAt,
&i.UpdatedAt,
)
return &i, err
}
const listAccounts = `-- name: ListAccounts :many
SELECT id, gochat_account_id, gochat_inbox_id, gochat_inbox_identifier, config_version, applied_config_version, config_sync_status, session_id, username, password, pending_password, credential_state, enabled, desired_presence, actual_presence, connection_status, base_url, site_id, login_name, ma_token, maxwordid, maxotick, maxtmpid, gochat_hmac_token, gochat_webhook_secret, failure_count, last_error_code, last_error_message, last_login_at, last_heartbeat_at, last_config_sync_at, deleted_at, created_at, updated_at FROM accounts ORDER BY id
`
func (q *Queries) ListAccounts(ctx context.Context) ([]*Account, error) {
rows, err := q.db.QueryContext(ctx, listAccounts)
if err != nil {
return nil, err
}
defer rows.Close()
items := []*Account{}
for rows.Next() {
var i Account
if err := rows.Scan(
&i.ID,
&i.GochatAccountID,
&i.GochatInboxID,
&i.GochatInboxIdentifier,
&i.ConfigVersion,
&i.AppliedConfigVersion,
&i.ConfigSyncStatus,
&i.SessionID,
&i.Username,
&i.Password,
&i.PendingPassword,
&i.CredentialState,
&i.Enabled,
&i.DesiredPresence,
&i.ActualPresence,
&i.ConnectionStatus,
&i.BaseUrl,
&i.SiteID,
&i.LoginName,
&i.MaToken,
&i.Maxwordid,
&i.Maxotick,
&i.Maxtmpid,
&i.GochatHmacToken,
&i.GochatWebhookSecret,
&i.FailureCount,
&i.LastErrorCode,
&i.LastErrorMessage,
&i.LastLoginAt,
&i.LastHeartbeatAt,
&i.LastConfigSyncAt,
&i.DeletedAt,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listRunnableAccounts = `-- name: ListRunnableAccounts :many
SELECT id, gochat_account_id, gochat_inbox_id, gochat_inbox_identifier, config_version, applied_config_version, config_sync_status, session_id, username, password, pending_password, credential_state, enabled, desired_presence, actual_presence, connection_status, base_url, site_id, login_name, ma_token, maxwordid, maxotick, maxtmpid, gochat_hmac_token, gochat_webhook_secret, failure_count, last_error_code, last_error_message, last_login_at, last_heartbeat_at, last_config_sync_at, deleted_at, created_at, updated_at FROM accounts
WHERE enabled = 1
AND desired_presence <> 'offline'
AND deleted_at IS NULL
ORDER BY id
`
func (q *Queries) ListRunnableAccounts(ctx context.Context) ([]*Account, error) {
rows, err := q.db.QueryContext(ctx, listRunnableAccounts)
if err != nil {
return nil, err
}
defer rows.Close()
items := []*Account{}
for rows.Next() {
var i Account
if err := rows.Scan(
&i.ID,
&i.GochatAccountID,
&i.GochatInboxID,
&i.GochatInboxIdentifier,
&i.ConfigVersion,
&i.AppliedConfigVersion,
&i.ConfigSyncStatus,
&i.SessionID,
&i.Username,
&i.Password,
&i.PendingPassword,
&i.CredentialState,
&i.Enabled,
&i.DesiredPresence,
&i.ActualPresence,
&i.ConnectionStatus,
&i.BaseUrl,
&i.SiteID,
&i.LoginName,
&i.MaToken,
&i.Maxwordid,
&i.Maxotick,
&i.Maxtmpid,
&i.GochatHmacToken,
&i.GochatWebhookSecret,
&i.FailureCount,
&i.LastErrorCode,
&i.LastErrorMessage,
&i.LastLoginAt,
&i.LastHeartbeatAt,
&i.LastConfigSyncAt,
&i.DeletedAt,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const markAccountConfigApplied = `-- name: MarkAccountConfigApplied :exec
UPDATE accounts SET
applied_config_version = config_version,
config_sync_status = 'applied',
credential_state = CASE
WHEN pending_password IS NULL THEN 'applied'
ELSE credential_state
END,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
`
func (q *Queries) MarkAccountConfigApplied(ctx context.Context, id int64) error {
_, err := q.db.ExecContext(ctx, markAccountConfigApplied, id)
return err
}
const markAccountDeleted = `-- name: MarkAccountDeleted :exec
UPDATE accounts SET
enabled = 0,
desired_presence = 'offline',
actual_presence = 'offline',
connection_status = 'disabled',
config_sync_status = 'deleted',
deleted_at = CURRENT_TIMESTAMP,
updated_at = CURRENT_TIMESTAMP
WHERE gochat_inbox_id = ? AND deleted_at IS NULL
`
func (q *Queries) MarkAccountDeleted(ctx context.Context, gochatInboxID int64) error {
_, err := q.db.ExecContext(ctx, markAccountDeleted, gochatInboxID)
return err
}
const rejectPendingCredential = `-- name: RejectPendingCredential :exec
UPDATE accounts SET
credential_state = ?,
config_sync_status = 'rejected',
connection_status = ?,
failure_count = failure_count + 1,
last_error_code = ?,
last_error_message = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ? AND pending_password IS NOT NULL
`
type RejectPendingCredentialParams struct {
CredentialState string `json:"credential_state"`
ConnectionStatus string `json:"connection_status"`
LastErrorCode *string `json:"last_error_code"`
LastErrorMessage *string `json:"last_error_message"`
ID int64 `json:"id"`
}
func (q *Queries) RejectPendingCredential(ctx context.Context, arg RejectPendingCredentialParams) error {
_, err := q.db.ExecContext(ctx, rejectPendingCredential,
arg.CredentialState,
arg.ConnectionStatus,
arg.LastErrorCode,
arg.LastErrorMessage,
arg.ID,
)
return err
}
const stopAccountRuntime = `-- name: StopAccountRuntime :exec
UPDATE accounts SET
actual_presence = 'offline',
connection_status = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
`
type StopAccountRuntimeParams struct {
ConnectionStatus string `json:"connection_status"`
ID int64 `json:"id"`
}
func (q *Queries) StopAccountRuntime(ctx context.Context, arg StopAccountRuntimeParams) error {
_, err := q.db.ExecContext(ctx, stopAccountRuntime, arg.ConnectionStatus, arg.ID)
return err
}
const touchAccountHeartbeat = `-- name: TouchAccountHeartbeat :exec
UPDATE accounts SET
last_heartbeat_at = CURRENT_TIMESTAMP,
connection_status = 'connected',
failure_count = 0,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
`
func (q *Queries) TouchAccountHeartbeat(ctx context.Context, id int64) error {
_, err := q.db.ExecContext(ctx, touchAccountHeartbeat, id)
return err
}
const updateAccountConfig = `-- name: UpdateAccountConfig :one
UPDATE accounts SET
gochat_account_id = ?1,
gochat_inbox_identifier = ?2,
config_version = ?3,
pending_password = ?4,
credential_state = ?5,
enabled = ?6,
desired_presence = ?7,
gochat_hmac_token = ?8,
gochat_webhook_secret = ?9,
config_sync_status = 'pending',
last_config_sync_at = CURRENT_TIMESTAMP,
deleted_at = NULL,
updated_at = CURRENT_TIMESTAMP
WHERE gochat_inbox_id = ?10
AND config_version < ?3
RETURNING id, gochat_account_id, gochat_inbox_id, gochat_inbox_identifier, config_version, applied_config_version, config_sync_status, session_id, username, password, pending_password, credential_state, enabled, desired_presence, actual_presence, connection_status, base_url, site_id, login_name, ma_token, maxwordid, maxotick, maxtmpid, gochat_hmac_token, gochat_webhook_secret, failure_count, last_error_code, last_error_message, last_login_at, last_heartbeat_at, last_config_sync_at, deleted_at, created_at, updated_at
`
type UpdateAccountConfigParams struct {
GochatAccountID int64 `json:"gochat_account_id"`
GochatInboxIdentifier string `json:"gochat_inbox_identifier"`
ConfigVersion int64 `json:"config_version"`
PendingPassword *string `json:"pending_password"`
CredentialState string `json:"credential_state"`
Enabled int64 `json:"enabled"`
DesiredPresence string `json:"desired_presence"`
GochatHmacToken string `json:"gochat_hmac_token"`
GochatWebhookSecret string `json:"gochat_webhook_secret"`
GochatInboxID int64 `json:"gochat_inbox_id"`
}
func (q *Queries) UpdateAccountConfig(ctx context.Context, arg UpdateAccountConfigParams) (*Account, error) {
row := q.db.QueryRowContext(ctx, updateAccountConfig,
arg.GochatAccountID,
arg.GochatInboxIdentifier,
arg.ConfigVersion,
arg.PendingPassword,
arg.CredentialState,
arg.Enabled,
arg.DesiredPresence,
arg.GochatHmacToken,
arg.GochatWebhookSecret,
arg.GochatInboxID,
)
var i Account
err := row.Scan(
&i.ID,
&i.GochatAccountID,
&i.GochatInboxID,
&i.GochatInboxIdentifier,
&i.ConfigVersion,
&i.AppliedConfigVersion,
&i.ConfigSyncStatus,
&i.SessionID,
&i.Username,
&i.Password,
&i.PendingPassword,
&i.CredentialState,
&i.Enabled,
&i.DesiredPresence,
&i.ActualPresence,
&i.ConnectionStatus,
&i.BaseUrl,
&i.SiteID,
&i.LoginName,
&i.MaToken,
&i.Maxwordid,
&i.Maxotick,
&i.Maxtmpid,
&i.GochatHmacToken,
&i.GochatWebhookSecret,
&i.FailureCount,
&i.LastErrorCode,
&i.LastErrorMessage,
&i.LastLoginAt,
&i.LastHeartbeatAt,
&i.LastConfigSyncAt,
&i.DeletedAt,
&i.CreatedAt,
&i.UpdatedAt,
)
return &i, err
}
const updateAccountCursor = `-- name: UpdateAccountCursor :exec
UPDATE accounts SET
maxwordid = ?,
maxotick = ?,
maxtmpid = ?,
last_heartbeat_at = CURRENT_TIMESTAMP,
connection_status = 'connected',
failure_count = 0,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
`
type UpdateAccountCursorParams struct {
Maxwordid int64 `json:"maxwordid"`
Maxotick int64 `json:"maxotick"`
Maxtmpid int64 `json:"maxtmpid"`
ID int64 `json:"id"`
}
func (q *Queries) UpdateAccountCursor(ctx context.Context, arg UpdateAccountCursorParams) error {
_, err := q.db.ExecContext(ctx, updateAccountCursor,
arg.Maxwordid,
arg.Maxotick,
arg.Maxtmpid,
arg.ID,
)
return err
}
const updateAccountPresence = `-- name: UpdateAccountPresence :exec
UPDATE accounts SET
actual_presence = ?,
connection_status = ?,
failure_count = 0,
last_error_code = NULL,
last_error_message = NULL,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
`
type UpdateAccountPresenceParams struct {
ActualPresence string `json:"actual_presence"`
ConnectionStatus string `json:"connection_status"`
ID int64 `json:"id"`
}
func (q *Queries) UpdateAccountPresence(ctx context.Context, arg UpdateAccountPresenceParams) error {
_, err := q.db.ExecContext(ctx, updateAccountPresence, arg.ActualPresence, arg.ConnectionStatus, arg.ID)
return err
}
const updateAccountRuntimeError = `-- name: UpdateAccountRuntimeError :exec
UPDATE accounts SET
connection_status = ?,
credential_state = ?,
failure_count = failure_count + 1,
last_error_code = ?,
last_error_message = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
`
type UpdateAccountRuntimeErrorParams struct {
ConnectionStatus string `json:"connection_status"`
CredentialState string `json:"credential_state"`
LastErrorCode *string `json:"last_error_code"`
LastErrorMessage *string `json:"last_error_message"`
ID int64 `json:"id"`
}
func (q *Queries) UpdateAccountRuntimeError(ctx context.Context, arg UpdateAccountRuntimeErrorParams) error {
_, err := q.db.ExecContext(ctx, updateAccountRuntimeError,
arg.ConnectionStatus,
arg.CredentialState,
arg.LastErrorCode,
arg.LastErrorMessage,
arg.ID,
)
return err
}