From ec840ba4824be45364b560b64b39cd407924e3a6 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 5 Feb 2024 11:09:53 -0500 Subject: [PATCH] Ability to SkipTables --- addons/dexie-export-import/src/export.ts | 9 ++++++--- addons/dexie-export-import/src/import.ts | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/addons/dexie-export-import/src/export.ts b/addons/dexie-export-import/src/export.ts index de89bac81..53e41f867 100644 --- a/addons/dexie-export-import/src/export.ts +++ b/addons/dexie-export-import/src/export.ts @@ -5,6 +5,7 @@ import { DexieExportedTable, DexieExportJsonStructure } from './json-structure'; import { TSON } from './tson'; export interface ExportOptions { + skipTables?: string[], noTransaction?: boolean; numRowsPerChunk?: number; prettyJson?: boolean; @@ -25,8 +26,10 @@ const DEFAULT_ROWS_PER_CHUNK = 2000; export async function exportDB(db: Dexie, options?: ExportOptions): Promise { options = options || {}; + const skipTables = options.skipTables? options.skipTables: [] + const targetTables = db.tables.filter((x)=> !skipTables.includes(x.name)) const slices: (string | Blob)[] = []; - const tables = db.tables.map(table => ({ + const tables = targetTables.map(table => ({ name: table.name, schema: getSchemaString(table), rowCount: 0 @@ -49,7 +52,7 @@ export async function exportDB(db: Dexie, options?: ExportOptions): Promise table.count())); + const tablesRowCounts = await Promise.all(targetTables.map(table => table.count())); tablesRowCounts.forEach((rowCount, i) => tables[i].rowCount = rowCount); progress.totalRows = tablesRowCounts.reduce((p,c)=>p+c); diff --git a/addons/dexie-export-import/src/import.ts b/addons/dexie-export-import/src/import.ts index 385e6b074..2fae19a2d 100644 --- a/addons/dexie-export-import/src/import.ts +++ b/addons/dexie-export-import/src/import.ts @@ -19,6 +19,7 @@ export interface ImportOptions extends StaticImportOptions { acceptChangedPrimaryKey?: boolean; overwriteValues?: boolean; clearTablesBeforeImport?: boolean; + skipTables?: string[], noTransaction?: boolean; chunkSizeBytes?: number; // Default: DEFAULT_KILOBYTES_PER_CHUNK ( 1MB ) filter?: (table: string, value: any, key?: any) => boolean; @@ -68,6 +69,7 @@ export async function importInto(db: Dexie, exportedData: Blob | JsonStream