3 ms·
jOOQ helps with both 1 and 2. With jOOQ you can write something like (totally off-the-cuff code incoming, written outside of an IDE with only basic syntax highl
by ReidZB 10y ago
jOOQ helps with both 1 and 2. With jOOQ you can write something like (totally off-the-cuff code incoming, written outside of an IDE with only basic syntax highlighting, be warned, etc)
List<Condition> conditions = new ArrayList<>();
if (notNull(lessThan)) {
conditions.add(MY_TABLE.MY_COLUMN.lt(lessThan));
}
if (notNull(greaterThan)) {
conditions.add(MY_TABLE.MY_COLUMN.gt(greaterThan));
}
if (notEmpty(name)) {
conditions.add(MY_TABLE.NAME.eq(name));
}
dslContext.selectFrom(MY_TABLE).where(conditions).fetch();
(This is obviously really contrived but I hope it illustrates the ideas)
We use constructions like this with jOOQ relatively frequently, especially for cases where we offer all sorts of arbitrary filter knobs (useful for internal tools especially).
In general, you can do some pretty fancy manipulation with `Condition` in jOOQ, like you can build a list of conditions and then call `DSL.or(conditionList)` to OR them all together. Stuff like that.
Source: use jOOQ in production code -- been very pleased so far, other than sometimes poor documentation
- louthy 10y agoI much prefer: var query = from c in db.MyTable where lessThan == null ? true : c.MyColumn < lessThan where greaterThan == null ? true : c.MyColumn > greaterThan where name == null ? true : c.Name == name select c; Although IQueryable supports your approach also: var query = db.MyTable; if (lessThan != null) query = query.Where(c => c.MyColumn < lessThan); if (greaterThan != null) query = query.Where(c => c.MyColumn > greaterThan); if (!String.IsNullOrEmpty(name)) query = query.Where(c => c.Name == name); var results = query.ToList();
- lukaseder 10y ago> other than sometimes poor documentation Thanks for your feedback. We're currently collecting API that is not documented well enough yet. Your feedback would be very welcome: https://github.com/jOOQ/jOOQ/issues/5816 https://github.com/jOOQ/jOOQ/issues/5816 Lukas