Couchbase lite query from N1QL

I find QueryBuilder to be QUITE verbose and cumbersome.

I would MUCH prefer to supply my own prepared N1QL statement for the many queries I need to execute, e.g. something along the lines of:

val query = Query.fromN1ql("SELECT COUNT(*) as total FROM bucket WHERE type=\"user\")

Is there a way to generate a Query from a N1QL string? Or to execute a raw N1QL statement without wrapping it in a Query? If not, are there plans to add this?

You can’t do that via this the QueryBuilder interface today on Couchbase Lite.
The good news is that this is one our radar and we have plans to support that - we don’t have a specific timeframe that we can share at this time. So for your current needs, you will have to use the QueryBuilder interface. When we do support the N1QL query API, you should be able to leverage that for your future queries and apps.

Curious - what platform are you on?

Thanks for the update. I look forward to it. I’m developing an Android app via Android Studio on Windows 10.

In the mean time, I’ve created a utility class CB that acts as a simple adapter, to help shorten all those verbose method calls and chains for the most common query patterns.

e.g.:

CB.count()

returns/replaces:

SelectResult.expression(Function.count(Expression.string("*"))),

etc.

1 Like