Skip to content

Conditional expression

Ravi Teja Gudapati edited this page Jan 24, 2019 · 6 revisions

The most common case of conditional expression is comparing against a column/field in the table.

Note: Jaguar ORM generates Field elements in the bean for all columns in the table.

Lets consider the following two fields:

final name = StringField('name');
final age= IntField('age');

Comparison operators

// Retrieve all rows where age is greater than 25
Find('people').selAll().where(age > 25);

// Retrieve all rows where age is greater than or equal to 25
Find('people').selAll().where(age >= 25);  

// Retrieve all rows where age is less than 25
Find('people').selAll().where(age < 25);

// Retrieve all rows where age is less than or equal to 25
Find('people').selAll().where(age <= 25);

Alternatively, gt, gtEq, lt and ltEq methods can be used.

Equality operators

Dart does not allow == and != operators. So we have to use eq and eq methods:

// Retrieve all rows where age is greater than 25
Find('people').selAll().where(name.eq('Teja'));

// Retrieve all rows where age is greater than or equal to 25
Find('people').selAll().where(name.eq('Harry'));

Like (%) operator

Find('people').selAll().where(name % 'Harry%');

Alternatively, like method can be used.

Between operator

TODO

AND and OR expressions

& and | operators can be used to build nested conditions.

Find('people').selAll().where((firstName.eq('Harry') | lastName.eq('Harry')) & age > 25);

Conditions against other fields

TODO