Skip to main content

Class: SchemaDefinition<Schema, StrictTableTypes>

For AI agents: see llms.txt for the complete documentation index. Markdown versions are available by adding .md to a page URL or requesting Accept: text/markdown.

server.SchemaDefinition

The definition of a Convex project schema.

This should be produced by using defineSchema.

Type parameters

NameType
Schemaextends GenericSchema
StrictTableTypesextends boolean

Properties

tables

tables: Schema

Defined in

server/schema.ts:820


strictTableNameTypes

strictTableNameTypes: StrictTableTypes

Defined in

server/schema.ts:821


schemaValidation

Readonly schemaValidation: boolean

Defined in

server/schema.ts:822

Methods

doc

doc<TableName>(tableName): DocValidator<TableName, Schema[TableName]["validator"]>

The validator for whole documents of a table in this schema: the table's own validator with the _id and _creationTime system fields added.

Example

export const get = query({
args: { id: schema.id("messages") },
returns: v.union(schema.doc("messages"), v.null()),
handler: (ctx, args) => ctx.db.get(args.id),
});

Type parameters

NameType
TableNameextends string

Parameters

NameTypeDescription
tableNameTableNameThe name of a table in this schema.

Returns

DocValidator<TableName, Schema[TableName]["validator"]>

A validator matching documents of that table.

Defined in

server/schema.ts:849


id

id<TableName>(tableName): VId<GenericId<TableName>, "required">

The validator for IDs of a table in this schema.

Same as v.id(tableName), but only accepts tables in this schema.

Type parameters

NameType
TableNameextends string

Parameters

NameTypeDescription
tableNameTableNameThe name of a table in this schema.

Returns

VId<GenericId<TableName>, "required">

A validator matching IDs of that table.

Defined in

server/schema.ts:863