Files
klz-cables.com/.pnpm-store/v10/files/e1/c27621cd1603f76169647140fdea2fd23865e51aea1967870932fd8da4ff509e547497ec592a46e9d9134ff8bed05c5f4ce1afdf549df7bc57a8233bc47484
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

106 lines
3.1 KiB
Plaintext

import { entityKind } from "./entity.js";
class ColumnBuilder {
static [entityKind] = "ColumnBuilder";
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) {
if (this.config.name !== "") return;
this.config.name = name;
}
}
export {
ColumnBuilder
};
//# sourceMappingURL=column-builder.js.map