mirror of https://github.com/AMT-Cheif/drift.git
Forbid distinct groupConcat with separator
This commit is contained in:
parent
946b6807d4
commit
78470b4280
|
@ -51,6 +51,12 @@ extension BaseAggregate<DT> on Expression<DT> {
|
|||
}) {
|
||||
const sqliteDefaultSeparator = ',';
|
||||
|
||||
// Distinct aggregates can only have one argument
|
||||
if (distinct && separator != sqliteDefaultSeparator) {
|
||||
throw ArgumentError(
|
||||
'Cannot use groupConcat with distinct: true and a custom serparator');
|
||||
}
|
||||
|
||||
return _AggregateExpression(
|
||||
'GROUP_CONCAT',
|
||||
[
|
||||
|
|
|
@ -83,21 +83,6 @@ void main() {
|
|||
expect(foo.groupConcat(distinct: true),
|
||||
generates('GROUP_CONCAT(DISTINCT foo)', isEmpty));
|
||||
|
||||
expect(foo.groupConcat(distinct: true, separator: ' and '),
|
||||
generates('GROUP_CONCAT(DISTINCT foo, ?)', [' and ']));
|
||||
|
||||
expect(
|
||||
foo.groupConcat(
|
||||
distinct: true,
|
||||
separator: ' and ',
|
||||
filter: foo.isSmallerThan(const Variable(3)),
|
||||
),
|
||||
generates(
|
||||
'GROUP_CONCAT(DISTINCT foo, ?) FILTER (WHERE foo < ?)',
|
||||
[' and ', 3],
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
foo.groupConcat(
|
||||
distinct: true,
|
||||
|
@ -109,5 +94,19 @@ void main() {
|
|||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('does not allow distinct with a custom separator', () {
|
||||
expect(() => foo.groupConcat(distinct: true, separator: ' and '),
|
||||
throwsArgumentError);
|
||||
|
||||
expect(
|
||||
() => foo.groupConcat(
|
||||
distinct: true,
|
||||
separator: ' and ',
|
||||
filter: foo.isSmallerThan(const Variable(3)),
|
||||
),
|
||||
throwsArgumentError,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue