How can I use date function in query builder?

query

#1

Hi, I’m using couchbase lite 2.0 for android, and I would like to query the database with n1ql queries.
That is possible in query editor like below.

But, how should I do in android query builder?
At the moment I don’t see that possibility, below query is not working.

Query query = QueryBuilder
.select(
SelectResult.property(“WEEKDAY_STR(REG_DATE)”).as(“Day”),
SelectResult.expression(Function.sum(Expression.property(“TOTAL_AMOUNT”))).as(“TOT_AMOUNT”)
)
.from(DataSource.database(database))
.where(Expression.property(“type”).equalTo(Expression.string(“SALE”))
.groupBy(Expression.property(“WEEKDAY_STR(REG_DATE)”));


#2

We haven’t implemented the N1QL date functions yet.

(Couchbase Lite only implements a subset of N1QL; the docs should specify which functions are supported.)

Since your query is embedded in an app, you can use native code to post process the results and extract the info you need.


#3

Thanks for your reply.
Then, how can I use native code in an app?
Please show me more details.


#4

By “native code” I just mean the language the app is written in — Swift, Java, C#, Obj-C. Use your platform’s date library to get the weekday from the date.