在为 IndexedDB 使用 YDN-DB 包装器构建离线应用程序时,我现在需要查询任何对象存储以获取存储中的最高Integer
主键值。通过扩展,我可以预测并使用下一个 autoIncrement 数字,甚至在运行下一个INSERT
. 目前我可以想到以下方法:
db.values('store_name').done(function (recordset) {
//run through the key/value pairs in recordset until I arrive at the
highest value.
});
也许:
db.from('store_name').select('primary_key').order('primary_key', true).list(1)
.done(function(value) {
//use value for some task;
});
有没有更有效的方法?虽然我们在上面,但 中"primary_key"
指定的参数.order('primary_key', true)
对我来说似乎是多余的,因为这种排序通常是按主键。如果这是正确的,跳过它的语法是什么?
谢谢。
编辑:
在等待的过程中,我意识到,事实上,查询引擎完全忽略了 (==reverse).order('primary_key', true)
的第二个参数。true
但下面的表格来拯救:
db.from('store_name').select('primary_key').reverse().list(1)
.done(function(highest){
console.log(highest);
});
虽然这似乎有点时尚,但我仍然渴望得到“教授”的认可。
谢谢你。