sdbImportDatabase function

Future<SdbDatabase> sdbImportDatabase(
  1. Object data,
  2. SdbFactory dstFactory,
  3. String dstDbName, {
  4. SdbCodec? codec,
  5. SdbImportOptions? options,
})

Import a database from sdb export lines

data is a sembast export (lines, map or their json/jsonl string), with or without the sdb_export marker (idb exports and older sdb ones have none). A newer sdb export throws a FormatException.

The custom types are decoded in the encoding given by the export header (type_prefix), the legacy @ one without it. options can restrict the accepted encodings (all by default), another one throws a FormatException.

Implementation

Future<SdbDatabase> sdbImportDatabase(
  Object data,
  SdbFactory dstFactory,
  String dstDbName, {
  SdbCodec? codec,
  SdbImportOptions? options,
}) async {
  data = decodeImportAny(data);
  sdbCheckExportHeader(data);
  if (dstFactory is SdbFactoryIdb) {
    // idb based, import the underlying database (the idb factory of a
    // sandbox is an idb sandbox, mapping the name).
    var idbDatabase = await idbImportDatabase(
      data,
      dstFactory.idbFactory,
      dstDbName,
      options: options,
    );
    return SdbDatabaseImpl.idbDatabase(dstFactory, idbDatabase, codec: codec);
  }
  return sdbImportDatabaseGeneric(
    data,
    dstFactory,
    dstDbName,
    codec: codec,
    options: options,
  );
}