Render queries on the server
parent
67f997258d
commit
46f94a9881
|
@ -15,7 +15,8 @@ export async function query(
|
|||
}
|
||||
|
||||
/**
|
||||
* Renders a query either as a result array, or as a rendered template when the `render` clause is defined
|
||||
* Renders a query either as a result array, or as a rendered template when the `render` clause is defined.
|
||||
* Runs on the server side (except in sync mode)
|
||||
* @param parsedQuery
|
||||
* @param variables
|
||||
* @returns Promise<any[] | string>: a string if the query has a `render` clause, or an array of results
|
||||
|
|
|
@ -7,6 +7,7 @@ functions:
|
|||
path: api.ts:query
|
||||
renderQuery:
|
||||
path: api.ts:renderQuery
|
||||
env: server
|
||||
|
||||
queryWidget:
|
||||
path: widget.ts:widget
|
||||
|
|
|
@ -17,7 +17,6 @@ import { parseQuery } from "../../plug-api/lib/parse_query.ts";
|
|||
import { loadPageObject, replaceTemplateVars } from "../template/page.ts";
|
||||
import type { CodeWidgetContent } from "../../plug-api/types.ts";
|
||||
import { jsonToMDTable } from "../template/util.ts";
|
||||
import { renderQuery } from "./api.ts";
|
||||
import type { ChangeSpec } from "@codemirror/state";
|
||||
import {
|
||||
findNodeMatching,
|
||||
|
@ -36,10 +35,14 @@ export async function widget(
|
|||
await replaceTemplateVars(bodyText, pageObject, config),
|
||||
);
|
||||
|
||||
const results = await renderQuery(parsedQuery, {
|
||||
page: pageObject,
|
||||
config,
|
||||
});
|
||||
const results = await system.invokeFunction(
|
||||
"query.renderQuery",
|
||||
parsedQuery,
|
||||
{
|
||||
page: pageObject,
|
||||
config,
|
||||
},
|
||||
);
|
||||
if (Array.isArray(results)) {
|
||||
resultMarkdown = jsonToMDTable(results);
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue