mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-15 02:55:37 +02:00
sqldb+graph/db: source nodes table, queries and CRUD
In this commit, we add the `source_nodes` table. It points to entries in the `nodes` table. This table will store one entry per protocol version that we are announcing a node_announcement on. With this commit, we can run the TestSourceNode unit test against our SQL backends.
This commit is contained in:
@@ -10,6 +10,22 @@ import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
const addSourceNode = `-- name: AddSourceNode :exec
|
||||
/* ─────────────────────────────────────────────
|
||||
source_nodes table queries
|
||||
─────────────────────────────────────────────
|
||||
*/
|
||||
|
||||
INSERT INTO source_nodes (node_id)
|
||||
VALUES ($1)
|
||||
ON CONFLICT (node_id) DO NOTHING
|
||||
`
|
||||
|
||||
func (q *Queries) AddSourceNode(ctx context.Context, nodeID int64) error {
|
||||
_, err := q.db.ExecContext(ctx, addSourceNode, nodeID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteExtraNodeType = `-- name: DeleteExtraNodeType :exec
|
||||
DELETE FROM node_extra_types
|
||||
WHERE node_id = $1
|
||||
@@ -272,6 +288,41 @@ func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByL
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
|
||||
SELECT sn.node_id, n.pub_key
|
||||
FROM source_nodes sn
|
||||
JOIN nodes n ON sn.node_id = n.id
|
||||
WHERE n.version = $1
|
||||
`
|
||||
|
||||
type GetSourceNodesByVersionRow struct {
|
||||
NodeID int64
|
||||
PubKey []byte
|
||||
}
|
||||
|
||||
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetSourceNodesByVersionRow
|
||||
for rows.Next() {
|
||||
var i GetSourceNodesByVersionRow
|
||||
if err := rows.Scan(&i.NodeID, &i.PubKey); 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
|
||||
|
Reference in New Issue
Block a user