* Insert a new node
(node: Node)
| 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, |