Skip to content

Commit

Permalink
Add CrdtChangeset type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
cachapa committed Aug 17, 2023
1 parent 7cda002 commit bf8920f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.1+1

- Add `CrdtChangeset` type alias

## 1.1.1

- Fix change notifications when no changes were made
Expand Down
6 changes: 4 additions & 2 deletions lib/src/base_crdt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import 'hlc.dart';
import 'sql_util.dart';

part 'sql_crdt.dart';

part 'timestamped_crdt.dart';

part 'transaction_crdt.dart';

typedef CrdtRecord = Map<String, Object?>;
typedef CrdtTableChangeset = List<CrdtRecord>;
typedef CrdtChangeset = Map<String, CrdtTableChangeset>;

/// Intercepts CREATE TABLE queries to assist with table creation and updates
class BaseCrdt {
final DatabaseApi _db;
Expand Down
9 changes: 4 additions & 5 deletions lib/src/sql_crdt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ abstract class SqlCrdt extends TimestampedCrdt {
/// Use [modifiedSince] to fetch only recently changed records.
/// Set [onlyModifiedBy] to get only records changed by the specified node id.
/// Set [exceptModifiedBy] to ignore records changed by the specified node id.
Future<Map<String, Iterable<Map<String, Object?>>>> getChangeset({
Future<CrdtChangeset> getChangeset({
Iterable<String>? fromTables,
Hlc? modifiedSince,
String? onlyModifiedBy,
Expand Down Expand Up @@ -168,7 +168,7 @@ abstract class SqlCrdt extends TimestampedCrdt {
/// Use [fromTables] to specify from which tables to read, returns all tables if null.
/// Use [modifiedSince] to fetch only recently changed records.
/// Set [onlyModifiedHere] to get only records changed in this node.
Stream<Map<String, Iterable<Map<String, Object?>>>> watchChangeset({
Stream<CrdtChangeset> watchChangeset({
Iterable<String>? fromTables,
Hlc? Function()? modifiedSince,
String? onlyModifiedBy,
Expand All @@ -190,8 +190,7 @@ abstract class SqlCrdt extends TimestampedCrdt {
}

/// Merge [changeset] into database
Future<void> merge(
Map<String, Iterable<Map<String, Object?>>> changeset) async {
Future<void> merge(CrdtChangeset changeset) async {
if (changeset.recordCount == 0) return;

var hlc = _canonicalTime;
Expand Down Expand Up @@ -315,7 +314,7 @@ class _Query {
_Query(this.sql, this.args) : affectedTables = SqlUtil.getAffectedTables(sql);
}

extension MapX on Map<String, Iterable<Map<String, Object?>>> {
extension CrdtChangesetX on CrdtChangeset {
/// Convenience method to get number of records in a changeset
int get recordCount => values.fold<int>(0, (prev, e) => prev + e.length);
}
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: sql_crdt
description: Base package for Conflict-free Replicated Data Types (CRDTs) using SQL databases
version: 1.1.1
version: 1.1.1+1
homepage: https://github.com/cachapa/sql_crdt
repository: https://github.com/cachapa/sql_crdt
issue_tracker: https://github.com/cachapa/sql_crdt/issues

environment:
sdk: '^3.0.0'
sdk: ^3.0.0

dependencies:
sqlparser: ^0.30.3
Expand Down

0 comments on commit bf8920f

Please sign in to comment.