Skip to content

Commit 9c64efd

Browse files
committed
sqldb: add UpsertSelfNode query
This query is less strict in terms of the latest update timestamp field. We want to be less strict with our own node data since we always want our own updates recorded.
1 parent f79d0d3 commit 9c64efd

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

sqldb/sqlc/graph.sql.go

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sqldb/sqlc/querier.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sqldb/sqlc/queries/graph.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,25 @@ WHERE graph_nodes.last_update IS NULL
2121
OR EXCLUDED.last_update > graph_nodes.last_update
2222
RETURNING id;
2323

24+
-- We use a separate upsert for our own node since we want to be less strict
25+
-- about the last_update field. For our own node, we always want to
26+
-- update the record even if the last_update is older than what we have.
27+
-- name: UpsertSourceNode :one
28+
INSERT INTO graph_nodes (
29+
version, pub_key, alias, last_update, color, signature
30+
) VALUES (
31+
$1, $2, $3, $4, $5, $6
32+
)
33+
ON CONFLICT (pub_key, version)
34+
-- Update the following fields if a conflict occurs on pub_key
35+
-- and version.
36+
DO UPDATE SET
37+
alias = EXCLUDED.alias,
38+
last_update = EXCLUDED.last_update,
39+
color = EXCLUDED.color,
40+
signature = EXCLUDED.signature
41+
RETURNING id;
42+
2443
-- name: GetNodesByIDs :many
2544
SELECT *
2645
FROM graph_nodes

0 commit comments

Comments
 (0)