我是否可以在运行时从条件数组中快速创建Couchbase Lite中的Where子句?

问题描述 投票:0回答:1

我正在使用Couchbase Lite 2.6,我想在运行时构建查询,我通过API接收条件列表([“ Key”:“ value”]),使用该API我需要过滤本地数据库并显示值。

有什么办法可以使用QueryBuilder?

我在Couchbase论坛上找到了类似的讨论,但是它已经很老了,因此该解决方案不再有效。

https://forums.couchbase.com/t/filter-on-array-filed-in-couchbase-and-couchbase-lite/3983/4

swift where-clause query-builder couchbase-lite n1ql
1个回答
0
投票
String name = "foo"; String surname = "bar"; Expression ex = Expression.property("type").equalTo(Expression.string("user")); if(name != null) { ex.and(Expression.property("name").equalTo(Expression.string(name))); } if(surname != null) { ex.and(Expression.property("surname").equalTo(Expression.string(surname))); } Query query = QueryBuilder .select(SelectResult.all()) .from(DataSource.database(DatabaseManager.getDatabase())) .where(ex) .limit(Expression.intValue(10));
© www.soinside.com 2019 - 2024. All rights reserved.