MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / insertNode

Method insertNode

src/db/queries.ts:374–447  ·  view source on GitHub ↗

* Insert a new node

(node: Node)

Source from the content-addressed store, hash-verified

372 * Insert a new node
373 */
374 insertNode(node: Node): void {
375 if (!this.stmts.insertNode) {
376 this.stmts.insertNode = this.db.prepare(`
377 INSERT OR REPLACE INTO nodes (
378 id, kind, name, qualified_name, file_path, language,
379 start_line, end_line, start_column, end_column,
380 docstring, signature, visibility,
381 is_exported, is_async, is_static, is_abstract,
382 decorators, type_parameters, return_type, updated_at
383 ) VALUES (
384 @id, @kind, @name, @qualifiedName, @filePath, @language,
385 @startLine, @endLine, @startColumn, @endColumn,
386 @docstring, @signature, @visibility,
387 @isExported, @isAsync, @isStatic, @isAbstract,
388 @decorators, @typeParameters, @returnType, @updatedAt
389 )
390 `);
391 }
392
393 // Validate required fields to prevent SQLite bind errors
394 if (!node.id || !node.kind || !node.name || !node.filePath || !node.language) {
395 console.error('[CodeGraph] Skipping node with missing required fields:', {
396 id: node.id,
397 kind: node.kind,
398 name: node.name,
399 filePath: node.filePath,
400 language: node.language,
401 });
402 return;
403 }
404
405 // INSERT OR REPLACE may overwrite a node we have cached. Drop the
406 // stale entry so the next getNodeById sees the new row, not the old
407 // one (matches the cache-invalidation pattern used by updateNode and
408 // deleteNode below).
409 this.nodeCache.delete(node.id);
410
411 this.stmts.insertNode.run({
412 id: node.id,
413 kind: node.kind,
414 name: node.name,
415 qualifiedName: node.qualifiedName ?? node.name,
416 filePath: node.filePath,
417 language: node.language,
418 startLine: node.startLine ?? 0,
419 endLine: node.endLine ?? 0,
420 startColumn: node.startColumn ?? 0,
421 endColumn: node.endColumn ?? 0,
422 docstring: node.docstring ?? null,
423 signature: node.signature ?? null,
424 visibility: node.visibility ?? null,
425 isExported: node.isExported ? 1 : 0,
426 isAsync: node.isAsync ? 1 : 0,
427 isStatic: node.isStatic ? 1 : 0,
428 isAbstract: node.isAbstract ? 1 : 0,
429 decorators: node.decorators ? JSON.stringify(node.decorators) : null,
430 typeParameters: node.typeParameters ? JSON.stringify(node.typeParameters) : null,
431 returnType: node.returnType ?? null,

Calls 6

isSegmentableKindMethod · 0.95
insertNameSegmentsMethod · 0.95
errorMethod · 0.80
prepareMethod · 0.65
deleteMethod · 0.65
runMethod · 0.65

Tested by

no test coverage detected