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/arktype

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

arktype schema for mysql.varchar()

For mysql.varchar({ length: ... }), the arktype schema is type.string.atMostLength(length).

arktype schema for mysql.varbinary() with length

For mysql.varbinary({ length: ... }), the arktype schema is type(`/^[01]{0,${length ?? "*"}}$/`).

arktype schema for mysql.longtext()

For mysql.longtext(), the arktype schema is type.string.atMostLength(4_294_967_295), representing the unsigned 32-bit integer limit.

arktype schema for mysql.longblob()

For mysql.longblob({ mode: 'string' }) or mysql.longblob() without mode, the arktype schema is type.string.atMostLength(4_294_967_295).

Generate validation schema for MySQL SELECT queries with arktype

Use createSelectSchema() from drizzle-orm/arktype to generate a validation schema for data selected from a MySQL table. The generated schema can validate that all required columns are present in the query result. Call createSelectSchema(table) to create a schema, then invoke it as a function with a row to parse. If any expected columns are missing from the selected data, validation fails with ArkErrors.

Generate validation schema for MySQL INSERT with arktype

Use createInsertSchema() from drizzle-orm/arktype to generate a validation schema for data to be inserted into a MySQL table. The schema makes primary key columns optional (since they are auto-generated) while requiring columns marked as notNull. Call createInsertSchema(table) to create a schema, then invoke it with the data object. Validation returns ArkErrors if required fields are missing. Check if result is instanceof ArkErrors before proceeding.

Generate validation schema for MySQL UPDATE with arktype

Use createUpdateSchema() from drizzle-orm/arktype to generate a validation schema for data to be updated in a MySQL table. The schema makes all columns optional since UPDATE statements only require the columns being modified. Call createUpdateSchema(table) to create a schema, then invoke it with the partial data object. Validation returns ArkErrors if data does not conform to the schema.

Refine arktype validation schemas with callbacks or overwrites

Each create schema function (createSelectSchema, createInsertSchema, createUpdateSchema) accepts a second optional parameter for refinements. Pass an object where keys are field names. For each field, you can pass a callback function to extend the schema (e.g., adding constraints like maxLength), or pass an arktype schema directly to overwrite it completely. Overwriting a field's schema includes overriding its nullability.

arktype schema for mysql.boolean()

The arktype schema mapping for mysql.boolean() is type.boolean.

arktype schema for mysql.mysqlEnum()

The arktype schema mapping for mysql.mysqlEnum('name', ['val1', 'val2']) is type.enumerated('val1', 'val2').

arktype schema for mysql date and datetime types in date mode

The arktype schema mapping for mysql.date({ mode: 'date' }), mysql.datetime({ mode: 'date' }), and mysql.timestamp({ mode: 'date' }) is type.Date.

arktype schema for mysql string-based types

The arktype schema mapping for mysql.binary(), mysql.date({ mode: 'string' }), mysql.datetime({ mode: 'string' }), mysql.decimal(), mysql.time(), mysql.timestamp({ mode: 'string' }), and mysql.varbinary() is type.string.

arktype schema for MySQL text types with enum option

For mysql.tinytext({ enum: ... }), mysql.mediumtext({ enum: ... }), mysql.text({ enum: ... }), mysql.longtext({ enum: ... }), mysql.char({ enum: ... }), or mysql.varchar({ enum: ... }), the arktype schema is type.enumerated(...enum).

arktype schema for mysql.tinyint()

For mysql.tinyint(), the arktype schema is type.keywords.number.integer.atLeast(-128).atMost(127), representing the 8-bit integer limits.

arktype schema for mysql.tinyint() unsigned

For mysql.tinyint({ unsigned: true }), the arktype schema is type.keywords.number.integer.atLeast(0).atMost(255), representing the unsigned 8-bit integer limits.

arktype schema for mysql.smallint()

For mysql.smallint(), the arktype schema is type.keywords.number.integer.atLeast(-32_768).atMost(32_767), representing the 16-bit integer limits.

arktype schema for mysql.mediumint()

For mysql.mediumint(), the arktype schema is type.keywords.number.integer.atLeast(-8_388_608).atMost(8_388_607), representing the 24-bit integer limits.

arktype schema for mysql.int()

