Skip to main content
Module

x/earthstar/src/entries/universal.ts>queryByTemplate

Storage for private, distributed, offline-first applications.
Go to Latest
function queryByTemplate
import { queryByTemplate } from "https://deno.land/x/earthstar@v10.0.2/src/entries/universal.ts";

Given a template string like "/posts/{postId}.json", query the replica for docs with matching paths.

See the docs for matchTemplateAndPath for details on template strings.

You can get the variables out of your document paths like this:

 let template = '/posts/{postId}.json';
 let docs = await queryByTemplate(myReplica, template);
 for (let doc of docs) {
     // vars will be like { postId: 'abc' }
     let vars = extractTemplateVariablesFromPath(template, doc.path);
 }

Type Parameters

optional
F = DefaultFormats

Parameters

replica: Replica
template: string
optional
moreQueryOptions: Omit<Query<[string]>, "formats"> = [UNSUPPORTED]
optional
formats: FormatsArg<F>

Returns

Promise<FormatDocType<F>[]>