It is possible to put parentheses in WHERE condition without CustomExpression #1544
Answered
by
simolus3
ycherniavskyi
asked this question in
Q&A
-
Particularly is it possible to write the next WHERE condition with dart code and without SimpleSelectStatement<$ContactsTableTable, ContactData> _selectAllContacts([ContactSourceType? sourceType]) =>
select(contactsTable)
..where((t) {
if (sourceType == null) {
return const Constant(true);
} else {
return t.sourceType.equals(sourceType.index);
}
})
..where((t) => const CustomExpression<bool?>(
"(display_name IS NOT NULL AND NOT (display_name = '')) OR (first_name IS NOT NULL AND NOT (first_name = '')) OR (last_name IS NOT NULL AND NOT (last_name = ''))"))
..orderBy([
(t) => OrderingTerm.asc(t.displayName),
(t) => OrderingTerm.asc(t.lastName),
(t) => OrderingTerm.asc(t.firstName),
]);
Stream<List<ContactData>> watchAllContacts([ContactSourceType? sourceType]) => _selectAllContacts(sourceType).watch(); |
Beta Was this translation helpful? Give feedback.
Answered by
simolus3
Nov 13, 2021
Replies: 1 comment 3 replies
-
Drift is supposed to add parentheses where this is necessary. However, |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
ycherniavskyi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Drift is supposed to add parentheses where this is necessary. However,
OR
has the lowest precedence andNOT
has a lower precedence than=
. So it looks like the parentheses are not needed in your custom expression? Do you just want the parentheses to make the generated query easier to reason about or is there something going wrong here?