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

valibot

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

Valibot data type mapping for SQLite text and numeric strings

SQLite numeric() column or text column with mode 'text' maps to Valibot string() schema.

createSelectSchema function for Valibot

The createSelectSchema function from drizzle-orm/valibot generates a validation schema that defines the shape of data queried from the database. It can be used to validate API responses. The schema enforces that all columns defined in the table must be present in the query result.

createInsertSchema function for Valibot

The createInsertSchema function from drizzle-orm/valibot generates a validation schema that defines the shape of data to be inserted into the database. It can be used to validate API requests. Columns with autoIncrement are optional in insert schemas since they are auto-generated.

createUpdateSchema function for Valibot

The createUpdateSchema function from drizzle-orm/valibot generates a validation schema that defines the shape of data to be updated in the database. It can be used to validate API requests. All fields become optional in update schemas since updates do not require every column to be modified.

Valibot schema refinements with callbacks and overwrites

Each create schema function (createSelectSchema, createInsertSchema, createUpdateSchema) accepts an optional second parameter for refinements. Providing a callback function will extend or modify a field's schema. Providing a Valibot schema object will overwrite the field entirely, including its nullability. Use pipe() to chain refinements onto existing schemas.

Valibot data type mapping for SQLite integer boolean

SQLite integer column with mode 'boolean' maps to Valibot boolean() schema.

Valibot data type mapping for SQLite integer timestamp

SQLite integer column with mode 'timestamp' or mode 'timestamp_ms' maps to Valibot date() schema.

Valibot data type mapping for SQLite text with length constraint

SQLite text() column with mode 'text' and a length parameter maps to Valibot pipe(string(), maxLength(length)) schema.

Valibot data type mapping for SQLite text with enum

SQLite text() column with mode 'text' and an enum parameter maps to Valibot enum(enum) schema.

Valibot data type mapping for SQLite real

SQLite real() column maps to Valibot pipe(number(), minValue(-140_737_488_355_328), maxValue(140_737_488_355_327)) schema, constraining to 48-bit integer limits.

Valibot data type mapping for SQLite integer number mode

SQLite integer() column with mode 'number' maps to Valibot pipe(number(), minValue(-9_007_199_254_740_991), maxValue(9_007_199_254_740_991), integer()) schema, constraining to JavaScript safe integer limits.

Valibot data type mapping for SQLite blob bigint mode

SQLite blob() column with mode 'bigint' maps to Valibot pipe(bigint(), minValue(-9_223_372_036_854_775_808n), maxValue(9_223_372_036_854_775_807n)) schema, constraining to 64-bit integer limits.

Valibot data type mapping for SQLite JSON

SQLite blob() column with mode 'json' or text() column with mode 'json' maps to Valibot union([union([string(), number(), boolean(), null_()]), array(any()), record(string(), any())]) schema, allowing any JSON-serializable value.

Valibot data type mapping for SQLite blob buffer mode

SQLite blob() column with mode 'buffer' maps to Valibot custom<Buffer>((v) => v instanceof Buffer) schema.

Valibot schema generation for SQLite views

The createSelectSchema function can be used with SQLite views created using sqliteView(). Views are treated the same as tables for schema generation purposes.

Install Valibot with Drizzle

To use Valibot with Drizzle, install drizzle-orm@rc and valibot packages.

Example createSelectSchema with Valibot validation error

When using createSelectSchema with Valibot, if a SELECT query does not return all columns defined in the table, parsing with the schema will fail. For example, selecting only id and name from a users table with id, name, and age will cause a validation error because age is missing from the result.

Example createInsertSchema requiring all non-autoincrement columns

When using createInsertSchema with Valibot, all non-autoincrement columns that are notNull must be provided. For example, inserting only the name field into a users table with id (autoIncrement), name (notNull), and age (notNull) will fail validation. Both name and age must be provided.

Example createUpdateSchema with all fields optional

When using createUpdateSchema with Valibot, all fields become optional. For example, updating only the age field in a users table is valid, and other fields like name remain optional in the schema.

Example Valibot refinement extending schema with pipe

To extend a schema with a refinement using a callback, use pipe() to chain additional validators. For example, createSelectSchema(users, { name: (schema) => pipe(schema, maxLength(20)) }) extends the name field's schema with a maxLength constraint while preserving the original schema behavior.

Example Valibot refinement overwriting schema

To completely overwrite a field's schema, provide a Valibot schema object directly instead of a callback. For example, createSelectSchema(users, { preferences: object({ theme: string() }) }) overwrites the preferences field schema entirely, including its nullability.

Give your agent this brain