exportDatabaseLines function
- DatabaseClient client, {
- List<
String> ? storeNames, - SembastExportOptions? options,
Return the data in an exported format where each item in the list can be JSONified. If simply encoded as list of json string, it makes it suitable to archive a mutable export on a git file system.
An optional storeNames can specify the list of stores to export. If null
All stores are exported.
options can give the stores to export (overriding storeNames) and the
encoding of the custom types. Without a type encoding (the legacy export),
the custom types are encoded by the database codec (@Timestamp, @Blob
by default). With one, they are encoded in it ($Timestamp, $Blob for
SembastExportTypeEncoding.dollar) and the header gives it
({"sembast_export": 1, "version": 1, "type_prefix": "$"}, the import
reads it). SembastExportTypeEncoding.at from a database whose codec uses
@ is the legacy export.
client is a database or a transaction. In a transaction, the export
runs in it and includes its changes: writing and exporting can happen in
the same transaction.
Implementation
Future<List<Object>> exportDatabaseLines(
DatabaseClient client, {
List<String>? storeNames,
SembastExportOptions? options,
}) async {
var lines = <Object>[];
await _exportDatabase(
client,
typeEncoding: options?.typeEncoding,
storeNames: options?.storeNames ?? storeNames,
exportMeta: (Model map) {
lines.add(map);
},
exportStore: (Model map) {
lines.add(newModel()..[_store] = map[_name]);
var keys = map[_keys] as List;
var values = map[_values] as List;
for (var i = 0; i < keys.length; i++) {
lines.add([keys[i], values[i]]);
}
},
);
return lines;
}