holds.sql.go134 lines, 2.8 KB
| 1 | // Code generated by sqlc. DO NOT EDIT. |
| 2 | // versions: |
| 3 | // sqlc v1.31.1 |
| 4 | // source: holds.sql |
| 5 | |
| 6 | package walletdb |
| 7 | |
| 8 | import ( |
| 9 | "context" |
| 10 | |
| 11 | "github.com/google/uuid" |
| 12 | ) |
| 13 | |
| 14 | const createHold = `-- name: CreateHold :one |
| 15 | INSERT INTO holds (id, wallet_id, amount, currency, hold_tx_id) |
| 16 | VALUES ($1, $2, $3, $4, $5) |
| 17 | RETURNING id, wallet_id, amount, currency, status, hold_tx_id, settled_to, settle_tx_id, created_at, settled_at |
| 18 | ` |
| 19 | |
| 20 | type CreateHoldParams struct { |
| 21 | ID uuid.UUID `json:"id"` |
| 22 | WalletID uuid.UUID `json:"wallet_id"` |
| 23 | Amount int64 `json:"amount"` |
| 24 | Currency string `json:"currency"` |
| 25 | HoldTxID uuid.UUID `json:"hold_tx_id"` |
| 26 | } |
| 27 | |
| 28 | func (q *Queries) CreateHold(ctx context.Context, arg CreateHoldParams) (Hold, error) { |
| 29 | row := q.db.QueryRow(ctx, createHold, |
| 30 | arg.ID, |
| 31 | arg.WalletID, |
| 32 | arg.Amount, |
| 33 | arg.Currency, |
| 34 | arg.HoldTxID, |
| 35 | ) |
| 36 | var i Hold |
| 37 | err := row.Scan( |
| 38 | &i.ID, |
| 39 | &i.WalletID, |
| 40 | &i.Amount, |
| 41 | &i.Currency, |
| 42 | &i.Status, |
| 43 | &i.HoldTxID, |
| 44 | &i.SettledTo, |
| 45 | &i.SettleTxID, |
| 46 | &i.CreatedAt, |
| 47 | &i.SettledAt, |
| 48 | ) |
| 49 | return i, err |
| 50 | } |
| 51 | |
| 52 | const getHold = `-- name: GetHold :one |
| 53 | SELECT id, wallet_id, amount, currency, status, hold_tx_id, settled_to, settle_tx_id, created_at, settled_at FROM holds |
| 54 | WHERE id = $1 |
| 55 | ` |
| 56 | |
| 57 | func (q *Queries) GetHold(ctx context.Context, id uuid.UUID) (Hold, error) { |
| 58 | row := q.db.QueryRow(ctx, getHold, id) |
| 59 | var i Hold |
| 60 | err := row.Scan( |
| 61 | &i.ID, |
| 62 | &i.WalletID, |
| 63 | &i.Amount, |
| 64 | &i.Currency, |
| 65 | &i.Status, |
| 66 | &i.HoldTxID, |
| 67 | &i.SettledTo, |
| 68 | &i.SettleTxID, |
| 69 | &i.CreatedAt, |
| 70 | &i.SettledAt, |
| 71 | ) |
| 72 | return i, err |
| 73 | } |
| 74 | |
| 75 | const lockHold = `-- name: LockHold :one |
| 76 | SELECT id, wallet_id, amount, currency, status, hold_tx_id, settled_to, settle_tx_id, created_at, settled_at FROM holds |
| 77 | WHERE id = $1 |
| 78 | FOR UPDATE |
| 79 | ` |
| 80 | |
| 81 | func (q *Queries) LockHold(ctx context.Context, id uuid.UUID) (Hold, error) { |
| 82 | row := q.db.QueryRow(ctx, lockHold, id) |
| 83 | var i Hold |
| 84 | err := row.Scan( |
| 85 | &i.ID, |
| 86 | &i.WalletID, |
| 87 | &i.Amount, |
| 88 | &i.Currency, |
| 89 | &i.Status, |
| 90 | &i.HoldTxID, |
| 91 | &i.SettledTo, |
| 92 | &i.SettleTxID, |
| 93 | &i.CreatedAt, |
| 94 | &i.SettledAt, |
| 95 | ) |
| 96 | return i, err |
| 97 | } |
| 98 | |
| 99 | const settleHold = `-- name: SettleHold :one |
| 100 | UPDATE holds |
| 101 | SET status = $2, settled_to = $3, settle_tx_id = $4, settled_at = now() |
| 102 | WHERE id = $1 AND status = 'held' |
| 103 | RETURNING id, wallet_id, amount, currency, status, hold_tx_id, settled_to, settle_tx_id, created_at, settled_at |
| 104 | ` |
| 105 | |
| 106 | type SettleHoldParams struct { |
| 107 | ID uuid.UUID `json:"id"` |
| 108 | Status HoldStatus `json:"status"` |
| 109 | SettledTo *uuid.UUID `json:"settled_to"` |
| 110 | SettleTxID *uuid.UUID `json:"settle_tx_id"` |
| 111 | } |
| 112 | |
| 113 | func (q *Queries) SettleHold(ctx context.Context, arg SettleHoldParams) (Hold, error) { |
| 114 | row := q.db.QueryRow(ctx, settleHold, |
| 115 | arg.ID, |
| 116 | arg.Status, |
| 117 | arg.SettledTo, |
| 118 | arg.SettleTxID, |
| 119 | ) |
| 120 | var i Hold |
| 121 | err := row.Scan( |
| 122 | &i.ID, |
| 123 | &i.WalletID, |
| 124 | &i.Amount, |
| 125 | &i.Currency, |
| 126 | &i.Status, |
| 127 | &i.HoldTxID, |
| 128 | &i.SettledTo, |
| 129 | &i.SettleTxID, |
| 130 | &i.CreatedAt, |
| 131 | &i.SettledAt, |
| 132 | ) |
| 133 | return i, err |
| 134 | } |