-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support OfflineFirstSerdes as a unique field for SQLite (#388)
- Loading branch information
Showing
28 changed files
with
217 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
## Unreleased | ||
|
||
## 1.2.0 | ||
|
||
* Apply standardized lints | ||
* Upgrade minimum Dart to 2.18 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
## Unreleased | ||
|
||
## 3.1.0 | ||
|
||
* Apply standardized lints | ||
* Upgrade minimum Dart to 2.18 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
## Unreleased | ||
|
||
## 3.1.0 | ||
|
||
* Apply standardized lints | ||
* Upgrade minimum Dart to 2.18 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
128 changes: 128 additions & 0 deletions
128
...ck_offline_first_build/test/offline_first_generator/test_unique_offline_first_serdes.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import 'package:brick_offline_first/brick_offline_first.dart' show OfflineFirstSerdes; | ||
import 'package:brick_offline_first_with_rest/brick_offline_first_with_rest.dart'; | ||
import 'package:brick_sqlite/brick_sqlite.dart'; | ||
|
||
final output = r""" | ||
// GENERATED CODE DO NOT EDIT | ||
part of '../brick.g.dart'; | ||
Future<CustomOfflineFirstSerdes> _$CustomOfflineFirstSerdesFromTest( | ||
Map<String, dynamic> data, | ||
{required TestProvider provider, | ||
OfflineFirstRepository? repository}) async { | ||
return CustomOfflineFirstSerdes( | ||
string: Serializable.fromTest(data['string'])); | ||
} | ||
Future<Map<String, dynamic>> _$CustomOfflineFirstSerdesToTest( | ||
CustomOfflineFirstSerdes instance, | ||
{required TestProvider provider, | ||
OfflineFirstRepository? repository}) async { | ||
return {'string': instance.string?.toTest()}; | ||
} | ||
Future<CustomOfflineFirstSerdes> _$CustomOfflineFirstSerdesFromSqlite( | ||
Map<String, dynamic> data, | ||
{required SqliteProvider provider, | ||
OfflineFirstRepository? repository}) async { | ||
return CustomOfflineFirstSerdes( | ||
string: data['string'] == null | ||
? null | ||
: Serializable.fromSqlite(data['string'] as int)) | ||
..primaryKey = data['_brick_id'] as int; | ||
} | ||
Future<Map<String, dynamic>> _$CustomOfflineFirstSerdesToSqlite( | ||
CustomOfflineFirstSerdes instance, | ||
{required SqliteProvider provider, | ||
OfflineFirstRepository? repository}) async { | ||
return {}; | ||
} | ||
/// Construct a [CustomOfflineFirstSerdes] | ||
class CustomOfflineFirstSerdesAdapter | ||
extends OfflineFirstAdapter<CustomOfflineFirstSerdes> { | ||
CustomOfflineFirstSerdesAdapter(); | ||
@override | ||
final Map<String, RuntimeSqliteColumnDefinition> fieldsToSqliteColumns = { | ||
'primaryKey': const RuntimeSqliteColumnDefinition( | ||
association: false, | ||
columnName: '_brick_id', | ||
iterable: false, | ||
type: int, | ||
), | ||
'string': const RuntimeSqliteColumnDefinition( | ||
association: false, | ||
columnName: 'string', | ||
iterable: false, | ||
type: Serializable, | ||
) | ||
}; | ||
@override | ||
Future<int?> primaryKeyByUniqueColumns( | ||
CustomOfflineFirstSerdes instance, DatabaseExecutor executor) async { | ||
final results = await executor.rawQuery(''' | ||
SELECT * FROM `CustomOfflineFirstSerdes` WHERE string = ? LIMIT 1''', | ||
[instance.string.toSqlite()]); | ||
// SQFlite returns [{}] when no results are found | ||
if (results.isEmpty || (results.length == 1 && results.first.isEmpty)) { | ||
return null; | ||
} | ||
return results.first['_brick_id'] as int; | ||
} | ||
@override | ||
final String tableName = 'CustomOfflineFirstSerdes'; | ||
@override | ||
Future<CustomOfflineFirstSerdes> fromTest(Map<String, dynamic> input, | ||
{required provider, | ||
covariant OfflineFirstRepository? repository}) async => | ||
await _$CustomOfflineFirstSerdesFromTest(input, | ||
provider: provider, repository: repository); | ||
@override | ||
Future<Map<String, dynamic>> toTest(CustomOfflineFirstSerdes input, | ||
{required provider, | ||
covariant OfflineFirstRepository? repository}) async => | ||
await _$CustomOfflineFirstSerdesToTest(input, | ||
provider: provider, repository: repository); | ||
@override | ||
Future<CustomOfflineFirstSerdes> fromSqlite(Map<String, dynamic> input, | ||
{required provider, | ||
covariant OfflineFirstRepository? repository}) async => | ||
await _$CustomOfflineFirstSerdesFromSqlite(input, | ||
provider: provider, repository: repository); | ||
@override | ||
Future<Map<String, dynamic>> toSqlite(CustomOfflineFirstSerdes input, | ||
{required provider, | ||
covariant OfflineFirstRepository? repository}) async => | ||
await _$CustomOfflineFirstSerdesToSqlite(input, | ||
provider: provider, repository: repository); | ||
} | ||
"""; | ||
|
||
class Serializable extends OfflineFirstSerdes<Map<String, dynamic>, int> { | ||
final int age; | ||
Serializable(this.age); | ||
|
||
Map<String, dynamic> toTest() => {'age': '$age'}; | ||
|
||
factory Serializable.fromTest(Map<String, dynamic> data) { | ||
return Serializable(data['age']); | ||
} | ||
|
||
factory Serializable.fromSqlite(age) { | ||
return Serializable(age); | ||
} | ||
} | ||
|
||
@ConnectOfflineFirstWithRest() | ||
class CustomOfflineFirstSerdes { | ||
CustomOfflineFirstSerdes({this.string}); | ||
|
||
@Sqlite(unique: true) | ||
final Serializable? string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
## Unreleased | ||
|
||
## 3.1.0 | ||
|
||
* Upgrade minimum Dart to 2.18 | ||
|
||
## 3.0.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
## Unreleased | ||
|
||
## 3.2.0 | ||
|
||
* Apply standardized lints | ||
* Upgrade minimum Dart to 2.18 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
## Unreleased | ||
|
||
## 3.1.0 | ||
|
||
* Apply standardized lints | ||
* Upgrade minimum Dart to 2.18 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.