diff --git a/.gitignore b/.gitignore
index f7932aa5..685e2c62 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,3 +20,4 @@ docs/**/*.g.dart
*/build/
drift/extension/devtools/build
**/pubspec_overrides.yaml
+**.history/
\ No newline at end of file
diff --git a/drift/lib/src/runtime/query_builder/expressions/aggregate.dart b/drift/lib/src/runtime/query_builder/expressions/aggregate.dart
index 2921b3c5..b2f99b52 100644
--- a/drift/lib/src/runtime/query_builder/expressions/aggregate.dart
+++ b/drift/lib/src/runtime/query_builder/expressions/aggregate.dart
@@ -30,6 +30,20 @@ extension BaseAggregate
on Expression {
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 max({Expression? 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 min({Expression? filter}) =>
+ _AggregateExpression('MIN', [this], filter: filter);
+
/// Returns the concatenation of all non-null values in the current group,
/// joined by the [separator].
///
diff --git a/drift/test/database/expressions/aggregate_test.dart b/drift/test/database/expressions/aggregate_test.dart
index 695443a1..7f201f04 100644
--- a/drift/test/database/expressions/aggregate_test.dart
+++ b/drift/test/database/expressions/aggregate_test.dart
@@ -5,6 +5,7 @@ import '../../test_utils/test_utils.dart';
void main() {
const foo = CustomExpression('foo', precedence: Precedence.primary);
+ const s1 = CustomExpression('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', () {