sqldb: add queries for deleting a payment and attempts
This commit is contained in:
4 files changed
+42
No files matched your search
@@ -55,6 +55,16 @@ type SQLQueries interface {
|
|||||||
FetchPaymentLevelFirstHopCustomRecords(ctx context.Context, paymentIDs []int64) ([]sqlc.PaymentFirstHopCustomRecord, error)
|
FetchPaymentLevelFirstHopCustomRecords(ctx context.Context, paymentIDs []int64) ([]sqlc.PaymentFirstHopCustomRecord, error)
|
||||||
FetchRouteLevelFirstHopCustomRecords(ctx context.Context, htlcAttemptIndices []int64) ([]sqlc.PaymentAttemptFirstHopCustomRecord, error)
|
FetchRouteLevelFirstHopCustomRecords(ctx context.Context, htlcAttemptIndices []int64) ([]sqlc.PaymentAttemptFirstHopCustomRecord, error)
|
||||||
FetchHopLevelCustomRecords(ctx context.Context, hopIDs []int64) ([]sqlc.PaymentHopCustomRecord, error)
|
FetchHopLevelCustomRecords(ctx context.Context, hopIDs []int64) ([]sqlc.PaymentHopCustomRecord, error)
|
||||||
|
|
||||||
|
/*
|
||||||
|
Payment DB write operations.
|
||||||
|
*/
|
||||||
|
|
||||||
|
DeletePayment(ctx context.Context, paymentID int64) error
|
||||||
|
|
||||||
|
// DeleteFailedAttempts removes all failed HTLCs from the db for a
|
||||||
|
// given payment.
|
||||||
|
DeleteFailedAttempts(ctx context.Context, paymentID int64) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// BatchedSQLQueries is a version of the SQLQueries that's capable
|
// BatchedSQLQueries is a version of the SQLQueries that's capable
|
||||||
|
|||||||
@@ -23,6 +23,26 @@ func (q *Queries) CountPayments(ctx context.Context) (int64, error) {
|
|||||||
return count, err
|
return count, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deleteFailedAttempts = `-- name: DeleteFailedAttempts :exec
|
||||||
|
DELETE FROM payment_htlc_attempts WHERE payment_id = $1 AND attempt_index IN (
|
||||||
|
SELECT attempt_index FROM payment_htlc_attempt_resolutions WHERE resolution_type = 2
|
||||||
|
)
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) DeleteFailedAttempts(ctx context.Context, paymentID int64) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, deleteFailedAttempts, paymentID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const deletePayment = `-- name: DeletePayment :exec
|
||||||
|
DELETE FROM payments WHERE id = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) DeletePayment(ctx context.Context, id int64) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, deletePayment, id)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const fetchAllInflightAttempts = `-- name: FetchAllInflightAttempts :many
|
const fetchAllInflightAttempts = `-- name: FetchAllInflightAttempts :many
|
||||||
SELECT
|
SELECT
|
||||||
ha.id,
|
ha.id,
|
||||||
|
|||||||
@@ -22,11 +22,13 @@ type Querier interface {
|
|||||||
DeleteChannelPolicyExtraTypes(ctx context.Context, channelPolicyID int64) error
|
DeleteChannelPolicyExtraTypes(ctx context.Context, channelPolicyID int64) error
|
||||||
DeleteChannels(ctx context.Context, ids []int64) error
|
DeleteChannels(ctx context.Context, ids []int64) error
|
||||||
DeleteExtraNodeType(ctx context.Context, arg DeleteExtraNodeTypeParams) error
|
DeleteExtraNodeType(ctx context.Context, arg DeleteExtraNodeTypeParams) error
|
||||||
|
DeleteFailedAttempts(ctx context.Context, paymentID int64) error
|
||||||
DeleteInvoice(ctx context.Context, arg DeleteInvoiceParams) (sql.Result, error)
|
DeleteInvoice(ctx context.Context, arg DeleteInvoiceParams) (sql.Result, error)
|
||||||
DeleteNode(ctx context.Context, id int64) error
|
DeleteNode(ctx context.Context, id int64) error
|
||||||
DeleteNodeAddresses(ctx context.Context, nodeID int64) error
|
DeleteNodeAddresses(ctx context.Context, nodeID int64) error
|
||||||
DeleteNodeByPubKey(ctx context.Context, arg DeleteNodeByPubKeyParams) (sql.Result, error)
|
DeleteNodeByPubKey(ctx context.Context, arg DeleteNodeByPubKeyParams) (sql.Result, error)
|
||||||
DeleteNodeFeature(ctx context.Context, arg DeleteNodeFeatureParams) error
|
DeleteNodeFeature(ctx context.Context, arg DeleteNodeFeatureParams) error
|
||||||
|
DeletePayment(ctx context.Context, id int64) error
|
||||||
DeletePruneLogEntriesInRange(ctx context.Context, arg DeletePruneLogEntriesInRangeParams) error
|
DeletePruneLogEntriesInRange(ctx context.Context, arg DeletePruneLogEntriesInRangeParams) error
|
||||||
DeleteUnconnectedNodes(ctx context.Context) ([][]byte, error)
|
DeleteUnconnectedNodes(ctx context.Context) ([][]byte, error)
|
||||||
DeleteZombieChannel(ctx context.Context, arg DeleteZombieChannelParams) (sql.Result, error)
|
DeleteZombieChannel(ctx context.Context, arg DeleteZombieChannelParams) (sql.Result, error)
|
||||||
|
|||||||
@@ -151,3 +151,13 @@ FROM payment_hop_custom_records l
|
|||||||
WHERE l.hop_id IN (sqlc.slice('hop_ids')/*SLICE:hop_ids*/)
|
WHERE l.hop_id IN (sqlc.slice('hop_ids')/*SLICE:hop_ids*/)
|
||||||
ORDER BY l.hop_id ASC, l.key ASC;
|
ORDER BY l.hop_id ASC, l.key ASC;
|
||||||
|
|
||||||
|
|
||||||
|
-- name: DeletePayment :exec
|
||||||
|
DELETE FROM payments WHERE id = $1;
|
||||||
|
|
||||||
|
-- name: DeleteFailedAttempts :exec
|
||||||
|
-- Delete all failed HTLC attempts for the given payment. Resolution type 2
|
||||||
|
-- indicates a failed attempt.
|
||||||
|
DELETE FROM payment_htlc_attempts WHERE payment_id = $1 AND attempt_index IN (
|
||||||
|
SELECT attempt_index FROM payment_htlc_attempt_resolutions WHERE resolution_type = 2
|
||||||
|
);
|
||||||
Reference in new issue
Block a user