For mysql.int(), the arktype schema is type.keywords.number.integer.atLeast(-2_147_483_648).atMost(2_147_483_647), representing the 32-bit integer limits.

arktype schema for mysql.int() unsigned

For mysql.int({ unsigned: true }), the arktype schema is type.keywords.number.integer.atLeast(0).atMost(4_294_967_295), representing the unsigned 32-bit integer limits.

arktype schema for mysql.float()

For mysql.float(), the arktype schema is type.number.atLeast(-8_388_608).atMost(8_388_607), representing the 24-bit integer limits.

arktype schema for mysql.float() unsigned

For mysql.float({ unsigned: true }), the arktype schema is type.number.atLeast(0).atMost(16_777_215), representing the unsigned 24-bit integer limits.

arktype schema for mysql.double() and mysql.real()

For mysql.double() or mysql.real(), the arktype schema is type.number.atLeast(-140_737_488_355_328).atMost(140_737_488_355_327), representing the 48-bit integer limits.

arktype schema for mysql.double() unsigned and mysql.real() unsigned

For mysql.double({ unsigned: true }) or mysql.real({ unsigned: true }), the arktype schema is type.number.atLeast(0).atMost(281_474_976_710_655), representing the unsigned 48-bit integer limits.

arktype schema for mysql.decimal() unsigned with mode number

For mysql.decimal({ mode: 'number', unsigned: true }), the arktype schema is type.number.atLeast(0).atMost(9_007_199_254_740_991).

arktype schema for mysql.bigint() unsigned with mode number

For mysql.bigint({ mode: 'number', unsigned: true }), the arktype schema is type.keywords.number.integer.atLeast(0).atMost(9_007_199_254_740_991), representing JavaScript's maximum safe integer.

arktype schema for mysql.bigint() unsigned with mode string

For mysql.bigint({ mode: 'string', unsigned: true }), the arktype schema validates that the value is a string representing a non-negative number within the unsigned 64-bit integer range (0 to 9_223_372_036_854_775_807n). It checks the string matches /^\d+$/ before converting to BigInt.

arktype schema for mysql.bigint() with mode bigint

For mysql.bigint({ mode: 'bigint' }), the arktype schema is type.bigint.narrow((value, ctx) => value < -9_223_372_036_854_775_808n ? ctx.mustBe('greater than') : value > 9_223_372_036_854_775_807n ? ctx.mustBe('less than') : true), representing the 64-bit signed integer limits.

arktype schema for mysql.bigint() unsigned with mode bigint

For mysql.bigint({ mode: 'bigint', unsigned: true }), the arktype schema is type.bigint.narrow((value, ctx) => value < 0n ? ctx.mustBe('greater than') : value > 18_446_744_073_709_551_615n ? ctx.mustBe('less than') : true), representing the unsigned 64-bit integer limits.

arktype schema for mysql.serial()

For mysql.serial(), the arktype schema is type.keywords.number.integer.atLeast(0).atMost(9_007_199_254_740_991), representing the JavaScript maximum safe integer.

arktype schema for mysql.year()

For mysql.year(), the arktype schema is type.keywords.number.integer.atLeast(1_901).atMost(2_155).

arktype schema for mysql.json()

For mysql.json(), the arktype schema is type('string | number | boolean | null').or(type('unknown.any[] | Record<string, unknown.any>')).

Create validation schemas for MySQL views with arktype

Views are supported with arktype validation. Use createSelectSchema(view) where view is created with mysqlView(). This works the same as creating a select schema for a table.

Install arktype for Drizzle MySQL validation

To use arktype validation with Drizzle MySQL, install both drizzle-orm@rc and arktype as dependencies.

Validator packages consolidated into drizzle-orm

In v1, validation packages are consolidated into drizzle-orm as submodules: drizzle-zod becomes drizzle-orm/zod, drizzle-valibot becomes drizzle-orm/valibot, drizzle-typebox becomes drizzle-orm/typebox-legacy (using @sinclair/typebox) or drizzle-orm/typebox (using typebox), drizzle-arktype becomes drizzle-orm/arktype, and a new drizzle-orm/effect-schema package is added. Old packages can still be used but future updates go to drizzle-orm directly.

Give your agent this brain