What changed, and why it matters
This commit adds a new database query helper called NodeExists. It simply checks whether a node with a given public key and version already exists in the database. There is no change to user-facing behavior, no bug fix, and no security-related content visible in the diff.
No security action required. Review the consuming code that will call NodeExists when it is introduced, to ensure the result is used safely.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch introduces a SQLC-generated NodeExists query in sqldb/sqlc/graph.sql.go, registers it in the Querier interface, and adds the underlying SQL in sqldb/sqlc/queries/graph.sql. The query uses a parameterized EXISTS clause against graph_nodes filtered by pub_key and version. It is read-only and does not modify any existing logic.
Changed components
sqldb/sqlc/graph.sql.gosqldb/sqlc/querier.gosqldb/sqlc/queries/graph.sqlInspect captured patch +30 / −0
diff --git a/sqldb/sqlc/graph.sql.go b/sqldb/sqlc/graph.sql.go
index cdf15a9..2c26eb5 100644
--- a/sqldb/sqlc/graph.sql.go
+++ b/sqldb/sqlc/graph.sql.go
@@ -3537,6 +3537,27 @@ func (q *Queries) ListNodesPaginated(ctx context.Context, arg ListNodesPaginated
return items, nil
}
+const nodeExists = `-- name: NodeExists :one
+SELECT EXISTS (
+ SELECT 1
+ FROM graph_nodes
+ WHERE pub_key = $1
+ AND version = $2
+) AS node_exists
+`
+
+type NodeExistsParams struct {
+ PubKey []byte
+ Version int16
+}
+
+func (q *Queries) NodeExists(ctx context.Context, arg NodeExistsParams) (bool, error) {
+ row := q.db.QueryRowContext(ctx, nodeExists, arg.PubKey, arg.Version)
+ var node_exists bool
+ err := row.Scan(&node_exists)
+ return node_exists, err
+}
+
const upsertChanPolicyExtraType = `-- name: UpsertChanPolicyExtraType :exec
/* ─────────────────────────────────────────────
graph_channel_policy_extra_types table queries
diff --git a/sqldb/sqlc/querier.go b/sqldb/sqlc/querier.go
index 7b7b064..aa8ab2e 100644
--- a/sqldb/sqlc/querier.go
+++ b/sqldb/sqlc/querier.go
@@ -125,6 +125,7 @@ type Querier interface {
ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndPubKeysParams) ([]ListNodeIDsAndPubKeysRow, error)
ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]GraphNode, error)
NextInvoiceSettleIndex(ctx context.Context) (int64, error)
+ NodeExists(ctx context.Context, arg NodeExistsParams) (bool, error)
OnAMPSubInvoiceCanceled(ctx context.Context, arg OnAMPSubInvoiceCanceledParams) error
OnAMPSubInvoiceCreated(ctx context.Context, arg OnAMPSubInvoiceCreatedParams) error
OnAMPSubInvoiceSettled(ctx context.Context, arg OnAMPSubInvoiceSettledParams) error
diff --git a/sqldb/sqlc/queries/graph.sql b/sqldb/sqlc/queries/graph.sql
index 4804376..2df865d 100644
--- a/sqldb/sqlc/queries/graph.sql
+++ b/sqldb/sqlc/queries/graph.sql
@@ -59,6 +59,14 @@ FROM graph_nodes
WHERE pub_key = $1
AND version = $2;
+-- name: NodeExists :one
+SELECT EXISTS (
+ SELECT 1
+ FROM graph_nodes
+ WHERE pub_key = $1
+ AND version = $2
+) AS node_exists;
+
-- name: GetNodeIDByPubKey :one
SELECT id
FROM graph_nodes
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.