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 · PostgreSQL · all subjects

arktype

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

Install arktype integration

Install drizzle-orm@rc and arktype packages together to use Arktype schema validation with Drizzle.

createSelectSchema function

Use createSelectSchema to generate a validation schema from a Drizzle table, view, or enum that defines the shape of data queried from the database. The schema can validate API responses and will ensure all fields returned from the query match the expected shape. If a field is not included in the SELECT clause, validation will fail.

createSelectSchema with views and enums

createSelectSchema supports pgView and pgEnum. For views, it generates a schema matching the view's shape. For enums, it generates a schema that validates the enum values (e.g., 'admin' | 'basic').

createInsertSchema function

Use createInsertSchema to generate a validation schema that defines the shape of data to be inserted into the database. The schema can validate API requests. Generated from a table, it makes required fields mandatory and omits auto-generated fields like generatedAlwaysAsIdentity primary keys.

createUpdateSchema function

Use createUpdateSchema to generate a validation schema that defines the shape of data for UPDATE operations. The schema can validate API requests. All fields become optional since UPDATE may modify any subset of columns.

ArkErrors validation result type

Schema validation functions return either ArkErrors on validation failure or the validated data on success. Check if the result is an instance of ArkErrors and access error details via the summary property.

createSelectSchema example with all fields

Example showing createSelectSchema usage: when selecting all columns from a table, the schema validates that all fields match the expected types. If only some columns are selected in the query, validation will fail if those missing columns are required in the schema.

createInsertSchema example

Example showing createInsertSchema usage: the schema requires all non-auto-generated fields (age is required, id is omitted because it's generatedAlwaysAsIdentity). Passing incomplete data fails validation, but passing all required fields succeeds and can be inserted via db.insert().

createUpdateSchema example

Example showing createUpdateSchema usage: all fields are optional in the update schema, allowing partial updates. A subset of fields can be validated and passed to db.update().set().

Schema refinement example with callback and overwrite

Example showing refinements parameter: callbacks can extend schemas (e.g., schema.atMostLength(20)), while direct arktype schema values overwrite the field including nullability. The name field is extended to max 20 chars, bio is extended before applying nullability, and preferences is completely overwritten to validate a specific object shape.

Give your agent this brain