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

Method insertNode

src/db/queries.ts:718–791  ·  view source on GitHub ↗

* Insert a new node

(node: Node)

Source from the content-addressed store, hash-verified

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