sdbImportDatabase function

Future<Database> sdbImportDatabase(
  1. Object data,
  2. IdbFactory dstFactory,
  3. String dstDbName
)

Copy a database export (lines or map sembast export) to another

return the opened database

Implementation

Future<Database> sdbImportDatabase(
    Object data, IdbFactory dstFactory, String dstDbName) async {
  // if it is a sembast factory use it!
  // if (false) {
  if (dstFactory is IdbFactorySembast) {
    final sdbDb = await sembast.importDatabaseAny(
        data, dstFactory.sdbFactory, dstFactory.getDbPath(dstDbName));
    return dstFactory.openFromSdbDatabase(sdbDb);
  } else {
    // import to a memory one
    final sdbDb = await sembast.importDatabaseAny(
        data, sembast.databaseFactoryMemory, _tempExportPath);
    final tmpDb = await (idbFactoryMemory as IdbFactorySembast)
        .openFromSdbDatabase(sdbDb);
    final db = await copyDatabase(tmpDb, dstFactory, dstDbName);
    tmpDb.close();
    return db;
  }
}