mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-07 14:00:08 +02:00
sqldb+graph/db: implement SQLStore.NodeUpdatesInHorizon
In this commit we add the necessary SQL queries and then implement the SQLStore's NodeUpdatesInHorizon method. This lets us run the TestNodeUpdatesInHorizon unit tests against SQL backends.
This commit is contained in:
@ -229,6 +229,49 @@ func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeatur
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
|
||||
SELECT id, version, pub_key, alias, last_update, color, signature
|
||||
FROM nodes
|
||||
WHERE last_update >= $1
|
||||
AND last_update < $2
|
||||
`
|
||||
|
||||
type GetNodesByLastUpdateRangeParams struct {
|
||||
StartTime sql.NullInt64
|
||||
EndTime sql.NullInt64
|
||||
}
|
||||
|
||||
func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]Node, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange, arg.StartTime, arg.EndTime)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Node
|
||||
for rows.Next() {
|
||||
var i Node
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Version,
|
||||
&i.PubKey,
|
||||
&i.Alias,
|
||||
&i.LastUpdate,
|
||||
&i.Color,
|
||||
&i.Signature,
|
||||
); 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 insertNodeAddress = `-- name: InsertNodeAddress :exec
|
||||
/* ─────────────────────────────────────────────
|
||||
node_addresses table queries
|
||||
|
@ -40,6 +40,7 @@ type Querier interface {
|
||||
GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (Node, error)
|
||||
GetNodeFeatures(ctx context.Context, nodeID int64) ([]NodeFeature, error)
|
||||
GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error)
|
||||
GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]Node, error)
|
||||
InsertAMPSubInvoice(ctx context.Context, arg InsertAMPSubInvoiceParams) error
|
||||
InsertAMPSubInvoiceHTLC(ctx context.Context, arg InsertAMPSubInvoiceHTLCParams) error
|
||||
InsertInvoice(ctx context.Context, arg InsertInvoiceParams) (int64, error)
|
||||
|
@ -82,6 +82,12 @@ LEFT JOIN node_addresses a ON a.node_id = n.id
|
||||
WHERE n.pub_key = $1 AND n.version = $2
|
||||
ORDER BY a.type ASC, a.position ASC;
|
||||
|
||||
-- name: GetNodesByLastUpdateRange :many
|
||||
SELECT *
|
||||
FROM nodes
|
||||
WHERE last_update >= @start_time
|
||||
AND last_update < @end_time;
|
||||
|
||||
-- name: DeleteNodeAddresses :exec
|
||||
DELETE FROM node_addresses
|
||||
WHERE node_id = $1;
|
||||
|
Reference in New Issue
Block a user