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

Method insertEdges

src/db/queries.ts:2707–2740  ·  view source on GitHub ↗

* Insert multiple edges in a transaction

(edges: Edge[])

Source from the content-addressed store, hash-verified

2705 * Insert multiple edges in a transaction
2706 */
2707 insertEdges(edges: Edge[]): void {
2708 if (edges.length === 0) return;
2709
2710 this.db.transaction(() => {
2711 const endpointIds = new Set<string>();
2712 for (const edge of edges) {
2713 endpointIds.add(edge.source);
2714 endpointIds.add(edge.target);
2715 }
2716 const existingNodeIds = this.getExistingNodeIds([...endpointIds]);
2717
2718 const rows: unknown[][] = [];
2719 for (const edge of edges) {
2720 if (!existingNodeIds.has(edge.source) || !existingNodeIds.has(edge.target)) {
2721 continue;
2722 }
2723 rows.push([
2724 edge.source,
2725 edge.target,
2726 edge.kind,
2727 edge.metadata ? JSON.stringify(edge.metadata) : null,
2728 edge.line ?? null,
2729 edge.column ?? null,
2730 edge.provenance ?? null,
2731 ]);
2732 }
2733 this.runBatched(
2734 'insertEdges',
2735 'INSERT OR IGNORE INTO edges (source, target, kind, metadata, line, col, provenance) VALUES ',
2736 '(?,?,?,?,?,?,?)',
2737 rows
2738 );
2739 })();
2740 }
2741
2742 /**
2743 * 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