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

cockroach/custom-types

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.

customType import for CockroachDB

The customType function is exposed from 'drizzle-orm/cockroach-core' for CockroachDB. It allows you to define custom column types with custom SQL data types and JS/DB value transforms.

customType basic structure for integer

A custom integer type for CockroachDB uses customType with a generic type parameter specifying { data: number } and a dataType function that returns 'int4'. Example: const customInteger = customType<{ data: number; }>({ dataType() { return 'int4'; } });

customType basic structure for text

A custom text type for CockroachDB uses customType with a generic type parameter specifying { data: string } and a dataType function that returns 'text'. Example: const customText = customType<{ data: string }>({ dataType() { return 'text'; } });

customType with configuration and transform functions

A custom timestamp type example shows how to use config, fromDriver, and dataType functions. The generic type includes data: Date, driverData: string, config with withTimezone and precision fields, and configRequired: false. The dataType function builds the SQL type string, and fromDriver transforms the driver's string value to a Date object.

CustomTypeValues generic type structure

CustomTypeValues is a generic type with the following optional properties: data (required, the TypeScript type after selecting/inserting), driverData (the type the database driver accepts), driverOutput (what the driver returns, defaults to driverData), jsonData (the type after JSON aggregation), config (configuration type for dataType generation), configRequired (boolean, default false, whether config is required), notNull (boolean, whether the column is notNull by default), and default (boolean, whether the column has a default by default).

forJsonSelect function for custom types

The forJsonSelect function is an optional selection modifier function that modifies column selection inside JSON functions. It takes identifier (SQL), sql (SQLGenerator), and optional arrayDimensions parameters and returns SQL. Following types are automatically casted to text by default: bytea, geometry, timestamp, numeric, and bigint. It is used by relational queries and JSON functions.

Custom type usage in table schema with modifiers

Custom types can be used with standard column modifiers like primaryKey(), notNull(), and default(). Example: const usersTable = cockroachTable('users', { id: customInteger().primaryKey(), name: customText().notNull(), createdAt: customTimestamp('created_at', { withTimezone: true }).notNull().default(sql`now()`) });

Give your agent this brain