Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

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

Storage for private, distributed, offline-first applications.
Go to Latest
function queryByTemplate
import { queryByTemplate } from "https://deno.land/x/earthstar@v10.2.0/src/entries/npm.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);
 }

Parameters

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