sqlc+firewalldb: add GetAction SQL query

Add a new SQL query `GetAction` to retrieve a single action by its ID.
This query will be needed for the kvdb to SQL migration of actions
store.
This commit is contained in:
Viktor Torstensson 2025-09-04 01:08:06 +02:00
parent c2c63cc241
commit 5d8f03e241
No known key found for this signature in database
GPG key ID: 961CC8259AE675D4
4 changed files with 36 additions and 0 deletions

View file

@ -11,6 +11,34 @@ import (
"time"
)
const getAction = `-- name: GetAction :one
SELECT id, session_id, account_id, macaroon_identifier, actor_name, feature_name, action_trigger, intent, structured_json_data, rpc_method, rpc_params_json, created_at, action_state, error_reason
FROM actions
WHERE id = $1
`
func (q *Queries) GetAction(ctx context.Context, id int64) (Action, error) {
row := q.db.QueryRowContext(ctx, getAction, id)
var i Action
err := row.Scan(
&i.ID,
&i.SessionID,
&i.AccountID,
&i.MacaroonIdentifier,
&i.ActorName,
&i.FeatureName,
&i.ActionTrigger,
&i.Intent,
&i.StructuredJsonData,
&i.RpcMethod,
&i.RpcParamsJson,
&i.CreatedAt,
&i.ActionState,
&i.ErrorReason,
)
return i, err
}
const insertAction = `-- name: InsertAction :one
INSERT INTO actions (
session_id, account_id, macaroon_identifier, actor_name, feature_name, action_trigger,

View file

@ -24,6 +24,7 @@ type Querier interface {
GetAccountIndex(ctx context.Context, name string) (int64, error)
GetAccountInvoice(ctx context.Context, arg GetAccountInvoiceParams) (AccountInvoice, error)
GetAccountPayment(ctx context.Context, arg GetAccountPaymentParams) (AccountPayment, error)
GetAction(ctx context.Context, id int64) (Action, error)
GetAliasBySessionID(ctx context.Context, id int64) ([]byte, error)
GetAllPrivacyPairs(ctx context.Context, groupID int64) ([]GetAllPrivacyPairsRow, error)
GetFeatureID(ctx context.Context, name string) (int64, error)

View file

@ -13,3 +13,9 @@ UPDATE actions
SET action_state = $1,
error_reason = $2
WHERE id = $3;
-- name: GetAction :one
SELECT *
FROM actions
WHERE id = $1;

View file

@ -35,6 +35,7 @@ type SQLActionQueries interface {
SetActionState(ctx context.Context, arg sqlc.SetActionStateParams) error
ListActions(ctx context.Context, arg sqlc.ListActionsParams) ([]sqlc.Action, error)
CountActions(ctx context.Context, arg sqlc.ActionQueryParams) (int64, error)
GetAction(ctx context.Context, id int64) (sqlc.Action, error)
}
// sqlActionLocator helps us find an action in the SQL DB.