WHEN, IN, FOR with n1ql expressions

hi,

i need to execute the following query:

update bucket1 use keys “abc123” set version.description=“blabla” for version IN versions WHEN version.status=“ACTIVE” END returning versions;

through my code i use n1ql with the expression language.
are WHEN, In, FOR etc available through the expression language the same way UPDATE, USE KEYS, SET etc. are? if yes, could someone give me a hint on how the entire query above can be build, starting with

N1qlQuery.simple( Update.update( i( “bucket1” ) ).useKeys( s(“abc123” ) ).set( x( “version.description” ), s( “blabla” ) ) )…

thanks!

looks like we’re missing this operator in the DSL…
@daschl I wonder at what level we could integrate that… Looks to me the whole “expression = value FOR … IN … WHEN … END” is the expression in the “set”?

Yes, I think so indeed.

@atarno note that worst case scenario you can provide the whole N1QL statement in String format if the DSL is lacking (but not without telling us what the DSL is missing of course :slight_smile: )

it turns out the DSL is halfway there. For now you can provide an “updateFor” Expression when you call the set in the DSL, but that leaves you to write the whole FOR…IN…WHEN clause yourself:

Statement statement = Update
            .update(i("bucket1"))
            .useKeysValues("abc123")
            .set(x("version.description"), s("blabla"), 
                x("FOR version IN versions WHEN version.status = \"ACTIVE\" END")
            .returning("versions");

I’ve opened a ticket to provide a helper in order to write that Expression. It would become (after importing static method forIn from the helper):

Statement statement = Update
            .update(i("bucket1"))
            .useKeysValues("abc123")
            .set(x("version.description"), s("blabla"), forIn("version", "versions").when(x("version.status").eq(s("ACTIVE"))))
            .returning("versions");

Ticket number is JCBC-925

@atarno this will be part of the API in 2.2.6 next month :wink: