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

Method insertEdges

src/db/queries.ts:1774–1807  ·  view source on GitHub ↗

* Insert multiple edges in a transaction

(edges: Edge[])

Source from the content-addressed store, hash-verified

1772 * Insert multiple edges in a transaction
1773 */
1774 insertEdges(edges: Edge[]): void {
1775 if (edges.length === 0) return;
1776
1777 this.db.transaction(() => {
1778 const endpointIds = new Set<string>();
1779 for (const edge of edges) {
1780 endpointIds.add(edge.source);
1781 endpointIds.add(edge.target);
1782 }
1783 const existingNodeIds = this.getExistingNodeIds([...endpointIds]);
1784
1785 const rows: unknown[][] = [];
1786 for (const edge of edges) {
1787 if (!existingNodeIds.has(edge.source) || !existingNodeIds.has(edge.target)) {
1788 continue;
1789 }
1790 rows.push([
1791 edge.source,
1792 edge.target,
1793 edge.kind,
1794 edge.metadata ? JSON.stringify(edge.metadata) : null,
1795 edge.line ?? null,
1796 edge.column ?? null,
1797 edge.provenance ?? null,
1798 ]);
1799 }
1800 this.runBatched(
1801 'insertEdges',
1802 'INSERT OR IGNORE INTO edges (source, target, kind, metadata, line, col, provenance) VALUES ',
1803 '(?,?,?,?,?,?,?)',
1804 rows
1805 );
1806 })();
1807 }
1808
1809 /**
1810 * 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