unique-constraint.cjs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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] = "SingleStoreUniqueConstraintBuilder";
  42. /** @internal */
  43. columns;
  44. /** @internal */
  45. build(table) {
  46. return new UniqueConstraint(table, this.columns, this.name);
  47. }
  48. }
  49. class UniqueOnConstraintBuilder {
  50. static [import_entity.entityKind] = "SingleStoreUniqueOnConstraintBuilder";
  51. /** @internal */
  52. name;
  53. constructor(name) {
  54. this.name = name;
  55. }
  56. on(...columns) {
  57. return new UniqueConstraintBuilder(columns, this.name);
  58. }
  59. }
  60. class UniqueConstraint {
  61. constructor(table, columns, name) {
  62. this.table = table;
  63. this.columns = columns;
  64. this.name = name ?? uniqueKeyName(this.table, this.columns.map((column) => column.name));
  65. }
  66. static [import_entity.entityKind] = "SingleStoreUniqueConstraint";
  67. columns;
  68. name;
  69. nullsNotDistinct = false;
  70. getName() {
  71. return this.name;
  72. }
  73. }
  74. // Annotate the CommonJS export names for ESM import in node:
  75. 0 && (module.exports = {
  76. UniqueConstraint,
  77. UniqueConstraintBuilder,
  78. UniqueOnConstraintBuilder,
  79. unique,
  80. uniqueKeyName
  81. });
  82. //# sourceMappingURL=unique-constraint.cjs.map