defineSchema
Call Signature
Section titled “Call Signature”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" }.
Type Parameters
Section titled “Type Parameters”C extends Columns
Parameters
Section titled “Parameters”string
The name entities are tagged with — a str, so at most 128 bytes. Optional.
columns
Section titled “columns”C
The columns, keyed by attribute name.
Returns
Section titled “Returns”Schema<C>
Throws
Section titled “Throws”If a name violates the attribute-name grammar.
Throws
Section titled “Throws”If the name is not a valid str, an entry is not a column, or a
column is named after the schema tag.
Throws
Section titled “Throws”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.
Example
Section titled “Example”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})Call Signature
Section titled “Call Signature”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" }.
Type Parameters
Section titled “Type Parameters”C extends Columns
Parameters
Section titled “Parameters”columns
Section titled “columns”C
The columns, keyed by attribute name.
Returns
Section titled “Returns”Schema<C>
Throws
Section titled “Throws”If a name violates the attribute-name grammar.
Throws
Section titled “Throws”If the name is not a valid str, an entry is not a column, or a
column is named after the schema tag.
Throws
Section titled “Throws”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.
Example
Section titled “Example”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})