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

schema validation & typebox integration

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.

Typebox package support added

Drizzle ORM v0.28.2 added support for the Typebox package through a new drizzle-typebox package for schema validation.

effect-schema overview and supported features

effect-schema allows you to generate Effect schemas from Drizzle ORM schemas. Supported features include creating select schemas for tables and views, creating insert and update schemas for tables, and support for the MySQL dialect.

Creating Effect schemas with createInsertSchema, createSelectSchema, createUpdateSchema

Import createInsertSchema, createSelectSchema, and createUpdateSchema from 'drizzle-orm/effect-schema'. Use createInsertSchema to generate a schema for inserting data (validates API requests), createUpdateSchema for updating data (validates API requests), and createSelectSchema for selecting data (validates API responses).

Overriding fields in Effect schemas

When creating an Effect schema, you can override fields by passing a second argument with field names mapped to new schema values. For example, createInsertSchema(users, { role: Schema.String }) overrides the role field with a different schema.

Refining fields in Effect schemas using check

Fields in Effect schemas can be refined before they become nullable or optional by passing a function as the field value. The function receives the original schema and returns a modified schema. For example, createInsertSchema(users, { id: (schema) => schema.check(Schema.isGreaterThanOrEqualTo(0)) }) adds a check constraint to the id field.

Validating data with Effect Schema.decodeUnknownEffect

Use Schema.decodeUnknownEffect with an Effect schema to validate and parse data. For example, Schema.decodeUnknownEffect(UserInsert)({ name: 'John Doe', email: 'johndoe@test.com', role: 'admin' }) validates the data against the UserInsert schema.

Complete Effect schema generation example

import { int, mysqlTable, text, timestamp } from 'drizzle-orm/mysql-core'; import { createInsertSchema, createSelectSchema, createUpdateSchema } from 'drizzle-orm/effect-schema'; import { Effect, Schema } from "effect"; const users = mysqlTable('users', { id: int().primaryKey().autoincrement(), name: text().notNull(), email: text().notNull(), role: text({ enum: ['admin', 'user'] }).notNull(), createdAt: timestamp('created_at').notNull().defaultNow(), }); const UserInsert = createInsertSchema(users); const UserUpdate = createUpdateSchema(users); const UserSelect = createSelectSchema(users); const program = Effect.gen(function*() { const parsedUser = yield* Schema.decodeUnknownEffect(UserInsert)({ name: 'John Doe', email: 'johndoe@test.com', role: 'admin', }); });

Give your agent this brain