-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eng(supabase): expose private supabase methods as protected; allow ty…
…pe generics in SQLite domain (#469)
- Loading branch information
Showing
10 changed files
with
87 additions
and
24 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
42 changes: 42 additions & 0 deletions
42
packages/brick_offline_first/lib/src/mixins/get_first_mixin.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,42 @@ | ||
import 'package:brick_offline_first/brick_offline_first.dart'; | ||
|
||
/// A convenience mixin for single-instance get operations. | ||
mixin GetFirstMixin<CModel extends OfflineFirstModel> on OfflineFirstRepository<CModel> { | ||
/// Retrieves the first instance of [TModel] with certainty that it exists. | ||
/// If no instances exist, a [StateError] is thrown from within Dart's core | ||
/// `Iterable#first` method. It is recommended to use [getFirstOrNull] instead. | ||
/// | ||
/// Automatically applies `'limit': 1` to the query's `providerArgs` | ||
Future<TModel> getFirst<TModel extends CModel>({ | ||
OfflineFirstGetPolicy policy = OfflineFirstGetPolicy.awaitRemoteWhenNoneExist, | ||
Query? query, | ||
bool seedOnly = false, | ||
}) async { | ||
final result = await super.get<TModel>( | ||
policy: policy, | ||
query: query?.copyWith(providerArgs: {'limit': 1}), | ||
seedOnly: seedOnly, | ||
); | ||
|
||
return result.first; | ||
} | ||
|
||
/// A safer version of [getFirst] that attempts to get the first instance of [TModel] | ||
/// according to the [query], but returns `null` if no instances exist. | ||
/// | ||
/// Automatically applies `'limit': 1` to the query's `providerArgs` | ||
Future<TModel?> getFirstOrNull<TModel extends CModel>({ | ||
OfflineFirstGetPolicy policy = OfflineFirstGetPolicy.awaitRemoteWhenNoneExist, | ||
Query? query, | ||
bool seedOnly = false, | ||
}) async { | ||
final result = await super.get<TModel>( | ||
policy: policy, | ||
query: query?.copyWith(providerArgs: {'limit': 1}), | ||
seedOnly: seedOnly, | ||
); | ||
|
||
if (result.isEmpty) return null; | ||
return result.first; | ||
} | ||
} |
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
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