new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Drizzle ORM · all subjects

arktype/refinements

7 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Schema refinements with arktype schema overwrites

Each create schema function accepts an optional second parameter for refinements. Providing an arktype schema object directly overwrites the field's schema entirely, including its nullability and optionality.

Schema refinements with callbacks extend validation

Each create schema function (createSelectSchema, createInsertSchema, createUpdateSchema) accepts an optional refinements parameter. Defining a callback function for a field will extend or modify that field's schema validation.

Schema refinements with arktype types overwrite field schema

When providing an arktype schema directly (not a callback) in the refinements parameter, it completely overwrites the field's schema including its nullability and optionality.

Refinements callback example with atMostLength

A refinement callback can chain methods on the schema. For example, `name: (schema) => schema.atMostLength(20)` extends the name field schema to enforce a maximum length of 20 characters.

Refinements can modify nullability before extending

When using a callback refinement, the bio field example shows that `bio: () => type.string.atMostLength(2000)` extends the schema before it becomes nullable or optional, allowing you to add constraints to the base type before nullability is applied.

Full createUpdateSchema example with refinements

Example: import { int, mssqlTable, text } from 'drizzle-orm/mssql-core'; import { createSelectSchema } from 'drizzle-orm/arktype'; import { ArkErrors, type } from 'arktype'; const users = mssqlTable('users', { id: int().primaryKey().identity(), name: text().notNull(), bio: text(), preferences: text() }); const userSelectSchema = createSelectSchema(users, { name: (schema) => schema.atMostLength(20), bio: () => type.string.atMostLength(2000), preferences: type({ theme: 'string' }) }); const parsed: ArkErrors | { id: number; name: string, bio: string | null; preferences: { theme: string; }; } = userSelectSchema(...);

Schema refinements with callbacks and overwrite

Each create schema function (createSelectSchema, createInsertSchema, createUpdateSchema) accepts an optional second parameter for refining field schemas. Passing a callback function extends or modifies the generated schema. Providing an arktype schema directly overwrites the field schema completely, including its nullability.

Give your agent this brain