新增 kv list
This commit is contained in:
@@ -8,3 +8,12 @@ if(request.path == "put"){
|
||||
}
|
||||
}
|
||||
response.write("当前存储的数值为 " + db.get('key'))
|
||||
|
||||
var test = kv.repo("test");
|
||||
for (let i = 0; i < 500; i++) {
|
||||
test.set("key" + i,"value" + i);
|
||||
}
|
||||
var list = test.list()
|
||||
console.log(list.keys.length)
|
||||
console.log(list.cursor)
|
||||
console.log(list.hasNext)
|
||||
|
||||
@@ -27,7 +27,7 @@ func kvResult(db kv.CursorPagedKV) func(ctx core.FilterContext, jsCtx *goja.Runt
|
||||
if group == "" {
|
||||
panic("kv: invalid group name")
|
||||
}
|
||||
db := db.Child(group)
|
||||
db := db.Child(group).(kv.CursorPagedKV)
|
||||
return jsCtx.ToValue(map[string]interface{}{
|
||||
"get": func(key string) goja.Value {
|
||||
get, err := db.Get(ctx, key)
|
||||
@@ -66,6 +66,23 @@ func kvResult(db kv.CursorPagedKV) func(ctx core.FilterContext, jsCtx *goja.Runt
|
||||
}
|
||||
return swap
|
||||
},
|
||||
"list": func(limit int64, cursor string) map[string]any {
|
||||
if limit <= 0 {
|
||||
limit = 100
|
||||
}
|
||||
list, err := db.CursorList(ctx, &kv.ListOptions{
|
||||
Limit: limit,
|
||||
Cursor: cursor,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return map[string]any{
|
||||
"keys": list.Keys,
|
||||
"cursor": list.Cursor,
|
||||
"hasNext": list.HasMore,
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user