time.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { entityKind } from "../../entity.js";
  2. import { getColumnNameAndConfig } from "../../utils.js";
  3. import { PgColumn } from "./common.js";
  4. import { PgDateColumnBaseBuilder } from "./date.common.js";
  5. class PgTimeBuilder extends PgDateColumnBaseBuilder {
  6. constructor(name, withTimezone, precision) {
  7. super(name, "string", "PgTime");
  8. this.withTimezone = withTimezone;
  9. this.precision = precision;
  10. this.config.withTimezone = withTimezone;
  11. this.config.precision = precision;
  12. }
  13. static [entityKind] = "PgTimeBuilder";
  14. /** @internal */
  15. build(table) {
  16. return new PgTime(table, this.config);
  17. }
  18. }
  19. class PgTime extends PgColumn {
  20. static [entityKind] = "PgTime";
  21. withTimezone;
  22. precision;
  23. constructor(table, config) {
  24. super(table, config);
  25. this.withTimezone = config.withTimezone;
  26. this.precision = config.precision;
  27. }
  28. getSQLType() {
  29. const precision = this.precision === void 0 ? "" : `(${this.precision})`;
  30. return `time${precision}${this.withTimezone ? " with time zone" : ""}`;
  31. }
  32. }
  33. function time(a, b = {}) {
  34. const { name, config } = getColumnNameAndConfig(a, b);
  35. return new PgTimeBuilder(name, config.withTimezone ?? false, config.precision);
  36. }
  37. export {
  38. PgTime,
  39. PgTimeBuilder,
  40. time
  41. };
  42. //# sourceMappingURL=time.js.map