unique-constraint.cjs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 uniqueKeyName(table, columns) {
  31. return `${table[import_table_utils.TableName]}_${columns.join("_")}_unique`;
  32. }
  33. function unique(name) {
  34. return new UniqueOnConstraintBuilder(name);
  35. }
  36. class UniqueConstraintBuilder {
  37. constructor(columns, name) {
  38. this.name = name;
  39. this.columns = columns;
  40. }
  41. static [import_entity.entityKind] = "SQLiteUniqueConstraintBuilder";
  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] = "SQLiteUniqueOnConstraintBuilder";
  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] = "SQLiteUniqueConstraint";
  67. columns;
  68. name;
  69. getName() {
  70. return this.name;
  71. }
  72. }
  73. // Annotate the CommonJS export names for ESM import in node:
  74. 0 && (module.exports = {
  75. UniqueConstraint,
  76. UniqueConstraintBuilder,
  77. UniqueOnConstraintBuilder,
  78. unique,
  79. uniqueKeyName
  80. });
  81. //# sourceMappingURL=unique-constraint.cjs.map