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 parsedQuery
|
||||||
* @param variables
|
* @param variables
|
||||||
* @returns Promise<any[] | string>: a string if the query has a `render` clause, or an array of results
|
* @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
|
path: api.ts:query
|
||||||
renderQuery:
|
renderQuery:
|
||||||
path: api.ts:renderQuery
|
path: api.ts:renderQuery
|
||||||
|
env: server
|
||||||
|
|
||||||
queryWidget:
|
queryWidget:
|
||||||
path: widget.ts:widget
|
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 { loadPageObject, replaceTemplateVars } from "../template/page.ts";
|
||||||
import type { CodeWidgetContent } from "../../plug-api/types.ts";
|
import type { CodeWidgetContent } from "../../plug-api/types.ts";
|
||||||
import { jsonToMDTable } from "../template/util.ts";
|
import { jsonToMDTable } from "../template/util.ts";
|
||||||
import { renderQuery } from "./api.ts";
|
|
||||||
import type { ChangeSpec } from "@codemirror/state";
|
import type { ChangeSpec } from "@codemirror/state";
|
||||||
import {
|
import {
|
||||||
findNodeMatching,
|
findNodeMatching,
|
||||||
|
@ -36,10 +35,14 @@ export async function widget(
|
||||||
await replaceTemplateVars(bodyText, pageObject, config),
|
await replaceTemplateVars(bodyText, pageObject, config),
|
||||||
);
|
);
|
||||||
|
|
||||||
const results = await renderQuery(parsedQuery, {
|
const results = await system.invokeFunction(
|
||||||
page: pageObject,
|
"query.renderQuery",
|
||||||
config,
|
parsedQuery,
|
||||||
});
|
{
|
||||||
|
page: pageObject,
|
||||||
|
config,
|
||||||
|
},
|
||||||
|
);
|
||||||
if (Array.isArray(results)) {
|
if (Array.isArray(results)) {
|
||||||
resultMarkdown = jsonToMDTable(results);
|
resultMarkdown = jsonToMDTable(results);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue