CREATE TABLE `table` ( `serial` serial AUTO_INCREMENT);
---
binary
BINARY(M) stores a fixed-length byte string of exactly M bytes.
On insert, shorter values are right-padded with 0x00 bytes to reach M bytes; on retrieval, no padding is stripped.
All bytes—including trailing 0x00—are significant in comparisons, ORDER BY, and DISTINCT
VARBINARY(M) stores a variable-length byte string of exactly M bytes.
On insert, shorter values are right-padded with 0x00 bytes to reach M bytes; on retrieval, no padding is stripped.
All bytes—including trailing 0x00—are significant in comparisons, ORDER BY, and DISTINCT
You can specify .$type<..>() for json object inference, it won’t check runtime values.
It provides compile time protection for default values, insert and select schemas.
// will be inferred as { foo: string }json: json().$type<{ foo: string }>();// will be inferred as string[]json: json().$type<string[]>();// won't compilejson: json().$type<string[]>().default({});
Every column builder has a .$type() method, which allows you to customize the data type of the column. This is useful, for example, with unknown or branded types.
type UserId = number & { __brand: 'user_id' };type Data = { foo: string; bar: number;};const users = mysqlTable('users', { id: int().$type<UserId>().primaryKey(), jsonField: json().$type<Data>(),});
Not null
NOT NULL constraint dictates that the associated column may not contain a NULL value.
The DEFAULT clause specifies a default value to use for the column if no value
is explicitly provided by the user when doing an INSERT.
If there is no explicit DEFAULT clause attached to a column definition,
then the default value of the column is NULL.
An explicit DEFAULT clause may specify that the default value is NULL,
a string constant, a blob constant, a signed-number, or any constant expression enclosed in parentheses.
When using $default() or $defaultFn(), which are simply different aliases for the same function,
you can generate defaults at runtime and use these values in all insert queries.
These functions can assist you in utilizing various implementations such as uuid, cuid, cuid2, and many more.
Note: This value does not affect the drizzle-kit behavior, it is only used at runtime in drizzle-orm
When using $onUpdate() or $onUpdateFn(), which are simply different aliases for the same function,
you can generate defaults at runtime and use these values in all update queries.
Adds a dynamic update value to the column. The function will be called when the row is updated,
and the returned value will be used as the column value if none is provided.
If no default (or $defaultFn) value is provided, the function will be called
when the row is inserted as well, and the returned value will be used as the column value.
Note: This value does not affect the drizzle-kit behavior, it is only used at runtime in drizzle-orm