MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_store_upsert_node

Function cbm_store_upsert_node

src/store/store.c:2565–2596  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2563/* ── Node CRUD ──────────────────────────────────────────────────── */
2564
2565int64_t cbm_store_upsert_node(cbm_store_t *s, const cbm_node_t *n) {
2566 sqlite3_stmt *stmt =
2567 prepare_cached(s, &s->stmt_upsert_node,
2568 "INSERT INTO nodes (project, label, name, qualified_name, file_path, "
2569 "start_line, end_line, properties) "
2570 "VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8) "
2571 "ON CONFLICT(project, qualified_name) DO UPDATE SET "
2572 "label=?2, name=?3, file_path=?5, start_line=?6, end_line=?7, properties=?8 "
2573 "RETURNING id;");
2574 if (!stmt) {
2575 return CBM_STORE_ERR;
2576 }
2577
2578 bind_text(stmt, SKIP_ONE, safe_str(n->project));
2579 bind_text(stmt, ST_COL_2, safe_str(n->label));
2580 bind_text(stmt, ST_COL_3, safe_str(n->name));
2581 bind_text(stmt, ST_COL_4, safe_str(n->qualified_name));
2582 bind_text(stmt, ST_COL_5, safe_str(n->file_path));
2583 sqlite3_bind_int(stmt, ST_COL_6, n->start_line);
2584 sqlite3_bind_int(stmt, ST_COL_7, n->end_line);
2585 bind_text(stmt, ST_COL_8, safe_props(n->properties_json));
2586
2587 int rc = sqlite3_step(stmt);
2588 if (rc == SQLITE_ROW) {
2589 int64_t id = sqlite3_column_int64(stmt, 0);
2590 sqlite3_reset(stmt); /* unblock COMMIT — RETURNING leaves stmt active */
2591 return id;
2592 }
2593 sqlite3_reset(stmt);
2594 store_set_error_sqlite(s, "upsert_node");
2595 return CBM_STORE_ERR;
2596}
2597
2598/* Scan a node from current row of stmt. Heap-allocates strings. */
2599static void scan_node(sqlite3_stmt *stmt, cbm_node_t *n) {

Callers 15

cov_rebuild_shadow_graphFunction · 0.85
cbm_gbuf_flush_to_storeFunction · 0.85
setup_cypher_storeFunction · 0.85
test_cypher.cFile · 0.85
setup_cypher_http_storeFunction · 0.85
test_cli.cFile · 0.85
make_legacy_file_graphFunction · 0.85

Calls 5

prepare_cachedFunction · 0.85
bind_textFunction · 0.85
safe_propsFunction · 0.85
store_set_error_sqliteFunction · 0.85
safe_strFunction · 0.70

Tested by 15

setup_cypher_storeFunction · 0.68
setup_cypher_http_storeFunction · 0.68
make_legacy_file_graphFunction · 0.68
setup_prefilter_serverFunction · 0.68
setup_snippet_serverFunction · 0.68
issue704_make_dbFunction · 0.68