lua-query
Zef Hemel 2025-01-10 17:32:39 +01:00
parent 3e9b5f4565
commit 1640d32889
2 changed files with 13 additions and 6 deletions

View File

@ -32,7 +32,7 @@ const luaStyleTags = styleTags({
CompareOp: t.operator,
"true false": t.bool,
Comment: t.lineComment,
"return break goto do end while repeat until function local if then else elseif in for nil or and not query where limit select order":
"return break goto do end while repeat until function local if then else elseif in for nil or and not query where limit select order by desc":
t.keyword,
});

View File

@ -20,6 +20,7 @@ import type {
LuaCollectionQuery,
LuaQueryCollection,
} from "$common/space_lua/query_collection.ts";
import { KV } from "@silverbulletmd/silverbullet/types";
const printFunction = new LuaBuiltinFunction(async (_sf, ...args) => {
console.log("[Lua]", ...(await Promise.all(args)));
@ -134,11 +135,17 @@ const tagFunction = new LuaBuiltinFunction(
throw new LuaRuntimeError("Global not found", sf);
}
return {
query: (query: LuaCollectionQuery): any => {
return global.get("datastore").get("query_lua").call(sf, [
"idx",
tagName,
], query);
query: async (query: LuaCollectionQuery): Promise<any[]> => {
const kvs: KV[] = (await global.get("datastore").get("query_lua").call(
sf,
[
"idx",
tagName,
],
query,
)).asJSArray();
console.log("Got kvs", kvs);
return kvs.map((kv) => kv.value);
},
};
},