* Insert a new node
(node: Node)
| 766 | * Insert a new node |
| 767 | */ |
| 768 | insertNode(node: Node): void { |
| 769 | if (!this.stmts.insertNode) { |
| 770 | this.stmts.insertNode = this.db.prepare(` |
| 771 | INSERT OR REPLACE INTO nodes ( |
| 772 | id, kind, name, qualified_name, file_path, language, |
| 773 | start_line, end_line, start_column, end_column, |
| 774 | docstring, signature, visibility, |
| 775 | is_exported, is_async, is_static, is_abstract, |
| 776 | decorators, type_parameters, return_type, updated_at |
| 777 | ) VALUES ( |
| 778 | @id, @kind, @name, @qualifiedName, @filePath, @language, |
| 779 | @startLine, @endLine, @startColumn, @endColumn, |
| 780 | @docstring, @signature, @visibility, |
| 781 | @isExported, @isAsync, @isStatic, @isAbstract, |
| 782 | @decorators, @typeParameters, @returnType, @updatedAt |
| 783 | ) |
| 784 | `); |
| 785 | } |
| 786 | |
| 787 | // Validate required fields to prevent SQLite bind errors |
| 788 | if (!node.id || !node.kind || !node.name || !node.filePath || !node.language) { |
| 789 | console.error('[CodeGraph] Skipping node with missing required fields:', { |
| 790 | id: node.id, |
| 791 | kind: node.kind, |
| 792 | name: node.name, |
| 793 | filePath: node.filePath, |
| 794 | language: node.language, |
| 795 | }); |
| 796 | return; |
| 797 | } |
| 798 | |
| 799 | // INSERT OR REPLACE may overwrite a node we have cached. Drop the |
| 800 | // stale entry so the next getNodeById sees the new row, not the old |
| 801 | // one (matches the cache-invalidation pattern used by updateNode and |
| 802 | // deleteNode below). |
| 803 | this.nodeCache.delete(node.id); |
| 804 | |
| 805 | this.stmts.insertNode.run({ |
| 806 | id: node.id, |
| 807 | kind: node.kind, |
| 808 | name: node.name, |
| 809 | qualifiedName: node.qualifiedName ?? node.name, |
| 810 | filePath: node.filePath, |
| 811 | language: node.language, |
| 812 | startLine: node.startLine ?? 0, |
| 813 | endLine: node.endLine ?? 0, |
| 814 | startColumn: node.startColumn ?? 0, |
| 815 | endColumn: node.endColumn ?? 0, |
| 816 | docstring: node.docstring ?? null, |
| 817 | signature: node.signature ?? null, |
| 818 | visibility: node.visibility ?? null, |
| 819 | isExported: node.isExported ? 1 : 0, |
| 820 | isAsync: node.isAsync ? 1 : 0, |
| 821 | isStatic: node.isStatic ? 1 : 0, |
| 822 | isAbstract: node.isAbstract ? 1 : 0, |
| 823 | decorators: node.decorators ? JSON.stringify(node.decorators) : null, |
| 824 | typeParameters: node.typeParameters ? JSON.stringify(node.typeParameters) : null, |
| 825 | returnType: node.returnType ?? null, |