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

arktype/select-schema

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.

createSelectSchema function

createSelectSchema is imported from 'drizzle-orm/arktype' and generates an arktype schema that validates data queried from the database. It can be used to validate API responses. The schema will only match the fields that are actually selected in the query. If a table column is not included in the select(), validation will fail even if the schema defines it.

createSelectSchema with views

createSelectSchema works with sqliteView in addition to sqliteTable. You can create a select schema from a view by passing the view to createSelectSchema.

createSelectSchema example with validation

Example showing createSelectSchema validation failing when not all columns are selected: import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'; import { createSelectSchema } from 'drizzle-orm/arktype'; import { ArkErrors } from "arktype"; const users = sqliteTable('users', { id: integer().primaryKey({ autoIncrement: true }), name: text().notNull(), age: integer().notNull() }); const userSelectSchema = createSelectSchema(users); const rows = await db.select({ id: users.id, name: users.name }).from(users).limit(1); const parsed: ArkErrors | { id: number; name: string; age: number } = userSelectSchema(rows[0]); // Error: `age` is not returned in the above query const rows = await db.select().from(users).limit(1); const parsed: ArkErrors | { id: number; name: string; age: number } = userSelectSchema(rows[0]); // Will parse successfully

createSelectSchema with typebox-legacy

The createSelectSchema function from drizzle-orm/typebox-legacy generates a Typebox schema that validates data shape from SELECT queries. It can be used to validate API responses. When using createSelectSchema, only columns actually returned by the query will be validated; attempting to validate a row missing a queried column will cause an error. For example, if a query selects only id and name from a table but the schema expects id, name, and age, validation will fail.

createSelectSchema supports views

The createSelectSchema function from drizzle-orm/typebox-legacy can generate schemas not only for tables but also for sqliteView objects. The schema works the same way as with tables.

Give your agent this brain