-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support OfflineFirstSerdes as a unique field for SQLite #388
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d8d9234
feat: support OfflineFirstSerdes as a unique field for SQLite
tshedor f5c252b
revert save
tshedor 1a1b348
fix tests
tshedor 98a1d9e
update subpackage versions
tshedor 2beb5a9
use gh concurrency instead of external package
tshedor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,10 @@ on: | |
required: true | ||
type: string | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.package }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
dart_analyze_format_test: | ||
runs-on: ubuntu-latest | ||
|
@@ -15,10 +19,6 @@ jobs: | |
matrix: | ||
sdk_version: [beta, stable] | ||
steps: | ||
- name: Cancel Previous Runs | ||
uses: styfle/cancel-workflow-action@89f242ee29e10c53a841bfe71cc0ce7b2f065abc | ||
with: | ||
access_token: ${{ github.token }} | ||
- uses: dart-lang/[email protected] | ||
with: | ||
sdk: ${{ matrix.sdk_version }} | ||
|
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice stealing this