* Insert a new node
(node: Node)
| 328 | * Insert a new node |
| 329 | */ |
| 330 | insertNode(node: Node): void { |
| 331 | if (!this.stmts.insertNode) { |
| 332 | this.stmts.insertNode = this.db.prepare(` |
| 333 | INSERT OR REPLACE INTO nodes ( |
| 334 | id, kind, name, qualified_name, file_path, language, |
| 335 | start_line, end_line, start_column, end_column, |
| 336 | docstring, signature, visibility, |
| 337 | is_exported, is_async, is_static, is_abstract, |
| 338 | decorators, type_parameters, return_type, updated_at |
| 339 | ) VALUES ( |
| 340 | @id, @kind, @name, @qualifiedName, @filePath, @language, |
| 341 | @startLine, @endLine, @startColumn, @endColumn, |
| 342 | @docstring, @signature, @visibility, |
| 343 | @isExported, @isAsync, @isStatic, @isAbstract, |
| 344 | @decorators, @typeParameters, @returnType, @updatedAt |
| 345 | ) |
| 346 | `); |
| 347 | } |
| 348 | |
| 349 | // Validate required fields to prevent SQLite bind errors |
| 350 | if (!node.id || !node.kind || !node.name || !node.filePath || !node.language) { |
| 351 | console.error('[CodeGraph] Skipping node with missing required fields:', { |
| 352 | id: node.id, |
| 353 | kind: node.kind, |
| 354 | name: node.name, |
| 355 | filePath: node.filePath, |
| 356 | language: node.language, |
| 357 | }); |
| 358 | return; |
| 359 | } |
| 360 | |
| 361 | // INSERT OR REPLACE may overwrite a node we have cached. Drop the |
| 362 | // stale entry so the next getNodeById sees the new row, not the old |
| 363 | // one (matches the cache-invalidation pattern used by updateNode and |
| 364 | // deleteNode below). |
| 365 | this.nodeCache.delete(node.id); |
| 366 | |
| 367 | this.stmts.insertNode.run({ |
| 368 | id: node.id, |
| 369 | kind: node.kind, |
| 370 | name: node.name, |
| 371 | qualifiedName: node.qualifiedName ?? node.name, |
| 372 | filePath: node.filePath, |
| 373 | language: node.language, |
| 374 | startLine: node.startLine ?? 0, |
| 375 | endLine: node.endLine ?? 0, |
| 376 | startColumn: node.startColumn ?? 0, |
| 377 | endColumn: node.endColumn ?? 0, |
| 378 | docstring: node.docstring ?? null, |
| 379 | signature: node.signature ?? null, |
| 380 | visibility: node.visibility ?? null, |
| 381 | isExported: node.isExported ? 1 : 0, |
| 382 | isAsync: node.isAsync ? 1 : 0, |
| 383 | isStatic: node.isStatic ? 1 : 0, |
| 384 | isAbstract: node.isAbstract ? 1 : 0, |
| 385 | decorators: node.decorators ? JSON.stringify(node.decorators) : null, |
| 386 | typeParameters: node.typeParameters ? JSON.stringify(node.typeParameters) : null, |
| 387 | returnType: node.returnType ?? null, |
no test coverage detected