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, CompareOp: t.operator,
"true false": t.bool, "true false": t.bool,
Comment: t.lineComment, 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, t.keyword,
}); });

View File

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