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

drizzle-orm/zod

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

SingleStore enum columns to Zod schema mapping

SingleStore text({ enum: ... }), char({ enum: ... }), varchar({ enum: ... }), and singlestoreEnum(..., ...) all map to z.enum(enum) in Zod schemas.

SingleStore text column to Zod schema mapping

SingleStore text() maps to z.string().max(65_535) in Zod schemas, where 65535 is the unsigned 16-bit integer limit.

createSelectSchema for validating query results

The createSelectSchema function generates a Zod schema that defines the shape of data queried from the database and can be used to validate API responses. The schema will enforce that all fields defined in the table are present in the parsed data.

createInsertSchema for validating insert data

The createInsertSchema function generates a Zod schema that defines the shape of data to be inserted into the database and can be used to validate API requests. Required fields must be present; auto-increment primary keys are optional.

createUpdateSchema for validating update data

The createUpdateSchema function generates a Zod schema that defines the shape of data to be updated in the database and can be used to validate API requests. Generated columns like auto-increment primary keys cannot be updated. All other fields become optional.

SingleStore boolean column to Zod schema mapping

SingleStore boolean() maps to z.boolean() in Zod schemas.

SingleStore date/datetime/timestamp with mode date to Zod schema mapping

SingleStore date({ mode: 'date' }), datetime({ mode: 'date' }), and timestamp({ mode: 'date' }) all map to z.date() in Zod schemas.

SingleStore binary and string types to Zod schema mapping

SingleStore binary(), date({ mode: 'string' }), datetime({ mode: 'string' }), decimal(), time(), and timestamp({ mode: 'string' }) all map to z.string() in Zod schemas.

SingleStore varchar column to Zod schema mapping

SingleStore varchar({ length: ... }) maps to z.string().max(length) in Zod schemas.

SingleStore float column to Zod schema mapping

SingleStore float() maps to z.number().min(-8_388_608).max(8_388_607) in Zod schemas, representing 24-bit integer limits.

SingleStore mediumint column to Zod schema mapping

SingleStore mediumint() maps to z.number().min(-8_388_608).max(8_388_607).int() in Zod schemas, representing 24-bit integer limits.

SingleStore unsigned mediumint column to Zod schema mapping

SingleStore mediumint({ unsigned: true }) maps to z.number().min(0).max(16_777_215).int() in Zod schemas, representing unsigned 24-bit integer limits.

SingleStore int column to Zod schema mapping

SingleStore int() maps to z.number().min(-2_147_483_648).max(2_147_483_647).int() in Zod schemas, representing 32-bit integer limits.

SingleStore double and real columns to Zod schema mapping

SingleStore double() and real() map to z.number().min(-140_737_488_355_328).max(140_737_488_355_327) in Zod schemas, representing 48-bit integer limits.

SingleStore unsigned double column to Zod schema mapping

SingleStore double({ unsigned: true }) maps to z.number().min(0).max(281_474_976_710_655) in Zod schemas, representing unsigned 48-bit integer limits.

SingleStore bigint with mode number to Zod schema mapping

SingleStore bigint({ mode: 'number' }) maps to z.number().min(-9_007_199_254_740_991).max(9_007_199_254_740_991).int() in Zod schemas, representing JavaScript safe integer limits.

SingleStore serial column to Zod schema mapping

SingleStore serial() maps to z.number().min(0).max(9_007_199_254_740_991).int() in Zod schemas, representing JavaScript maximum safe integer.

SingleStore bigint with mode bigint to Zod schema mapping

SingleStore bigint({ mode: 'bigint' }) maps to z.bigint().min(-9_223_372_036_854_775_808n).max(9_223_372_036_854_775_807n) in Zod schemas, representing 64-bit integer limits.

SingleStore unsigned bigint with mode bigint to Zod schema mapping

SingleStore bigint({ mode: 'bigint', unsigned: true }) maps to z.bigint().min(0).max(18_446_744_073_709_551_615n) in Zod schemas, representing unsigned 64-bit integer limits.

SingleStore year column to Zod schema mapping

SingleStore year() maps to z.number().min(1_901).max(2_155).int() in Zod schemas.

SingleStore json column to Zod schema mapping

SingleStore json() maps to z.union([z.union([z.string(), z.number(), z.boolean(), z.null()]), z.record(z.any()), z.array(z.any())]) in Zod schemas.

Example: createSelectSchema with validation

Example showing createSelectSchema usage: createSelectSchema generates a schema from a table definition. When parsing query results, all fields in the schema must be present in the result. Selecting only specific columns will cause validation to fail if the schema includes those unselected columns.

Example: createInsertSchema with validation

Example showing createInsertSchema usage: createInsertSchema generates a schema for insert operations. Required fields must be provided during validation. Auto-increment primary keys are optional. Validation will fail if required fields are missing.

Example: createUpdateSchema with validation

Example showing createUpdateSchema usage: createUpdateSchema generates a schema for update operations. Generated columns like auto-increment primary keys cannot be included. All other fields are optional. Attempting to include generated columns in the update data will fail validation.

Example: Schema refinements with callbacks and overwrites

Example showing refinements: Callback functions like (schema) => schema.max(20) extend the generated schema. Providing a Zod schema directly like z.object({ theme: z.string() }) overwrites the field schema entirely, including its nullability.

Example: createSchemaFactory with extended Zod instance

Example showing createSchemaFactory with zodInstance parameter: createSchemaFactory({ zodInstance: z }) allows using an extended Zod instance like @hono/zod-openapi. The resulting schema functions can then use extended Zod methods like .openapi().

Example: createSchemaFactory with type coercion

Example showing createSchemaFactory with coerce parameter: createSchemaFactory({ coerce: { date: true } }) enables type coercion for specific data types. This converts coerce configuration into z.coerce.date() for timestamp fields. Set coerce to true to coerce all data types.

Give your agent this brain