mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
This commit introduces the `sqlcmig6` package, which at the time of this commit contains the same queries and models as `sqlc` package. Importantly though, once the kvdb to sql migration is made available in production, the `sqlcmig6` package will not change, as it is intended to represent the sql db as it was at the time of the migration. The sqlcmig6 package is therefore intended to be used in the kvdb to sql migration code, as it is will always be compatible with the sql database when all sql migrations prior to the kvdb to sql migration are applied. When additional sql migrations are added in the future, they may effect the `sqlc` package in such a way that the standard `sqlc` queries and models aren't compatible with kvdb to sql migration code any longer. By preserving the `sqlcmig6` package, we ensure that the kvdb to sql migration code can always use the same queries and models that were available at the time of the migration, even if the `sqlc` package changes in the future. Note that the `sqlcmig6` package have not been generated by `sqlc` (the queries and models are copied from the `sqlc` package), as it is not intended to be changed in the future.
101 lines
2.4 KiB
Go
101 lines
2.4 KiB
Go
package sqlcmig6
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"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,
|
|
intent, structured_json_data, rpc_method, rpc_params_json, created_at,
|
|
action_state, error_reason
|
|
) VALUES (
|
|
$1, $2, $3, $4, $5, $6,
|
|
$7, $8, $9, $10, $11, $12, $13
|
|
) RETURNING id
|
|
`
|
|
|
|
type InsertActionParams struct {
|
|
SessionID sql.NullInt64
|
|
AccountID sql.NullInt64
|
|
MacaroonIdentifier []byte
|
|
ActorName sql.NullString
|
|
FeatureName sql.NullString
|
|
ActionTrigger sql.NullString
|
|
Intent sql.NullString
|
|
StructuredJsonData []byte
|
|
RpcMethod string
|
|
RpcParamsJson []byte
|
|
CreatedAt time.Time
|
|
ActionState int16
|
|
ErrorReason sql.NullString
|
|
}
|
|
|
|
func (q *Queries) InsertAction(ctx context.Context, arg InsertActionParams) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, insertAction,
|
|
arg.SessionID,
|
|
arg.AccountID,
|
|
arg.MacaroonIdentifier,
|
|
arg.ActorName,
|
|
arg.FeatureName,
|
|
arg.ActionTrigger,
|
|
arg.Intent,
|
|
arg.StructuredJsonData,
|
|
arg.RpcMethod,
|
|
arg.RpcParamsJson,
|
|
arg.CreatedAt,
|
|
arg.ActionState,
|
|
arg.ErrorReason,
|
|
)
|
|
var id int64
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const setActionState = `-- name: SetActionState :exec
|
|
UPDATE actions
|
|
SET action_state = $1,
|
|
error_reason = $2
|
|
WHERE id = $3
|
|
`
|
|
|
|
type SetActionStateParams struct {
|
|
ActionState int16
|
|
ErrorReason sql.NullString
|
|
ID int64
|
|
}
|
|
|
|
func (q *Queries) SetActionState(ctx context.Context, arg SetActionStateParams) error {
|
|
_, err := q.db.ExecContext(ctx, setActionState, arg.ActionState, arg.ErrorReason, arg.ID)
|
|
return err
|
|
}
|