unique-constraint.cjs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __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. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var unique_constraint_exports = {};
  20. __export(unique_constraint_exports, {
  21. UniqueConstraint: () => UniqueConstraint,
  22. UniqueConstraintBuilder: () => UniqueConstraintBuilder,
  23. UniqueOnConstraintBuilder: () => UniqueOnConstraintBuilder,
  24. unique: () => unique,
  25. uniqueKeyName: () => uniqueKeyName
  26. });
  27. module.exports = __toCommonJS(unique_constraint_exports);
  28. var import_entity = require("../entity.cjs");
  29. var import_table_utils = require("../table.utils.cjs");
  30. function unique(name) {
  31. return new UniqueOnConstraintBuilder(name);
  32. }
  33. function uniqueKeyName(table, columns) {
  34. return `${table[import_table_utils.TableName]}_${columns.join("_")}_unique`;
  35. }
  36. class UniqueConstraintBuilder {
  37. constructor(columns, name) {
  38. this.name = name;
  39. this.columns = columns;
  40. }
  41. static [import_entity.entityKind] = "PgUniqueConstraintBuilder";
  42. /** @internal */
  43. columns;
  44. /** @internal */
  45. nullsNotDistinctConfig = false;
  46. nullsNotDistinct() {
  47. this.nullsNotDistinctConfig = true;
  48. return this;
  49. }
  50. /** @internal */
  51. build(table) {
  52. return new UniqueConstraint(table, this.columns, this.nullsNotDistinctConfig, this.name);
  53. }
  54. }
  55. class UniqueOnConstraintBuilder {
  56. static [import_entity.entityKind] = "PgUniqueOnConstraintBuilder";
  57. /** @internal */
  58. name;
  59. constructor(name) {
  60. this.name = name;
  61. }
  62. on(...columns) {
  63. return new UniqueConstraintBuilder(columns, this.name);
  64. }
  65. }
  66. class UniqueConstraint {
  67. constructor(table, columns, nullsNotDistinct, name) {
  68. this.table = table;
  69. this.columns = columns;
  70. this.name = name ?? uniqueKeyName(this.table, this.columns.map((column) => column.name));
  71. this.nullsNotDistinct = nullsNotDistinct;
  72. }
  73. static [import_entity.entityKind] = "PgUniqueConstraint";
  74. columns;
  75. name;
  76. nullsNotDistinct = false;
  77. getName() {
  78. return this.name;
  79. }
  80. }
  81. // Annotate the CommonJS export names for ESM import in node:
  82. 0 && (module.exports = {
  83. UniqueConstraint,
  84. UniqueConstraintBuilder,
  85. UniqueOnConstraintBuilder,
  86. unique,
  87. uniqueKeyName
  88. });
  89. //# sourceMappingURL=unique-constraint.cjs.map