Skip to Content
DocsConceptsCollections

Collections

A collection is a set of documents with the same fields. Define one with defineCollection.

import { defineCollection, fields as f } from "@quickben/core"; export const posts = defineCollection({ slug: "posts", labels: { singular: "Post", plural: "Posts" }, fields: { title: f.text({ required: true, maxLength: 200 }), status: f.select({ options: ["draft", "published"], required: true, default: "draft" }), publishedAt: f.datetime(), }, access: { read: () => true }, hooks: { beforeChange: [({ data }) => data] }, admin: { useAsTitle: "title", defaultColumns: ["title", "status", "publishedAt"] }, });

Options

OptionPurpose
slugIdentifier used in the API, URLs and table names.
labels{ singular, plural }. Default: humanized slug (blog-posts → Blog posts).
fieldsField definitions keyed by name. See Fields.
accessRules per operation. See Access control.
hooksFunctions per stage. See Hooks.
adminAdmin UI options (below).

Naming rules

ItemAllowed
SlugLowercase letters, digits, -, _. Starts with a letter. Up to 63 characters.
Field nameLetters, digits, _. Starts with a letter.
Reservedid, createdAt, updatedAt, and, or

System fields

Every document has these fields. You do not declare them.

FieldValue
idString. UUIDv7 unless you pass an id on create.
createdAtISO 8601 UTC string
updatedAtISO 8601 UTC string

Admin options

OptionPurpose
useAsTitleField shown as the document title. Default id.
defaultColumnsColumns of the list view.
groupSidebar group label.
hiddenHide the collection from the admin UI.
descriptionText shown under the collection title.

Types

TypeShape
InferDoc<typeof posts>System fields plus every field.
InferCreateInput<…>Required fields without a default are required. id is optional.
InferUpdateInput<…>Every field optional. Only non-required fields accept null.
InferWhere<…>Filter with operators per field type.
InferSort<…>"field", "-field" or an array of them.
import type { InferCreateInput, InferDoc } from "@quickben/core"; import { posts } from "./collections"; type Post = InferDoc<typeof posts>; type NewPost = InferCreateInput<typeof posts>; const input: NewPost = { title: "Hello" };
Last updated on