新增 kv list

This commit is contained in:
ExplodingDragon
2025-11-18 00:45:44 +08:00
parent 562413b3bf
commit f4ca1377ca
2 changed files with 27 additions and 1 deletions

View File

@@ -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)

View File

@@ -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,
}
},
})
}
}