timestamp.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { entityKind } from "../../entity.js";
  2. import { getColumnNameAndConfig } from "../../utils.js";
  3. import { MySqlDateBaseColumn, MySqlDateColumnBaseBuilder } from "./date.common.js";
  4. class MySqlTimestampBuilder extends MySqlDateColumnBaseBuilder {
  5. static [entityKind] = "MySqlTimestampBuilder";
  6. constructor(name, config) {
  7. super(name, "date", "MySqlTimestamp");
  8. this.config.fsp = config?.fsp;
  9. }
  10. /** @internal */
  11. build(table) {
  12. return new MySqlTimestamp(
  13. table,
  14. this.config
  15. );
  16. }
  17. }
  18. class MySqlTimestamp extends MySqlDateBaseColumn {
  19. static [entityKind] = "MySqlTimestamp";
  20. fsp = this.config.fsp;
  21. getSQLType() {
  22. const precision = this.fsp === void 0 ? "" : `(${this.fsp})`;
  23. return `timestamp${precision}`;
  24. }
  25. mapFromDriverValue(value) {
  26. return /* @__PURE__ */ new Date(value + "+0000");
  27. }
  28. mapToDriverValue(value) {
  29. return value.toISOString().slice(0, -1).replace("T", " ");
  30. }
  31. }
  32. class MySqlTimestampStringBuilder extends MySqlDateColumnBaseBuilder {
  33. static [entityKind] = "MySqlTimestampStringBuilder";
  34. constructor(name, config) {
  35. super(name, "string", "MySqlTimestampString");
  36. this.config.fsp = config?.fsp;
  37. }
  38. /** @internal */
  39. build(table) {
  40. return new MySqlTimestampString(
  41. table,
  42. this.config
  43. );
  44. }
  45. }
  46. class MySqlTimestampString extends MySqlDateBaseColumn {
  47. static [entityKind] = "MySqlTimestampString";
  48. fsp = this.config.fsp;
  49. getSQLType() {
  50. const precision = this.fsp === void 0 ? "" : `(${this.fsp})`;
  51. return `timestamp${precision}`;
  52. }
  53. }
  54. function timestamp(a, b = {}) {
  55. const { name, config } = getColumnNameAndConfig(a, b);
  56. if (config?.mode === "string") {
  57. return new MySqlTimestampStringBuilder(name, config);
  58. }
  59. return new MySqlTimestampBuilder(name, config);
  60. }
  61. export {
  62. MySqlTimestamp,
  63. MySqlTimestampBuilder,
  64. MySqlTimestampString,
  65. MySqlTimestampStringBuilder,
  66. timestamp
  67. };
  68. //# sourceMappingURL=timestamp.js.map