timestamp.cjs 3.2 KB

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