Interface: Collection
Defined in: query.ts:24
One collection's documents. Everything is built ahead of time, so reads are synchronous.
Example
const posts = collections.get("posts");
posts.documents().filter((post) => post.metadata.tags.includes("vite"));
posts.get("hello-world").metadata.title;
posts.slugs(); // ["hello-world", "setup"]Methods
documents()
documents(this: void): readonly TDocument[];Defined in: query.ts:30
Every document, in the order its loader returned them, eg file name order for directory. Sort, filter and slice it like any array.
get()
get(this: void, slug: TKnownSlug): TDocument;Defined in: query.ts:43
The document with this slug. A slug that exists returns its document.
posts.get("hello-world").metadata.title;get(this: void, slug: string): TDocument | undefined;Defined in: query.ts:54
The document with this slug, or undefined if there is none, eg for a route param.
const post = posts.get(params.slug);
if (!post) throw notFound();has()
has(this: void, slug: string): slug is TSlug;Defined in: query.ts:65
Whether a document has this slug. Narrows a route param to the collection's slugs, so get then returns the document.
if (posts.has(params.slug)) posts.get(params.slug).metadata.title;slugs()
slugs(this: void): readonly TSlug[];Defined in: query.ts:67
Every slug, in the same order as documents().