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

Method insertEdges

src/db/queries.ts:1668–1701  ·  view source on GitHub ↗

* Insert multiple edges in a transaction

(edges: Edge[])

Source from the content-addressed store, hash-verified

1666 * Insert multiple edges in a transaction
1667 */
1668 insertEdges(edges: Edge[]): void {
1669 if (edges.length === 0) return;
1670
1671 this.db.transaction(() => {
1672 const endpointIds = new Set<string>();
1673 for (const edge of edges) {
1674 endpointIds.add(edge.source);
1675 endpointIds.add(edge.target);
1676 }
1677 const existingNodeIds = this.getExistingNodeIds([...endpointIds]);
1678
1679 const rows: unknown[][] = [];
1680 for (const edge of edges) {
1681 if (!existingNodeIds.has(edge.source) || !existingNodeIds.has(edge.target)) {
1682 continue;
1683 }
1684 rows.push([
1685 edge.source,
1686 edge.target,
1687 edge.kind,
1688 edge.metadata ? JSON.stringify(edge.metadata) : null,
1689 edge.line ?? null,
1690 edge.column ?? null,
1691 edge.provenance ?? null,
1692 ]);
1693 }
1694 this.runBatched(
1695 'insertEdges',
1696 'INSERT OR IGNORE INTO edges (source, target, kind, metadata, line, col, provenance) VALUES ',
1697 '(?,?,?,?,?,?,?)',
1698 rows
1699 );
1700 })();
1701 }
1702
1703 /**
1704 * Delete all edges from a source node

Calls 4

getExistingNodeIdsMethod · 0.95
runBatchedMethod · 0.95
hasMethod · 0.80
transactionMethod · 0.65

Tested by

no test coverage detected