exportDatabaseLines function

Future<List<Object>> exportDatabaseLines(
  1. Database db, {
  2. List<String>? storeNames,
})

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.

Implementation

Future<List<Object>> exportDatabaseLines(
  Database db, {
  List<String>? storeNames,
}) async {
  var lines = <Object>[];

  await _exportDatabase(
    db,
    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;
}