MCPcopy
hub / github.com/tirth8205/code-review-graph / upsert_node

Method upsert_node

code_review_graph/graph.py:189–221  ·  view source on GitHub ↗

Insert or update a node. Returns the node ID.

(self, node: NodeInfo, file_hash: str = "")

Source from the content-addressed store, hash-verified

187 # --- Write operations ---
188
189 def upsert_node(self, node: NodeInfo, file_hash: str = "") -> int:
190 """Insert or update a node. Returns the node ID."""
191 now = time.time()
192 qualified = self._make_qualified(node)
193 extra = json.dumps(node.extra) if node.extra else "{}"
194
195 self._conn.execute(
196 """INSERT INTO nodes
197 (kind, name, qualified_name, file_path, line_start, line_end,
198 language, parent_name, params, return_type, modifiers, is_test,
199 file_hash, extra, updated_at)
200 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
201 ON CONFLICT(qualified_name) DO UPDATE SET
202 kind=excluded.kind, name=excluded.name,
203 file_path=excluded.file_path, line_start=excluded.line_start,
204 line_end=excluded.line_end, language=excluded.language,
205 parent_name=excluded.parent_name, params=excluded.params,
206 return_type=excluded.return_type, modifiers=excluded.modifiers,
207 is_test=excluded.is_test, file_hash=excluded.file_hash,
208 extra=excluded.extra, updated_at=excluded.updated_at
209 """,
210 (
211 node.kind, node.name, qualified, node.file_path,
212 node.line_start, node.line_end, node.language,
213 node.parent_name, node.params, node.return_type,
214 node.modifiers, int(node.is_test), file_hash,
215 extra, now,
216 ),
217 )
218 row = self._conn.execute(
219 "SELECT id FROM nodes WHERE qualified_name = ?", (qualified,)
220 ).fetchone()
221 return row["id"]
222
223 def upsert_edge(self, edge: EdgeInfo) -> int:
224 """Insert or update an edge."""

Callers 15

_make_chain_storeMethod · 0.95
test_hook_json_formatMethod · 0.95
store_with_dataFunction · 0.95
large_storeFunction · 0.95
store_file_batchMethod · 0.95
_seed_realistic_graphMethod · 0.80
_seed_dataMethod · 0.80

Calls 1

_make_qualifiedMethod · 0.95

Tested by 15

_make_chain_storeMethod · 0.76
test_hook_json_formatMethod · 0.76
store_with_dataFunction · 0.76
large_storeFunction · 0.76
_seed_realistic_graphMethod · 0.64
_seed_dataMethod · 0.64
setup_methodMethod · 0.64