decimal.cjs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 decimal_exports = {};
  20. __export(decimal_exports, {
  21. MySqlDecimal: () => MySqlDecimal,
  22. MySqlDecimalBigInt: () => MySqlDecimalBigInt,
  23. MySqlDecimalBigIntBuilder: () => MySqlDecimalBigIntBuilder,
  24. MySqlDecimalBuilder: () => MySqlDecimalBuilder,
  25. MySqlDecimalNumber: () => MySqlDecimalNumber,
  26. MySqlDecimalNumberBuilder: () => MySqlDecimalNumberBuilder,
  27. decimal: () => decimal
  28. });
  29. module.exports = __toCommonJS(decimal_exports);
  30. var import_entity = require("../../entity.cjs");
  31. var import_utils = require("../../utils.cjs");
  32. var import_common = require("./common.cjs");
  33. class MySqlDecimalBuilder extends import_common.MySqlColumnBuilderWithAutoIncrement {
  34. static [import_entity.entityKind] = "MySqlDecimalBuilder";
  35. constructor(name, config) {
  36. super(name, "string", "MySqlDecimal");
  37. this.config.precision = config?.precision;
  38. this.config.scale = config?.scale;
  39. this.config.unsigned = config?.unsigned;
  40. }
  41. /** @internal */
  42. build(table) {
  43. return new MySqlDecimal(
  44. table,
  45. this.config
  46. );
  47. }
  48. }
  49. class MySqlDecimal extends import_common.MySqlColumnWithAutoIncrement {
  50. static [import_entity.entityKind] = "MySqlDecimal";
  51. precision = this.config.precision;
  52. scale = this.config.scale;
  53. unsigned = this.config.unsigned;
  54. mapFromDriverValue(value) {
  55. if (typeof value === "string") return value;
  56. return String(value);
  57. }
  58. getSQLType() {
  59. let type = "";
  60. if (this.precision !== void 0 && this.scale !== void 0) {
  61. type += `decimal(${this.precision},${this.scale})`;
  62. } else if (this.precision === void 0) {
  63. type += "decimal";
  64. } else {
  65. type += `decimal(${this.precision})`;
  66. }
  67. type = type === "decimal(10,0)" || type === "decimal(10)" ? "decimal" : type;
  68. return this.unsigned ? `${type} unsigned` : type;
  69. }
  70. }
  71. class MySqlDecimalNumberBuilder extends import_common.MySqlColumnBuilderWithAutoIncrement {
  72. static [import_entity.entityKind] = "MySqlDecimalNumberBuilder";
  73. constructor(name, config) {
  74. super(name, "number", "MySqlDecimalNumber");
  75. this.config.precision = config?.precision;
  76. this.config.scale = config?.scale;
  77. this.config.unsigned = config?.unsigned;
  78. }
  79. /** @internal */
  80. build(table) {
  81. return new MySqlDecimalNumber(
  82. table,
  83. this.config
  84. );
  85. }
  86. }
  87. class MySqlDecimalNumber extends import_common.MySqlColumnWithAutoIncrement {
  88. static [import_entity.entityKind] = "MySqlDecimalNumber";
  89. precision = this.config.precision;
  90. scale = this.config.scale;
  91. unsigned = this.config.unsigned;
  92. mapFromDriverValue(value) {
  93. if (typeof value === "number") return value;
  94. return Number(value);
  95. }
  96. mapToDriverValue = String;
  97. getSQLType() {
  98. let type = "";
  99. if (this.precision !== void 0 && this.scale !== void 0) {
  100. type += `decimal(${this.precision},${this.scale})`;
  101. } else if (this.precision === void 0) {
  102. type += "decimal";
  103. } else {
  104. type += `decimal(${this.precision})`;
  105. }
  106. type = type === "decimal(10,0)" || type === "decimal(10)" ? "decimal" : type;
  107. return this.unsigned ? `${type} unsigned` : type;
  108. }
  109. }
  110. class MySqlDecimalBigIntBuilder extends import_common.MySqlColumnBuilderWithAutoIncrement {
  111. static [import_entity.entityKind] = "MySqlDecimalBigIntBuilder";
  112. constructor(name, config) {
  113. super(name, "bigint", "MySqlDecimalBigInt");
  114. this.config.precision = config?.precision;
  115. this.config.scale = config?.scale;
  116. this.config.unsigned = config?.unsigned;
  117. }
  118. /** @internal */
  119. build(table) {
  120. return new MySqlDecimalBigInt(
  121. table,
  122. this.config
  123. );
  124. }
  125. }
  126. class MySqlDecimalBigInt extends import_common.MySqlColumnWithAutoIncrement {
  127. static [import_entity.entityKind] = "MySqlDecimalBigInt";
  128. precision = this.config.precision;
  129. scale = this.config.scale;
  130. unsigned = this.config.unsigned;
  131. mapFromDriverValue = BigInt;
  132. mapToDriverValue = String;
  133. getSQLType() {
  134. let type = "";
  135. if (this.precision !== void 0 && this.scale !== void 0) {
  136. type += `decimal(${this.precision},${this.scale})`;
  137. } else if (this.precision === void 0) {
  138. type += "decimal";
  139. } else {
  140. type += `decimal(${this.precision})`;
  141. }
  142. type = type === "decimal(10,0)" || type === "decimal(10)" ? "decimal" : type;
  143. return this.unsigned ? `${type} unsigned` : type;
  144. }
  145. }
  146. function decimal(a, b = {}) {
  147. const { name, config } = (0, import_utils.getColumnNameAndConfig)(a, b);
  148. const mode = config?.mode;
  149. return mode === "number" ? new MySqlDecimalNumberBuilder(name, config) : mode === "bigint" ? new MySqlDecimalBigIntBuilder(name, config) : new MySqlDecimalBuilder(name, config);
  150. }
  151. // Annotate the CommonJS export names for ESM import in node:
  152. 0 && (module.exports = {
  153. MySqlDecimal,
  154. MySqlDecimalBigInt,
  155. MySqlDecimalBigIntBuilder,
  156. MySqlDecimalBuilder,
  157. MySqlDecimalNumber,
  158. MySqlDecimalNumberBuilder,
  159. decimal
  160. });
  161. //# sourceMappingURL=decimal.cjs.map