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

validation & type safety

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

Infer INSERT type from table schema

Use `typeof table.$inferInsert` to create a TypeScript type matching the insert shape for a table. Example: `type NewUser = typeof users.$inferInsert;` can then be used to type parameters passed to insert operations.

InferType for TypeScript type inference from tables

Use InferType<TableClass> to generate a TypeScript type from a Drizzle table definition. Example: export type User = InferType<UsersTable>; This provides full type safety for query results.

$inferSelect and $inferInsert for table type inference

Tables now support $inferSelect / $.$inferSelect and $inferInsert / $.$inferInsert methods for convenient table model type inference. These replace the deprecated InferModel type and provide more explicit type inference for SELECT and INSERT operations.

InferSelectModel and InferInsertModel types

InferSelectModel and InferInsertModel are explicit type helpers that can be used as alternatives to the deprecated InferModel type. InferSelectModel infers the type returned from a SELECT query, while InferInsertModel infers the type used for INSERT operations.

Example of table type inference with $inferSelect and $inferInsert

import { InferSelectModel, InferInsertModel } from 'drizzle-orm' const usersTable = pgTable('users', { id: serial('id').primaryKey(), name: text('name').notNull(), verified: boolean('verified').notNull().default(false), jsonb: jsonb('jsonb').$type<string[]>(), createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(), }); type SelectUser = typeof usersTable.$inferSelect; type InsertUser = typeof usersTable.$inferInsert; type SelectUser2 = InferSelectModel<typeof usersTable>; type InsertUser2 = InferInsertModel<typeof usersTable>;

Give your agent this brain