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

Added SkipTables Option #1896

Merged
merged 1 commit into from
Feb 6, 2024
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
9 changes: 6 additions & 3 deletions addons/dexie-export-import/src/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,8 +26,10 @@ const DEFAULT_ROWS_PER_CHUNK = 2000;

export async function exportDB(db: Dexie, options?: ExportOptions): Promise<Blob> {
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
Expand All @@ -49,7 +52,7 @@ export async function exportDB(db: Dexie, options?: ExportOptions): Promise<Blob
completedRows: 0,
completedTables: 0,
totalRows: NaN,
totalTables: db.tables.length
totalTables: tables.length
};

try {
Expand All @@ -66,7 +69,7 @@ export async function exportDB(db: Dexie, options?: ExportOptions): Promise<Blob

async function exportAll() {
// Count rows:
const tablesRowCounts = await Promise.all(db.tables.map(table => 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);

Expand Down
4 changes: 4 additions & 0 deletions addons/dexie-export-import/src/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,6 +69,7 @@ export async function importInto(db: Dexie, exportedData: Blob | JsonStream<Dexi
const readBlobsSynchronously = 'FileReaderSync' in self; // true in workers only.

const dbExport = dbExportFile.data!;
const skipTables = options.skipTables? options.skipTables: []

if (!options!.acceptNameDiff && db.name !== dbExport.databaseName)
throw new Error(`Name differs. Current database name is ${db.name} but export is ${dbExport.databaseName}`);
Expand All @@ -91,6 +93,7 @@ export async function importInto(db: Dexie, exportedData: Blob | JsonStream<Dexi

if (options!.clearTablesBeforeImport) {
for (const table of db.tables) {
if(skipTables.includes(table.name) ) continue;
await table.clear();
}
}
Expand All @@ -104,6 +107,7 @@ export async function importInto(db: Dexie, exportedData: Blob | JsonStream<Dexi
async function importAll () {
do {
for (const tableExport of dbExport.data) {
if(skipTables.includes(tableExport.tableName)) continue;
if (!tableExport.rows) break; // Need to pull more!
if (!(tableExport.rows as any).incomplete && tableExport.rows.length === 0)
continue;
Expand Down
Loading