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

Method insertNodes

src/db/queries.ts:427–490  ·  view source on GitHub ↗

* Insert multiple nodes in a transaction

(nodes: Node[])

Source from the content-addressed store, hash-verified

425 * Insert multiple nodes in a transaction
426 */
427 insertNodes(nodes: Node[]): void {
428 this.db.transaction(() => {
429 // Bulk path: same semantics as insertNode() per row (validation, cache
430 // invalidation, segment vocab), but bound as multi-row INSERTs — the
431 // per-.run() call overhead dominates the store phase on full indexes.
432 const rows: unknown[][] = [];
433 const segmentRows: unknown[][] = [];
434 for (const node of nodes) {
435 if (!node.id || !node.kind || !node.name || !node.filePath || !node.language) {
436 console.error('[CodeGraph] Skipping node with missing required fields:', {
437 id: node.id,
438 kind: node.kind,
439 name: node.name,
440 filePath: node.filePath,
441 language: node.language,
442 });
443 continue;
444 }
445 this.nodeCache.delete(node.id);
446 rows.push([
447 node.id,
448 node.kind,
449 node.name,
450 node.qualifiedName ?? node.name,
451 node.filePath,
452 node.language,
453 node.startLine ?? 0,
454 node.endLine ?? 0,
455 node.startColumn ?? 0,
456 node.endColumn ?? 0,
457 node.docstring ?? null,
458 node.signature ?? null,
459 node.visibility ?? null,
460 node.isExported ? 1 : 0,
461 node.isAsync ? 1 : 0,
462 node.isStatic ? 1 : 0,
463 node.isAbstract ? 1 : 0,
464 node.decorators ? JSON.stringify(node.decorators) : null,
465 node.typeParameters ? JSON.stringify(node.typeParameters) : null,
466 node.returnType ?? null,
467 node.updatedAt ?? Date.now(),
468 ]);
469 if (this.isSegmentableKind(node.kind)) this.collectNameSegmentRows(node.name, segmentRows);
470 }
471 this.runBatched(
472 'insertNodes',
473 `INSERT OR REPLACE INTO nodes (
474 id, kind, name, qualified_name, file_path, language,
475 start_line, end_line, start_column, end_column,
476 docstring, signature, visibility,
477 is_exported, is_async, is_static, is_abstract,
478 decorators, type_parameters, return_type, updated_at
479 ) VALUES `,
480 '(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
481 rows
482 );
483 this.runBatched(
484 'insertNameSegments',

Callers 3

storeFileBundleMethod · 0.95
storeExtractionResultMethod · 0.80
db-perf.test.tsFile · 0.80

Calls 5

isSegmentableKindMethod · 0.95
runBatchedMethod · 0.95
errorMethod · 0.80
transactionMethod · 0.65

Tested by

no test coverage detected