2

从这里使用打包的 ydn-db 库:http: //git.yathit.com/ydn-db/downloads/ydn.db-jquery-0.7.12.js。https://storage.cloud.google.com/download.yathit.com/ydn-db/build/zsk-ydn.db-dev-0.7.15.js也是如此

var db = new ydn.db.Storage("mydb");
var clog = function(r) { console.log(r); }

db.put({name: "store1", keyPath: "id"}, {id: "id1", value: "value1"});
db.put({name: "store1", keyPath: "id"}, {id: "id2", value: "value2"});

db.get("store1", "id1").done(clog); // works fine

// Example as mentioned in the docs here: http://dev.yathit.com/ydn-db/getting-started.html
var reverse = false, limit = 10;
db.values(new ydn.db.Cursors("store1", "id", null, reverse), limit).done(clog)
// TypeError: Cannot call method 'getName' of null

// Also adapted from docs:
db.values(ydn.db.IndexValueCursors.where("store1", "id", "=", "id1")).done(clog)
// TypeError: Cannot call method 'getName' of null

// Also adapted from docs:
var iter = new ydn.db.ValueCursors("store1", ydn.db.KeyRange.starts("a"))
db.open(iter, clog, "readwrite")
// ydn.error.ArgumentException: Second argument must be cursor range iterator.

打包库的功能似乎与文档不一致。有小费吗?

4

2 回答 2

1

好的,终于从上一个答案的链接中得到它:

// Equivalent to: SELECT * FROM store1 where value = 'value1':
var keyRange = ydn.db.KeyRange.only("value1");
var cursor = new ydn.db.IndexValueCursors("store1", "value", keyRange);
db.get(cursor, keyRange).then(function(record) {
   console.log("record:", record);
}, function(err) {
   throw err;
});
于 2013-09-11T01:45:54.210 回答
1

实际上,您的架构没有索引名称id,因此正确的代码应如下所示。

var db = new ydn.db.Storage("mydb");
var clog = function(r) { console.log(r); }

db.put({name: "store1", keyPath: "id"}, {id: "id1", value: "value1"});
db.put({name: "store1", keyPath: "id"}, {id: "id2", value: "value2"});

db.get("store1", "id1").done(clog); // works fine


 // Example as mentioned in the docs here: http://dev.yathit.com/ydn-db/getting-started.html
var reverse = false, limit = 10;
db.values(new ydn.db.KeyCursors("store1", null, reverse), limit).done(clog)
// TypeError: Cannot call method 'getName' of null

// Also adapted from docs:
db.values(ydn.db.ValueCursors.where("store1",  "=", "id1")).done(clog)
// TypeError: Cannot call method 'getName' of null

// Also adapted from docs:
var iter = new ydn.db.ValueCursors("store1", ydn.db.KeyRange.starts("i"))
var pnt = function(r) {console.log(r.getValue())}
db.open(pnt, iter, "readwrite")

错误消息绝对不是信息。我推送了一个补丁,所以下一次,它给出了 index not found 错误。

open 方法中也有 api 更改。文档需要更新。

编辑:更复杂的查询可以在http://dev.yathit.com/ydn-db/nosql-query.html找到

于 2013-09-09T05:01:19.507 回答