Merge pull request #2814 from tt88dev/bugfix/max-and-min-string

[bugfix/max_and_min_string]
This commit is contained in:
Simon Binder 2024-01-03 13:20:20 +01:00 committed by GitHub
commit 379b92d09c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

1
.gitignore vendored
View File

@ -20,3 +20,4 @@ docs/**/*.g.dart
*/build/
drift/extension/devtools/build
**/pubspec_overrides.yaml
**.history/

View File

@ -30,6 +30,20 @@ extension BaseAggregate<DT extends Object> on Expression<DT> {
filter: filter, distinct: distinct);
}
/// Return the maximum of all non-null values in this group.
///
/// If there are no non-null values in the group, returns null.
/// {@macro drift_aggregate_filter}
Expression<DT> max({Expression<bool>? filter}) =>
_AggregateExpression('MAX', [this], filter: filter);
/// Return the minimum of all non-null values in this group.
///
/// If there are no non-null values in the group, returns null.
/// {@macro drift_aggregate_filter}
Expression<DT> min({Expression<bool>? filter}) =>
_AggregateExpression('MIN', [this], filter: filter);
/// Returns the concatenation of all non-null values in the current group,
/// joined by the [separator].
///

View File

@ -5,6 +5,7 @@ import '../../test_utils/test_utils.dart';
void main() {
const foo = CustomExpression<int>('foo', precedence: Precedence.primary);
const s1 = CustomExpression<String>('s1', precedence: Precedence.primary);
group('count', () {
test('all', () {
@ -49,10 +50,12 @@ void main() {
test('max', () {
expect(foo.max(), generates('MAX(foo)'));
expect(s1.max(), generates('MAX(s1)'));
});
test('min', () {
expect(foo.min(), generates('MIN(foo)'));
expect(s1.min(), generates('MIN(s1)'));
});
test('sum', () {