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

Method insertEdges

src/db/queries.ts:2973–3006  ·  view source on GitHub ↗

* Insert multiple edges in a transaction

(edges: Edge[])

Source from the content-addressed store, hash-verified

2971 * Insert multiple edges in a transaction
2972 */
2973 insertEdges(edges: Edge[]): void {
2974 if (edges.length === 0) return;
2975
2976 this.db.transaction(() => {
2977 const endpointIds = new Set<string>();
2978 for (const edge of edges) {
2979 endpointIds.add(edge.source);
2980 endpointIds.add(edge.target);
2981 }
2982 const existingNodeIds = this.getExistingNodeIds([...endpointIds]);
2983
2984 const rows: unknown[][] = [];
2985 for (const edge of edges) {
2986 if (!existingNodeIds.has(edge.source) || !existingNodeIds.has(edge.target)) {
2987 continue;
2988 }
2989 rows.push([
2990 edge.source,
2991 edge.target,
2992 edge.kind,
2993 edge.metadata ? JSON.stringify(edge.metadata) : null,
2994 edge.line ?? null,
2995 edge.column ?? null,
2996 edge.provenance ?? null,
2997 ]);
2998 }
2999 this.runBatched(
3000 'insertEdges',
3001 'INSERT OR IGNORE INTO edges (source, target, kind, metadata, line, col, provenance) VALUES ',
3002 '(?,?,?,?,?,?,?)',
3003 rows
3004 );
3005 })();
3006 }
3007
3008 /**
3009 * 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