crdt_lf_sqlite 0.3.0 copy "crdt_lf_sqlite: ^0.3.0" to clipboard
crdt_lf_sqlite: ^0.3.0 copied to clipboard

sqlite3 storage adapter for CRDT LF library objects, providing persistence for Change and Snapshot objects.

example/main.dart

// The example prints its result, and it is not a library entry point.
// ignore_for_file: avoid_print

import 'dart:io' as io;

import 'package:crdt_lf/crdt_lf.dart';
import 'package:crdt_lf_sqlite/crdt_lf_sqlite.dart';

Future<void> main() async {
  const itemsToAdd = 3;
  const documentId = '784ff372-6f0a-4fe9-8e63-19b72fd18c23';

  // Resolve the database next to this script so the example works regardless
  // of the current working directory.
  final dbLocation =
      '${io.File.fromUri(io.Platform.script).parent.path}/crdt_example.db';

  final backend = CRDTSqlite.open(dbLocation);

  // Reads the database into a document and follows it: everything written from
  // here on is stored without another line of code. The identity comes from
  // the backend too, so every run is the same author.
  final note = await backend.openDocument(documentId);
  final list = CRDTListHandler<String>(note.document, 'list');

  print('read back: ${list.value}');

  final length = list.value.length;
  for (var i = length; i < length + itemsToAdd; i++) {
    list.insert(i, 'Item $i');
  }

  // Writes what is still waiting. Without it the process could end before the
  // delayed write runs.
  await note.persistence.dispose();
  note.document.dispose();

  print('now: ${list.value}');
  print('documents in the database: ${backend.documentIds.length}');

  backend.close();
}
0
likes
150
points
211
downloads

Documentation

API reference

Publisher

verified publishermattiapispisa.it

Weekly Downloads

sqlite3 storage adapter for CRDT LF library objects, providing persistence for Change and Snapshot objects.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#crdt #local-first #sqlite #persistence #dart

License

MIT (license)

Dependencies

crdt_lf, crdt_lf_persistence, hlc_dart, sqlite3

More

Packages that depend on crdt_lf_sqlite