← Files RivetARCHIVED FILE
node_modules/drizzle-orm/column-builder.cjs
3.38 KB · Nov 5, 2026 · 12:09 UTC
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
let __entity_ts = require("./entity.cjs");
//#region src/column-builder.ts
function extractExtendedColumnType(column) {
const [type, constraint] = column.dataType.split(" ");
return {
type,
constraint
};
}
var ColumnBuilder = class {
static [__entity_ts.entityKind] = "ColumnBuilder";
/** @internal */
config;
constructor(name, dataType, columnType) {
this.config = {
name,
keyAsName: name === "",
notNull: false,
default: void 0,
hasDefault: false,
primaryKey: false,
isUnique: false,
uniqueName: void 0,
uniqueType: void 0,
dataType,
columnType,
generated: void 0
};
}
/**
* Changes the data type of the column. Commonly used with `json` columns. Also, useful for branded types.
*
* @example
* ```ts
* const users = pgTable('users', {
* id: integer('id').$type<UserId>().primaryKey(),
* details: json('details').$type<UserDetails>().notNull(),
* });
* ```
*/
$type() {
return this;
}
/**
* Adds a `not null` clause to the column definition.
*
* Affects the `select` model of the table - columns *without* `not null` will be nullable on select.
*/
notNull() {
this.config.notNull = true;
return this;
}
/**
* Adds a `default <value>` clause to the column definition.
*
* Affects the `insert` model of the table - columns *with* `default` are optional on insert.
*
* If you need to set a dynamic default value, use {@link $defaultFn} instead.
*/
default(value) {
this.config.default = value;
this.config.hasDefault = true;
return this;
}
/**
* Adds a dynamic default value to the column.
* The function will be called when the row is inserted, 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`.
*/
$defaultFn(fn) {
this.config.defaultFn = fn;
this.config.hasDefault = true;
return this;
}
/**
* Alias for {@link $defaultFn}.
*/
$default = this.$defaultFn;
/**
* 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`.
*/
$onUpdateFn(fn) {
this.config.onUpdateFn = fn;
this.config.hasDefault = true;
return this;
}
/**
* Alias for {@link $onUpdateFn}.
*/
$onUpdate = this.$onUpdateFn;
/**
* Adds a `primary key` clause to the column definition. This implicitly makes the column `not null`.
*
* In SQLite, `integer primary key` implicitly makes the column auto-incrementing.
*/
primaryKey() {
this.config.primaryKey = true;
this.config.notNull = true;
return this;
}
/** @internal Sets the name of the column to the key within the table definition if a name was not given. */
setName(name, casingFn) {
if (this.config.name !== "") return;
this.config.name = casingFn(name);
}
};
//#endregion
exports.ColumnBuilder = ColumnBuilder;
exports.extractExtendedColumnType = extractExtendedColumnType;
//# sourceMappingURL=column-builder.cjs.mapSHA-256: 8b3fdec1aaa486f9b49a9746e8bbf0eab499f06c6fc90dd774411dd0c39e12ce