Skip to content

Commit

Permalink
Fix failed inserts and updates with null argument lists
Browse files Browse the repository at this point in the history
  • Loading branch information
cachapa committed Oct 23, 2023
1 parent 31b728d commit 1bfab08
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.4

- Fix failed inserts and updates with null argument lists

## 2.1.3

- Automatically convert String HLCs when merging records
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: sqlite_crdt
description: Dart implementation of Conflict-free Replicated Data Types (CRDTs) using Sqlite
version: 2.1.3
version: 2.1.4
homepage: https://github.com/cachapa/sqlite_crdt
repository: https://github.com/cachapa/sqlite_crdt
issue_tracker: https://github.com/cachapa/sqlite_crdt/issues
Expand All @@ -12,7 +12,7 @@ dependencies:
sqflite_common: ^2.5.0
sqflite_common_ffi: ^2.3.0+2
sqflite_common_ffi_web: ^0.4.0
sql_crdt: ^2.1.3
sql_crdt: ^2.1.4
# path: ../sql_crdt

dev_dependencies:
Expand Down
70 changes: 59 additions & 11 deletions test/sqlite_crdt_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ void main() {
expect(result.first['name'], 'John Doe');
});

test('Insert without arguments', () async {
await crdt.execute('''
INSERT INTO users (id, name)
VALUES (1, 'John Doe')
''');
final result = await crdt.query('SELECT * FROM users');
expect(result.first['name'], 'John Doe');
});

test('Replace', () async {
await _insertUser(crdt, 1, 'John Doe');
final insertHlc =
Expand All @@ -69,6 +78,40 @@ void main() {
expect((result.first['hlc'] as String).compareTo(insertHlc), 1);
});

test('Replace without arguments', () async {
await _insertUser(crdt, 1, 'John Doe');
final insertHlc =
(await crdt.query('SELECT hlc FROM users')).first['hlc'] as String;
await crdt
.execute("REPLACE INTO users (id, name) VALUES (1, 'Jane Doe')");
final result = await crdt.query('SELECT * FROM users');
expect(result.first['name'], 'Jane Doe');
expect((result.first['hlc'] as String).compareTo(insertHlc), 1);
});

test('Update', () async {
await _insertUser(crdt, 1, 'John Doe');
final insertHlc =
(await crdt.query('SELECT hlc FROM users')).first['hlc'] as String;
await _updateUser(crdt, 1, 'Jane Doe');
final result = await crdt.query('SELECT * FROM users');
expect(result.first['name'], 'Jane Doe');
expect((result.first['hlc'] as String).compareTo(insertHlc), 1);
});

test('Update without arguments', () async {
await _insertUser(crdt, 1, 'John Doe');
final insertHlc =
(await crdt.query('SELECT hlc FROM users')).first['hlc'] as String;
await crdt.execute('''
UPDATE users SET name = 'Jane Doe'
WHERE id = 1
''');
final result = await crdt.query('SELECT * FROM users');
expect(result.first['name'], 'Jane Doe');
expect((result.first['hlc'] as String).compareTo(insertHlc), 1);
});

test('Upsert', () async {
await _insertUser(crdt, 1, 'John Doe');
final insertHlc =
Expand All @@ -82,11 +125,14 @@ void main() {
expect((result.first['hlc'] as String).compareTo(insertHlc), 1);
});

test('Update', () async {
test('Upsert without arguments', () async {
await _insertUser(crdt, 1, 'John Doe');
final insertHlc =
(await crdt.query('SELECT hlc FROM users')).first['hlc'] as String;
await _updateUser(crdt, 1, 'Jane Doe');
await crdt.execute('''
INSERT INTO users (id, name) VALUES (1, 'Jane Doe')
ON CONFLICT (id) DO UPDATE SET name = 'Jane Doe'
''');
final result = await crdt.query('SELECT * FROM users');
expect(result.first['name'], 'Jane Doe');
expect((result.first['hlc'] as String).compareTo(insertHlc), 1);
Expand All @@ -103,6 +149,17 @@ void main() {
expect(result.first['is_deleted'], 1);
});

test('Delete without arguments', () async {
await _insertUser(crdt, 1, 'John Doe');
await crdt.execute('''
DELETE FROM users
WHERE id = 1
''');
final result = await crdt.query('SELECT * FROM users');
expect(result.first['name'], 'John Doe');
expect(result.first['is_deleted'], 1);
});

test('Transaction', () async {
await crdt.transaction((txn) async {
await _insertUser(txn, 1, 'John Doe');
Expand Down Expand Up @@ -134,15 +191,6 @@ void main() {
expect(result.first['name'], 'John Doe');
expect(result.first['hlc'] as String, hlc.toString());
});

test('Insert without arguments', () async {
await crdt.execute('''
INSERT INTO users (id, name)
VALUES (1, 'John Doe')
''');
final result = await crdt.query('SELECT * FROM users');
expect(result.first['name'], 'John Doe');
});
});

group('Watch', () {
Expand Down

0 comments on commit 1bfab08

Please sign in to comment.