Skip to content

Commit

Permalink
Allow import with custom name (#1973)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasBora authored Nov 15, 2024
1 parent 527ac54 commit 7781374
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions addons/dexie-export-import/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export interface StaticImportOptions {
chunkSizeBytes?: number; // Default: DEFAULT_KILOBYTES_PER_CHUNK ( 1MB )
filter?: (table: string, value: any, key?: any) => boolean;
progressCallback?: (progress: ImportProgress) => boolean;
name?: string;
}

export interface ImportOptions extends StaticImportOptions {
Expand Down
5 changes: 3 additions & 2 deletions addons/dexie-export-import/src/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface StaticImportOptions {
filter?: (table: string, value: any, key?: any) => boolean;
transform?: (table: string, value: any, key?: any) => ({value: any, key?: any});
progressCallback?: (progress: ImportProgress) => boolean;
name?: string;
}

export interface ImportOptions extends StaticImportOptions {
Expand Down Expand Up @@ -42,9 +43,9 @@ export async function importDB(exportedData: Blob | JsonStream<DexieExportJsonSt
const CHUNK_SIZE = options!.chunkSizeBytes || (DEFAULT_KILOBYTES_PER_CHUNK * 1024);
const stream = await loadUntilWeGotEnoughData(exportedData, CHUNK_SIZE);
const dbExport = stream.result.data!;
const db = new Dexie(dbExport.databaseName);
const db = new Dexie(options.name !== undefined ? options.name : dbExport.databaseName);
db.version(dbExport.databaseVersion).stores(extractDbSchema(dbExport));
await importInto(db, stream, options);
await importInto(db, stream, options.name !== undefined ? {...options, acceptNameDiff: true } : options);
return db;
}

Expand Down

0 comments on commit 7781374

Please sign in to comment.