diff --git a/drift/CHANGELOG.md b/drift/CHANGELOG.md index f3a56026..3c5f617b 100644 --- a/drift/CHANGELOG.md +++ b/drift/CHANGELOG.md @@ -1,7 +1,11 @@ -## 1.3.0 +## (unreleased) - Add the `from(table)` method to generated databases. It can be used to write common queries more concisely. +- Make `groupConcat` nullable in the Dart API. +- Throw an exception in a `NativeDatabase` when multiple statements are run in + a single call. In previous versions, parts of the SQL string would otherwise + be ignored. ## 1.2.0 diff --git a/drift/lib/src/runtime/query_builder/expressions/aggregate.dart b/drift/lib/src/runtime/query_builder/expressions/aggregate.dart index bd4cb3f6..b0325d80 100644 --- a/drift/lib/src/runtime/query_builder/expressions/aggregate.dart +++ b/drift/lib/src/runtime/query_builder/expressions/aggregate.dart @@ -33,12 +33,13 @@ extension BaseAggregate
on Expression
{ /// Returns the concatenation of all non-null values in the current group, /// joined by the [separator]. /// - /// The order of the concatenated elements is arbitrary. + /// The order of the concatenated elements is arbitrary. If no non-null values + /// exist in the group, `NULL` is returned. /// /// See also: /// - the sqlite documentation: https://www.sqlite.org/lang_aggfunc.html#groupconcat /// - the conceptually similar [Iterable.join] - Expression groupConcat({String separator = ','}) { + Expression groupConcat({String separator = ','}) { const sqliteDefaultSeparator = ','; if (separator == sqliteDefaultSeparator) { return _AggregateExpression('GROUP_CONCAT', this); diff --git a/drift/test/expressions/expressions_integration_test.dart b/drift/test/expressions/expressions_integration_test.dart index 6c471a52..d30e9750 100644 --- a/drift/test/expressions/expressions_integration_test.dart +++ b/drift/test/expressions/expressions_integration_test.dart @@ -1,5 +1,5 @@ @TestOn('vm') -import 'package:drift/drift.dart'; +import 'package:drift/drift.dart' hide isNull; import 'package:drift/native.dart'; import 'package:test/test.dart'; @@ -139,6 +139,16 @@ void main() { expect(eval(noMatch), completion(isFalse)); }); + test('groupConcat is nullable', () async { + final ids = db.users.id.groupConcat(); + final query = db.selectOnly(db.users) + ..where(db.users.id.equals(999)) + ..addColumns([ids]); + + final result = await query.getSingle(); + expect(result.read(ids), isNull); + }); + test('subqueries cause updates to stream queries', () async { await db .into(db.categories)