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

Method insertEdges

src/db/queries.ts:2691–2724  ·  view source on GitHub ↗

* Insert multiple edges in a transaction

(edges: Edge[])

Source from the content-addressed store, hash-verified

2689 * Insert multiple edges in a transaction
2690 */
2691 insertEdges(edges: Edge[]): void {
2692 if (edges.length === 0) return;
2693
2694 this.db.transaction(() => {
2695 const endpointIds = new Set<string>();
2696 for (const edge of edges) {
2697 endpointIds.add(edge.source);
2698 endpointIds.add(edge.target);
2699 }
2700 const existingNodeIds = this.getExistingNodeIds([...endpointIds]);
2701
2702 const rows: unknown[][] = [];
2703 for (const edge of edges) {
2704 if (!existingNodeIds.has(edge.source) || !existingNodeIds.has(edge.target)) {
2705 continue;
2706 }
2707 rows.push([
2708 edge.source,
2709 edge.target,
2710 edge.kind,
2711 edge.metadata ? JSON.stringify(edge.metadata) : null,
2712 edge.line ?? null,
2713 edge.column ?? null,
2714 edge.provenance ?? null,
2715 ]);
2716 }
2717 this.runBatched(
2718 'insertEdges',
2719 'INSERT OR IGNORE INTO edges (source, target, kind, metadata, line, col, provenance) VALUES ',
2720 '(?,?,?,?,?,?,?)',
2721 rows
2722 );
2723 })();
2724 }
2725
2726 /**
2727 * Delete all edges from a source node

Calls 6

getExistingNodeIdsMethod · 0.95
runBatchedMethod · 0.95
hasMethod · 0.80
pushMethod · 0.80
transactionMethod · 0.65
addMethod · 0.45

Tested by 1