Javascript 使用“in”操作符筛选persistence.js

Javascript 使用“in”操作符筛选persistence.js,javascript,persistence,Javascript,Persistence,我在persistence.js中返回的查询集合上使用filter方法时遇到了一些有趣的行为 以下是我在调试器中运行的一些示例代码: Bookmark.all().list(function(items){items.forEach(function(item){console.log(item.id)})}) undefined SELECT `root`.id AS bookmarks_shs_id, `root`.`name` AS `bookmarks_shs_name`, `root`

我在persistence.js中返回的查询集合上使用filter方法时遇到了一些有趣的行为

以下是我在调试器中运行的一些示例代码:

Bookmark.all().list(function(items){items.forEach(function(item){console.log(item.id)})})
undefined
SELECT `root`.id AS bookmarks_shs_id, `root`.`name` AS `bookmarks_shs_name`, `root`.`url` AS `bookmarks_shs_url` FROM `bookmarks_shs` AS `root`  WHERE 1=1 []
0
1
2
显然,数据库中保存了三个书签对象,每个对象的id分别为0、1和2

但是,当我尝试使用操作符过滤对象时,在中。它开始返回一些古怪的结果

Bookmark.all().filter('id','in',[0,1,2]).list(function(items){items.forEach(function(item){console.log(item.id)})})
undefined
SELECT `root`.id AS bookmarks_shs_id, `root`.`name` AS `bookmarks_shs_name`, `root`.`url` AS `bookmarks_shs_url` FROM `bookmarks_shs` AS `root`  WHERE (1=1 AND `root`.`id` IN (?, ?, ?)) [0, 1, 2]
这个查询的结果是空的,过滤器本身没有返回任何内容,考虑到我刚刚确认数据库中肯定有与这些参数匹配的对象,这有点奇怪。我还尝试了一个简单的平等测试

Bookmark.all().filter('id','=',0).list(function(items){items.forEach(function(item){console.log(item.id)})})
undefined
SELECT `root`.id AS bookmarks_shs_id, `root`.`name` AS `bookmarks_shs_name`, `root`.`url` AS `bookmarks_shs_url` FROM `bookmarks_shs` AS `root`  WHERE (1=1 AND `root`.`id` = ?) [0]
同样,没有命中。也许最奇怪的是,如果我运行以下命令:

Bookmark.all().filter('id','<',2).list(function(items){items.forEach(function(item){console.log(item.id)})})
undefined
SELECT `root`.id AS bookmarks_shs_id, `root`.`name` AS `bookmarks_shs_name`, `root`.`url` AS `bookmarks_shs_url` FROM `bookmarks_shs` AS `root`  WHERE (1=1 AND `root`.`id` < ?) [2]
0
1
2
但2绝对不小于2。我做错什么了吗?过滤器函数不这样工作似乎有点奇怪,尤其是当它输出适当的SQL查询时

更新
看起来这是@nrabinowitz解决方案的组合。我做了一些挖掘,发现persistence.js的源代码中声明的默认idType是VARCHAR32。这就解释了不希望出现的行为。

您确定您的ID是整数而不是字符串吗?如果它存储的是字符串ID,但与整数进行比较,这可能解释了其中的一些行为。这是我最初的想法,但显然它们存储为字符串。知道如何在persistence.js中更改此默认行为吗?如果我尝试在数组中用引号括起数字,它会在计算查询之前去掉引号