exportDatabase function

Future<Map<String, Object?>> exportDatabase(
  1. DatabaseClient client, {
  2. List<String>? storeNames,
  3. SembastExportOptions? options,
})

Return the data in an exported format that (can be JSONified).

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

See exportDatabaseLines for client and options.

Implementation

Future<Map<String, Object?>> exportDatabase(
  DatabaseClient client, {
  List<String>? storeNames,
  SembastExportOptions? options,
}) async {
  var export = newModel();
  final storesExport = <Map<String, Object?>>[];
  await _exportDatabase(
    client,
    typeEncoding: options?.typeEncoding,
    exportMeta: (Model map) {
      export.addAll(map);
    },
    exportStore: (Model map) {
      storesExport.add(map);
    },
    storeNames: options?.storeNames ?? storeNames,
  );

  if (storesExport.isNotEmpty) {
    export[_stores] = storesExport;
  }
  return export;
}