primary-keys.js 1006 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { entityKind } from "../entity.js";
  2. import { PgTable } from "./table.js";
  3. function primaryKey(...config) {
  4. if (config[0].columns) {
  5. return new PrimaryKeyBuilder(config[0].columns, config[0].name);
  6. }
  7. return new PrimaryKeyBuilder(config);
  8. }
  9. class PrimaryKeyBuilder {
  10. static [entityKind] = "PgPrimaryKeyBuilder";
  11. /** @internal */
  12. columns;
  13. /** @internal */
  14. name;
  15. constructor(columns, name) {
  16. this.columns = columns;
  17. this.name = name;
  18. }
  19. /** @internal */
  20. build(table) {
  21. return new PrimaryKey(table, this.columns, this.name);
  22. }
  23. }
  24. class PrimaryKey {
  25. constructor(table, columns, name) {
  26. this.table = table;
  27. this.columns = columns;
  28. this.name = name;
  29. }
  30. static [entityKind] = "PgPrimaryKey";
  31. columns;
  32. name;
  33. getName() {
  34. return this.name ?? `${this.table[PgTable.Symbol.Name]}_${this.columns.map((column) => column.name).join("_")}_pk`;
  35. }
  36. }
  37. export {
  38. PrimaryKey,
  39. PrimaryKeyBuilder,
  40. primaryKey
  41. };
  42. //# sourceMappingURL=primary-keys.js.map