Hello,

That's a great idea! I've registered a feature request for this, to allow
for creating Conditions from Maps: https://github.com/jOOQ/jOOQ/issues/4508

In the meantime, you'll have to do so yourself:

Map<Field<Object>, Object> map = new HashMap<>();
map.put(DSL.field("a"), 1);
map.put(DSL.field("b"), 2);
map.put(DSL.field("c"), 3);

Condition condition = map
    .entrySet()
    .stream()
    .reduce(
        DSL.trueCondition(),
        (c, e) -> c.and(e.getKey().eq(e.getValue())),
        (c1, c2) -> c1.and(c2)
    );
System.out.println(condition);


This will yield

(
  1 = 1
  and a = 1
  and b = 2
  and c = 3
)



2015-09-01 23:44 GMT+02:00 siki <sikl...@gmail.com>:

> I'm trying to write a function that would take a map of fields and values
> and would return a WHERE clause or Condition from that.
>
> For example the input to the method would be a:
> Map<Field<?>, ?>
>
> and I would like to get back a Condition in the format of:
> f1.eq(v1)
> .and(f2.eq(v2))
> .and(f3.eq(v3))
> .
> .
>
>
> where f1, f2, f3, etc are the fields in the Map and v1, v2, v3, etc are
> the corresponding values.
>
> I've been using JOOQ for a while for basic things but don't know the API
> enough to come up with a solution for this. Thanks for your help in advance!
>
> --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jooq-user+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jooq-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to