@Permission("RocksDB") @Description("这是个使用RocksDB的参考代码") contract RocksDBSample{ function onCreate(){ Global.rocksdb = RocksDBUtil.loadDB("./dbdir/","false"); } @Description("示例参数: {\"key\":\"abc\",\"value\":\"def\"}") export function put(arg){ arg = JSON.parse(arg); Global.rocksdb.put(arg.key,arg.value); return "success"; } @Description("示例参数: \"abc\"}") export function get(arg){ return Global.rocksdb.get(arg); return "failed"; } @Description("示例参数: \"abc\"") export function deleteKey(arg){ return Global.rocksdb.delete(arg); } @Description("遍历KV库,无需参数") export function iter(arg){ var iter = Global.rocksdb.newIterator(); var obj = undefined; var ret = { }; for (iter.seekToFirst();(obj=Global.rocksdb.getNext(iter))!=undefined;){ ret[obj.key]=obj.value; } return JSON.stringify(ret) } }