admin管理员组文章数量:1334659
I'm using DexieJS to fetch data from an IndexedDB. I've done the following tests both with v. 1.1.0 and 1.2.0.
It is working great for simple queries, but unfortunately I am unable to chain multiple where clauses.
First, I've tried this
var collection = db[table];
collection = collection.where('Field').equals("1");
return collection.count();
And that was working. Then, I need to add a where clause, but only if a given value is set:
var collection = db[table];
collection = collection.where('Field').equals("1");
if(value) collection = collection.where('Field2').above(value);
return collection.count();
This one fails. For test purposes, I've also tried:
var collection = db[table];
collection = collection.where('Field').equals("1")
.and('Field2').above(value);
return collection.count();
var collection = db[table];
collection = collection.where('Field').equals("1")
.and().where('Field2').above(value);
return collection.count();
var collection = db[table];
collection = collection.where('Field').equals("1")
.where('Field2').above(value);
return collection.count();
None of these work. I'm starting to think that this is not possible at all, but since the method and()
exists, there must be a way!
PS this works:
var collection = db[table];
collection = collection.where('Field2').above(value);
return collection.count();
I'm using DexieJS to fetch data from an IndexedDB. I've done the following tests both with v. 1.1.0 and 1.2.0.
It is working great for simple queries, but unfortunately I am unable to chain multiple where clauses.
First, I've tried this
var collection = db[table];
collection = collection.where('Field').equals("1");
return collection.count();
And that was working. Then, I need to add a where clause, but only if a given value is set:
var collection = db[table];
collection = collection.where('Field').equals("1");
if(value) collection = collection.where('Field2').above(value);
return collection.count();
This one fails. For test purposes, I've also tried:
var collection = db[table];
collection = collection.where('Field').equals("1")
.and('Field2').above(value);
return collection.count();
var collection = db[table];
collection = collection.where('Field').equals("1")
.and().where('Field2').above(value);
return collection.count();
var collection = db[table];
collection = collection.where('Field').equals("1")
.where('Field2').above(value);
return collection.count();
None of these work. I'm starting to think that this is not possible at all, but since the method and()
exists, there must be a way!
PS this works:
var collection = db[table];
collection = collection.where('Field2').above(value);
return collection.count();
Share
Improve this question
edited Feb 28, 2016 at 7:10
don
asked Feb 28, 2016 at 6:37
dondon
4,54214 gold badges48 silver badges73 bronze badges
1 Answer
Reset to default 8DexieJS' AND
operator is implemented either as a filter function or a pound index. The simple way to implement your query is to use the filter method, something like;
var collection = db[table];
collection = collection
.where('Field').equals("1")
.and(function(item) { return item.Field2 > value });
return collection.count();
This means that the first filter will run against IndexedDB, and the additional condition will be run against each found item by DexieJS, which may or may not be good enough for what you need.
As to how to use the pound index, it's a bit harder to apply to your exact situation without more details on the collections and exact queries you want, but there is much more information available here.
本文标签: javascriptDexieJS (indexedDB) chain multiple where clausesStack Overflow
版权声明:本文标题:javascript - DexieJS (indexedDB) chain multiple .where clauses - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742378700a2463679.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论