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

Method insertNode

src/db/queries.ts:716–789  ·  view source on GitHub ↗

* Insert a new node

(node: Node)

Source from the content-addressed store, hash-verified

714 * Insert a new node
715 */
716 insertNode(node: Node): void {
717 if (!this.stmts.insertNode) {
718 this.stmts.insertNode = this.db.prepare(`
719 INSERT OR REPLACE INTO nodes (
720 id, kind, name, qualified_name, file_path, language,
721 start_line, end_line, start_column, end_column,
722 docstring, signature, visibility,
723 is_exported, is_async, is_static, is_abstract,
724 decorators, type_parameters, return_type, updated_at
725 ) VALUES (
726 @id, @kind, @name, @qualifiedName, @filePath, @language,
727 @startLine, @endLine, @startColumn, @endColumn,
728 @docstring, @signature, @visibility,
729 @isExported, @isAsync, @isStatic, @isAbstract,
730 @decorators, @typeParameters, @returnType, @updatedAt
731 )
732 `);
733 }
734
735 // Validate required fields to prevent SQLite bind errors
736 if (!node.id || !node.kind || !node.name || !node.filePath || !node.language) {
737 console.error('[CodeGraph] Skipping node with missing required fields:', {
738 id: node.id,
739 kind: node.kind,
740 name: node.name,
741 filePath: node.filePath,
742 language: node.language,
743 });
744 return;
745 }
746
747 // INSERT OR REPLACE may overwrite a node we have cached. Drop the
748 // stale entry so the next getNodeById sees the new row, not the old
749 // one (matches the cache-invalidation pattern used by updateNode and
750 // deleteNode below).
751 this.nodeCache.delete(node.id);
752
753 this.stmts.insertNode.run({
754 id: node.id,
755 kind: node.kind,
756 name: node.name,
757 qualifiedName: node.qualifiedName ?? node.name,
758 filePath: node.filePath,
759 language: node.language,
760 startLine: node.startLine ?? 0,
761 endLine: node.endLine ?? 0,
762 startColumn: node.startColumn ?? 0,
763 endColumn: node.endColumn ?? 0,
764 docstring: node.docstring ?? null,
765 signature: node.signature ?? null,
766 visibility: node.visibility ?? null,
767 isExported: node.isExported ? 1 : 0,
768 isAsync: node.isAsync ? 1 : 0,
769 isStatic: node.isStatic ? 1 : 0,
770 isAbstract: node.isAbstract ? 1 : 0,
771 decorators: node.decorators ? JSON.stringify(node.decorators) : null,
772 typeParameters: node.typeParameters ? JSON.stringify(node.typeParameters) : null,
773 returnType: node.returnType ?? null,

Callers 15

fixtureFunction · 0.95
fixtureFunction · 0.95
fixtureFunction · 0.95
fixtureFunction · 0.95
fixtureFunction · 0.95
fixtureFunction · 0.95
db-perf.test.tsFile · 0.80
failedFunction · 0.80
node-rows.test.tsFile · 0.80

Calls 6

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

Tested by 8

fixtureFunction · 0.76
fixtureFunction · 0.76
fixtureFunction · 0.76
fixtureFunction · 0.76
fixtureFunction · 0.76
fixtureFunction · 0.76
failedFunction · 0.64
seedFunction · 0.64