Skip to content

defineSchema<C>(name, columns): Schema<C>

Defined in: src/schema/schema.ts:96

Declares a schema: the attributes an entity carries, their types, and which of them are indexed.

Each column is a type constructor called with no arguments — str(), dec(), bytes() — refined with .indexed(), .optional() or .default(...). Only indexed columns can be filtered on; the rest are stored and selectable, and do not pay for an index.

Give the schema a name to tag its entities: every create then also writes an indexed arkiv.schema attribute holding the name, and .from(schema) filters on it — the way a collection keeps one model’s documents apart from another’s. Without a name, a query through the schema sees every entity its where matches, whatever wrote it — though the columns it selects are still checked against the schema, so an entity that does not fit is left out of the page, or fails the query with { onMismatch: "throw" }.

C extends Columns

string

The name entities are tagged with — a str, so at most 128 bytes. Optional.

C

The columns, keyed by attribute name.

Schema<C>

If a name violates the attribute-name grammar.

If the name is not a valid str, an entry is not a column, or a column is named after the schema tag.

If there are more columns than one create can carry — at most MAX_ATTRIBUTES, or one fewer for a named schema, whose tag counts as an attribute.

import { addr, bytes, dec, defineSchema, str } from "@arkiv-network/sdk/schema"
const Posts = defineSchema("posts", {
author: addr().indexed(),
category: str().indexed(),
score: dec().indexed(),
title: str(), // stored, not indexed
body: bytes(), // a blob; bytes can never be indexed
thumbnail: bytes().optional(), // bytes columns share one MAX_ENTITY_BYTES budget
mimeType: str().default("text/markdown"), // written on create when left out
})

defineSchema<C>(columns): Schema<C>

Defined in: src/schema/schema.ts:97

Declares a schema: the attributes an entity carries, their types, and which of them are indexed.

Each column is a type constructor called with no arguments — str(), dec(), bytes() — refined with .indexed(), .optional() or .default(...). Only indexed columns can be filtered on; the rest are stored and selectable, and do not pay for an index.

Give the schema a name to tag its entities: every create then also writes an indexed arkiv.schema attribute holding the name, and .from(schema) filters on it — the way a collection keeps one model’s documents apart from another’s. Without a name, a query through the schema sees every entity its where matches, whatever wrote it — though the columns it selects are still checked against the schema, so an entity that does not fit is left out of the page, or fails the query with { onMismatch: "throw" }.

C extends Columns

C

The columns, keyed by attribute name.

Schema<C>

If a name violates the attribute-name grammar.

If the name is not a valid str, an entry is not a column, or a column is named after the schema tag.

If there are more columns than one create can carry — at most MAX_ATTRIBUTES, or one fewer for a named schema, whose tag counts as an attribute.

import { addr, bytes, dec, defineSchema, str } from "@arkiv-network/sdk/schema"
const Posts = defineSchema("posts", {
author: addr().indexed(),
category: str().indexed(),
score: dec().indexed(),
title: str(), // stored, not indexed
body: bytes(), // a blob; bytes can never be indexed
thumbnail: bytes().optional(), // bytes columns share one MAX_ENTITY_BYTES budget
mimeType: str().default("text/markdown"), // written on create when left out
})