custom.cjs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 custom_exports = {};
  20. __export(custom_exports, {
  21. MySqlCustomColumn: () => MySqlCustomColumn,
  22. MySqlCustomColumnBuilder: () => MySqlCustomColumnBuilder,
  23. customType: () => customType
  24. });
  25. module.exports = __toCommonJS(custom_exports);
  26. var import_entity = require("../../entity.cjs");
  27. var import_utils = require("../../utils.cjs");
  28. var import_common = require("./common.cjs");
  29. class MySqlCustomColumnBuilder extends import_common.MySqlColumnBuilder {
  30. static [import_entity.entityKind] = "MySqlCustomColumnBuilder";
  31. constructor(name, fieldConfig, customTypeParams) {
  32. super(name, "custom", "MySqlCustomColumn");
  33. this.config.fieldConfig = fieldConfig;
  34. this.config.customTypeParams = customTypeParams;
  35. }
  36. /** @internal */
  37. build(table) {
  38. return new MySqlCustomColumn(
  39. table,
  40. this.config
  41. );
  42. }
  43. }
  44. class MySqlCustomColumn extends import_common.MySqlColumn {
  45. static [import_entity.entityKind] = "MySqlCustomColumn";
  46. sqlName;
  47. mapTo;
  48. mapFrom;
  49. constructor(table, config) {
  50. super(table, config);
  51. this.sqlName = config.customTypeParams.dataType(config.fieldConfig);
  52. this.mapTo = config.customTypeParams.toDriver;
  53. this.mapFrom = config.customTypeParams.fromDriver;
  54. }
  55. getSQLType() {
  56. return this.sqlName;
  57. }
  58. mapFromDriverValue(value) {
  59. return typeof this.mapFrom === "function" ? this.mapFrom(value) : value;
  60. }
  61. mapToDriverValue(value) {
  62. return typeof this.mapTo === "function" ? this.mapTo(value) : value;
  63. }
  64. }
  65. function customType(customTypeParams) {
  66. return (a, b) => {
  67. const { name, config } = (0, import_utils.getColumnNameAndConfig)(a, b);
  68. return new MySqlCustomColumnBuilder(name, config, customTypeParams);
  69. };
  70. }
  71. // Annotate the CommonJS export names for ESM import in node:
  72. 0 && (module.exports = {
  73. MySqlCustomColumn,
  74. MySqlCustomColumnBuilder,
  75. customType
  76. });
  77. //# sourceMappingURL=custom.cjs.map