dexie 在导出和导入时使用过滤器 (dexie-export-import)

dexie to use filter while exporting and importing (dexie-export-import)

我在 dexie 数据库中有两个表,我正在尝试使用 dexie-export-import 仅导出-导入其中一个。
官方 dexie 文件说你有过滤器作为可选参数

//Optional filter allows to import/export subset of data
export interface ExportOptions {
  noTransaction?: boolean;
  numRowsPerChunk?: number;
  prettyJson?: boolean;
  filter?: (table: string, value: any, key?: any) => boolean;
  progressCallback?: (progress: ExportProgress) => boolean;
}

谁能告诉我如何使用该过滤器参数...

database.export({prettyJson: true, filter: (table: 'A', value: '', key: '') => true});
import {exportDB} from "dexie-export-import";

function exportSingleTable(db, tableName) {
  return exportDB(db, {filter: (table, value, key) => table === tableName});
}

exportSingleTable(yourDexieInstance, "yourTableNameToExport").then(blob => {
  alert("done");
  // Result is in blob
}).catch(error => {
  alert("error: " + error);
});

更简化的答案:

导出

const blob = await database.export({prettyJson: true, filter: (table, value, key) => table === 'YOUR_TABLE_NAME'});

导入

await database.import(blob, {prettyJson: true, filter: (table, value, key) => table === 'YOUR_TABLE_NAME'});