Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the user to import into a different database than the one specified in the file #1973

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading