importDatabaseAny function

Future<Database> importDatabaseAny(
  1. Object srcData,
  2. DatabaseFactory dstFactory,
  3. String dstPath, {
  4. SembastCodec? codec,
  5. List<String>? storeNames,
})

Import the exported data (using exportDatabase or exportDatabaseLines or their json encoding or a string of it) into a new database

An optional storeNames can specify the list of stores to import. If null All stores are exported.

Implementation

Future<Database> importDatabaseAny(
    Object srcData, DatabaseFactory dstFactory, String dstPath,
    {SembastCodec? codec, List<String>? storeNames}) {
  Future<Database> mapImport(Map map) {
    return importDatabase(map, dstFactory, dstPath,
        codec: codec, storeNames: storeNames);
  }

  Future<Database> linesImport(List lines) {
    return importDatabaseLines(lines, dstFactory, dstPath,
        codec: codec, storeNames: storeNames);
  }

  srcData = decodeImportAny(srcData);
  try {
    if (srcData is Map) {
      return mapImport(srcData);
    } else if (srcData is List) {
      return linesImport(srcData);
    }
  } catch (e) {
    if (isDebug) {
      // ignore: avoid_print
      print('import error $e');
    }
    throw FormatException('invalid export format (error: $e)');
  }
  throw FormatException('invalid export format (${srcData.runtimeType})');
}