MCPcopy
hub / github.com/opentrace/opentrace / importDatabase

Method importDatabase

ui/src/store/ladybugStore.ts:1714–1979  ·  view source on GitHub ↗
(
    data: Uint8Array,
    onProgress?: (msg: string) => void,
  )

Source from the content-addressed store, hash-verified

1712 }
1713
1714 async importDatabase(
1715 data: Uint8Array,
1716 onProgress?: (msg: string) => void,
1717 ): Promise<ImportBatchResponse> {
1718 await this.ensureReady();
1719
1720 // Unzip the Parquet archive and COPY FROM each file into the in-memory DB.
1721 onProgress?.('Unpacking Parquet archive');
1722 let entries: Record<string, Uint8Array>;
1723 try {
1724 entries = unzipSync(data);
1725 } catch (err) {
1726 throw new Error(
1727 `Failed to unzip archive. Make sure the file is a .parquet.zip exported from OpenTrace. (${err})`,
1728 );
1729 }
1730
1731 const fileNames = Object.keys(entries);
1732 console.log(
1733 `[LadybugStore] importDatabase: archive contains ${fileNames.length} files:`,
1734 fileNames,
1735 );
1736
1737 if (fileNames.length === 0) {
1738 throw new Error(
1739 'Archive contains no files. Make sure you are importing a .parquet.zip exported from OpenTrace.',
1740 );
1741 }
1742
1743 // Clear current data and reset caches (also drains pending buffered writes)
1744 await this.clearGraph();
1745
1746 let totalNodes = 0;
1747 let totalRels = 0;
1748
1749 // Import node tables from Parquet files → CSV → COPY FROM
1750 // Also check for legacy node types (Package → Dependency)
1751 const LEGACY_TYPE_MAP: Record<string, NodeType> = {
1752 Package: 'Dependency',
1753 };
1754
1755 for (const type of NODE_TYPES) {
1756 // Check for both current and legacy file names
1757 const fileName = `nodes_${type}.parquet`;
1758 let fileData = entries[fileName];
1759
1760 // Check for legacy type name
1761 const legacyName = Object.entries(LEGACY_TYPE_MAP).find(
1762 ([, v]) => v === type,
1763 )?.[0];
1764 if (!fileData && legacyName) {
1765 fileData = entries[`nodes_${legacyName}.parquet`];
1766 }
1767 if (!fileData) continue;
1768
1769 onProgress?.(`Importing ${type} nodes`);
1770 const arrowTable = await parquetToArrow(fileData);
1771 const columns = NODE_COLUMN_NAMES[type] as string[];

Callers

nothing calls this directly

Calls 15

ensureReadyMethod · 0.95
clearGraphMethod · 0.95
tmpCsvPathMethod · 0.95
execMethod · 0.95
queryMethod · 0.95
cacheNodeMethod · 0.95
rebuildSourceFTSMethod · 0.95
parquetToArrowFunction · 0.85
safeJsonParseFunction · 0.85
generateTypedNodeCSVFunction · 0.85
typedReturnClauseFunction · 0.85

Tested by

no test coverage detected