date.cjs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 date_exports = {};
  20. __export(date_exports, {
  21. PgDate: () => PgDate,
  22. PgDateBuilder: () => PgDateBuilder,
  23. PgDateString: () => PgDateString,
  24. PgDateStringBuilder: () => PgDateStringBuilder,
  25. date: () => date
  26. });
  27. module.exports = __toCommonJS(date_exports);
  28. var import_entity = require("../../entity.cjs");
  29. var import_utils = require("../../utils.cjs");
  30. var import_common = require("./common.cjs");
  31. var import_date_common = require("./date.common.cjs");
  32. class PgDateBuilder extends import_date_common.PgDateColumnBaseBuilder {
  33. static [import_entity.entityKind] = "PgDateBuilder";
  34. constructor(name) {
  35. super(name, "date", "PgDate");
  36. }
  37. /** @internal */
  38. build(table) {
  39. return new PgDate(table, this.config);
  40. }
  41. }
  42. class PgDate extends import_common.PgColumn {
  43. static [import_entity.entityKind] = "PgDate";
  44. getSQLType() {
  45. return "date";
  46. }
  47. mapFromDriverValue(value) {
  48. if (typeof value === "string") return new Date(value);
  49. return value;
  50. }
  51. mapToDriverValue(value) {
  52. return value.toISOString();
  53. }
  54. }
  55. class PgDateStringBuilder extends import_date_common.PgDateColumnBaseBuilder {
  56. static [import_entity.entityKind] = "PgDateStringBuilder";
  57. constructor(name) {
  58. super(name, "string", "PgDateString");
  59. }
  60. /** @internal */
  61. build(table) {
  62. return new PgDateString(
  63. table,
  64. this.config
  65. );
  66. }
  67. }
  68. class PgDateString extends import_common.PgColumn {
  69. static [import_entity.entityKind] = "PgDateString";
  70. getSQLType() {
  71. return "date";
  72. }
  73. mapFromDriverValue(value) {
  74. if (typeof value === "string") return value;
  75. return value.toISOString().slice(0, -14);
  76. }
  77. }
  78. function date(a, b) {
  79. const { name, config } = (0, import_utils.getColumnNameAndConfig)(a, b);
  80. if (config?.mode === "date") {
  81. return new PgDateBuilder(name);
  82. }
  83. return new PgDateStringBuilder(name);
  84. }
  85. // Annotate the CommonJS export names for ESM import in node:
  86. 0 && (module.exports = {
  87. PgDate,
  88. PgDateBuilder,
  89. PgDateString,
  90. PgDateStringBuilder,
  91. date
  92. });
  93. //# sourceMappingURL=date.cjs.map