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

typebox

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

typebox schema generation - available functions

Drizzle ORM typebox support provides three main functions for SQLite: createInsertSchema() generates a schema for validating data being inserted into a table, createUpdateSchema() generates a schema for validating data being updated in a table, and createSelectSchema() generates a schema for validating data being selected from a table or view.

typebox createInsertSchema with field overrides

When creating an insert schema with createInsertSchema(table, overrides), you can pass an optional second parameter object to override the generated field types. For example, createInsertSchema(users, { role: Type.String() }) replaces the auto-generated role schema with a custom Type.String() schema.

typebox createInsertSchema with field refinement

When creating an insert schema with createInsertSchema(table, refinements), you can pass field refinements as an object where each key is a field name and the value is either a Type definition or a function that receives the auto-generated schema and returns a modified schema. For example, createInsertSchema(users, { id: (schema) => Type.Number({ ...schema, minimum: 0 }) }) refines the id field to add a minimum constraint.

typebox schema validation with Value.Check

Typebox schemas can be validated at runtime using Value.Check(schema, data). This function returns a boolean indicating whether the data conforms to the schema. For example, Value.Check(insertUserSchema, { name: 'John Doe', email: 'johndoe@test.com', role: 'admin' }) validates the given object against the insertUserSchema.

typebox - install dependencies

To use typebox schema generation with Drizzle ORM, install drizzle-orm@rc and typebox packages.

typebox imports for schema generation

To generate typebox schemas from Drizzle tables, import createInsertSchema, createSelectSchema, and createUpdateSchema from 'drizzle-orm/typebox'. Also import Type from 'typebox' for field refinements and Value from 'typebox/value' for validation.

typebox validation use case - API requests and responses

Typebox schemas generated from Drizzle ORM tables can be used to validate API requests (using insert and update schemas) and API responses (using select schemas).

typebox supported SQLite column features

Typebox schema generation supports SQLite column features including notNull constraints, enum constraints (via text({ enum: [...] })), timestamp mode columns (via integer('name', { mode: 'timestamp' })), and primaryKey with autoIncrement.

Give your agent this brain