Make groupConcat nullable in Dart (closes #1628)

This commit is contained in:
Simon Binder 2022-01-11 13:31:29 +01:00
parent b7dd8872c5
commit 25c62e5677
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
3 changed files with 19 additions and 4 deletions

View File

@ -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

View File

@ -33,12 +33,13 @@ extension BaseAggregate<DT> on Expression<DT> {
/// 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<String> groupConcat({String separator = ','}) {
Expression<String?> groupConcat({String separator = ','}) {
const sqliteDefaultSeparator = ',';
if (separator == sqliteDefaultSeparator) {
return _AggregateExpression('GROUP_CONCAT', this);

View File

@ -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)