MCPcopy
hub / github.com/colbymchenry/codegraph / insertNode

Method insertNode

src/db/queries.ts:246–306  ·  view source on GitHub ↗

* Insert a new node

(node: Node)

Source from the content-addressed store, hash-verified

244 * Insert a new node
245 */
246 insertNode(node: Node): void {
247 if (!this.stmts.insertNode) {
248 this.stmts.insertNode = this.db.prepare(`
249 INSERT OR REPLACE INTO nodes (
250 id, kind, name, qualified_name, file_path, language,
251 start_line, end_line, start_column, end_column,
252 docstring, signature, visibility,
253 is_exported, is_async, is_static, is_abstract,
254 decorators, type_parameters, return_type, updated_at
255 ) VALUES (
256 @id, @kind, @name, @qualifiedName, @filePath, @language,
257 @startLine, @endLine, @startColumn, @endColumn,
258 @docstring, @signature, @visibility,
259 @isExported, @isAsync, @isStatic, @isAbstract,
260 @decorators, @typeParameters, @returnType, @updatedAt
261 )
262 `);
263 }
264
265 // Validate required fields to prevent SQLite bind errors
266 if (!node.id || !node.kind || !node.name || !node.filePath || !node.language) {
267 console.error('[CodeGraph] Skipping node with missing required fields:', {
268 id: node.id,
269 kind: node.kind,
270 name: node.name,
271 filePath: node.filePath,
272 language: node.language,
273 });
274 return;
275 }
276
277 // INSERT OR REPLACE may overwrite a node we have cached. Drop the
278 // stale entry so the next getNodeById sees the new row, not the old
279 // one (matches the cache-invalidation pattern used by updateNode and
280 // deleteNode below).
281 this.nodeCache.delete(node.id);
282
283 this.stmts.insertNode.run({
284 id: node.id,
285 kind: node.kind,
286 name: node.name,
287 qualifiedName: node.qualifiedName ?? node.name,
288 filePath: node.filePath,
289 language: node.language,
290 startLine: node.startLine ?? 0,
291 endLine: node.endLine ?? 0,
292 startColumn: node.startColumn ?? 0,
293 endColumn: node.endColumn ?? 0,
294 docstring: node.docstring ?? null,
295 signature: node.signature ?? null,
296 visibility: node.visibility ?? null,
297 isExported: node.isExported ? 1 : 0,
298 isAsync: node.isAsync ? 1 : 0,
299 isStatic: node.isStatic ? 1 : 0,
300 isAbstract: node.isAbstract ? 1 : 0,
301 decorators: node.decorators ? JSON.stringify(node.decorators) : null,
302 typeParameters: node.typeParameters ? JSON.stringify(node.typeParameters) : null,
303 returnType: node.returnType ?? null,

Callers 3

insertNodesMethod · 0.95
db-perf.test.tsFile · 0.80

Calls 3

errorMethod · 0.80
prepareMethod · 0.65
runMethod · 0.65

Tested by

no test coverage detected