Skip to main content

upsert_node

Function upsert_node 

Source
pub fn upsert_node(conn: &Connection, node: &GraphNode) -> Result<()>
Expand description

Insert or update a node, preserving first-creation and access telemetry.

Uses ON CONFLICT ... DO UPDATE rather than INSERT OR REPLACE so that re-inserting a fixed-id node (e.g. an identity/stock node touched on every analysis) does not destroy created, access_count, or accessed_at. INSERT OR REPLACE is DELETE+INSERT in SQLite, which zeroes the access counters and rewrites the creation timestamp on every write — diverging from the Postgres backend (sqlx_pg.rs), which already does ON CONFLICT. This brings SQLite to parity.

  • created: first-write wins (nodes.created is kept).
  • access_count/accessed_at: the caller’s value never lowers an existing one (MAX(...)), so an import restoring a higher count is honored while a routine access_count: 0 write is a no-op on update.