Skip to content
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

[bugfix/max_and_min_string] #2814

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ docs/**/*.g.dart
*/build/
drift/extension/devtools/build
**/pubspec_overrides.yaml
**.history/
14 changes: 14 additions & 0 deletions drift/lib/src/runtime/query_builder/expressions/aggregate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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].
///
Expand Down
3 changes: 3 additions & 0 deletions drift/test/database/expressions/aggregate_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down Expand Up @@ -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', () {
Expand Down
Loading