primary-keys.cjs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 primary_keys_exports = {};
  20. __export(primary_keys_exports, {
  21. PrimaryKey: () => PrimaryKey,
  22. PrimaryKeyBuilder: () => PrimaryKeyBuilder,
  23. primaryKey: () => primaryKey
  24. });
  25. module.exports = __toCommonJS(primary_keys_exports);
  26. var import_entity = require("../entity.cjs");
  27. var import_table = require("./table.cjs");
  28. function primaryKey(...config) {
  29. if (config[0].columns) {
  30. return new PrimaryKeyBuilder(config[0].columns, config[0].name);
  31. }
  32. return new PrimaryKeyBuilder(config);
  33. }
  34. class PrimaryKeyBuilder {
  35. static [import_entity.entityKind] = "GelPrimaryKeyBuilder";
  36. /** @internal */
  37. columns;
  38. /** @internal */
  39. name;
  40. constructor(columns, name) {
  41. this.columns = columns;
  42. this.name = name;
  43. }
  44. /** @internal */
  45. build(table) {
  46. return new PrimaryKey(table, this.columns, this.name);
  47. }
  48. }
  49. class PrimaryKey {
  50. constructor(table, columns, name) {
  51. this.table = table;
  52. this.columns = columns;
  53. this.name = name;
  54. }
  55. static [import_entity.entityKind] = "GelPrimaryKey";
  56. columns;
  57. name;
  58. getName() {
  59. return this.name ?? `${this.table[import_table.GelTable.Symbol.Name]}_${this.columns.map((column) => column.name).join("_")}_pk`;
  60. }
  61. }
  62. // Annotate the CommonJS export names for ESM import in node:
  63. 0 && (module.exports = {
  64. PrimaryKey,
  65. PrimaryKeyBuilder,
  66. primaryKey
  67. });
  68. //# sourceMappingURL=primary-keys.cjs.map