CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
column-builder.cjs130 linesDownload Raw Back to drizzle-orm
1"use strict";2var __defProp = Object.defineProperty;3var __getOwnPropDesc = Object.getOwnPropertyDescriptor;4var __getOwnPropNames = Object.getOwnPropertyNames;5var __hasOwnProp = Object.prototype.hasOwnProperty;6var __export = (target, all) => {7  for (var name in all)8    __defProp(target, name, { get: all[name], enumerable: true });9};10var __copyProps = (to, from, except, desc) => {11  if (from && typeof from === "object" || typeof from === "function") {12    for (let key of __getOwnPropNames(from))13      if (!__hasOwnProp.call(to, key) && key !== except)14        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });15  }16  return to;17};18var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);19var column_builder_exports = {};20__export(column_builder_exports, {21  ColumnBuilder: () => ColumnBuilder22});23module.exports = __toCommonJS(column_builder_exports);24var import_entity = require("./entity.cjs");25class ColumnBuilder {26  static [import_entity.entityKind] = "ColumnBuilder";27  config;28  constructor(name, dataType, columnType) {29    this.config = {30      name,31      keyAsName: name === "",32      notNull: false,33      default: void 0,34      hasDefault: false,35      primaryKey: false,36      isUnique: false,37      uniqueName: void 0,38      uniqueType: void 0,39      dataType,40      columnType,41      generated: void 042    };43  }44  /**45   * Changes the data type of the column. Commonly used with `json` columns. Also, useful for branded types.46   *47   * @example48   * ```ts49   * const users = pgTable('users', {50   * 	id: integer('id').$type<UserId>().primaryKey(),51   * 	details: json('details').$type<UserDetails>().notNull(),52   * });53   * ```54   */55  $type() {56    return this;57  }58  /**59   * Adds a `not null` clause to the column definition.60   *61   * Affects the `select` model of the table - columns *without* `not null` will be nullable on select.62   */63  notNull() {64    this.config.notNull = true;65    return this;66  }67  /**68   * Adds a `default <value>` clause to the column definition.69   *70   * Affects the `insert` model of the table - columns *with* `default` are optional on insert.71   *72   * If you need to set a dynamic default value, use {@link $defaultFn} instead.73   */74  default(value) {75    this.config.default = value;76    this.config.hasDefault = true;77    return this;78  }79  /**80   * Adds a dynamic default value to the column.81   * The function will be called when the row is inserted, and the returned value will be used as the column value.82   *83   * **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.84   */85  $defaultFn(fn) {86    this.config.defaultFn = fn;87    this.config.hasDefault = true;88    return this;89  }90  /**91   * Alias for {@link $defaultFn}.92   */93  $default = this.$defaultFn;94  /**95   * Adds a dynamic update value to the column.96   * 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.97   * 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.98   *99   * **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.100   */101  $onUpdateFn(fn) {102    this.config.onUpdateFn = fn;103    this.config.hasDefault = true;104    return this;105  }106  /**107   * Alias for {@link $onUpdateFn}.108   */109  $onUpdate = this.$onUpdateFn;110  /**111   * Adds a `primary key` clause to the column definition. This implicitly makes the column `not null`.112   *113   * In SQLite, `integer primary key` implicitly makes the column auto-incrementing.114   */115  primaryKey() {116    this.config.primaryKey = true;117    this.config.notNull = true;118    return this;119  }120  /** @internal Sets the name of the column to the key within the table definition if a name was not given. */121  setName(name) {122    if (this.config.name !== "") return;123    this.config.name = name;124  }125}126// Annotate the CommonJS export names for ESM import in node:1270 && (module.exports = {128  ColumnBuilder129});130//# sourceMappingURL=column-builder.cjs.map