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