| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- import { entityKind } from "../../entity.js";
- import { getColumnNameAndConfig } from "../../utils.js";
- import { MySqlColumnBuilderWithAutoIncrement, MySqlColumnWithAutoIncrement } from "./common.js";
- class MySqlDecimalBuilder extends MySqlColumnBuilderWithAutoIncrement {
- static [entityKind] = "MySqlDecimalBuilder";
- constructor(name, config) {
- super(name, "string", "MySqlDecimal");
- this.config.precision = config?.precision;
- this.config.scale = config?.scale;
- this.config.unsigned = config?.unsigned;
- }
- /** @internal */
- build(table) {
- return new MySqlDecimal(
- table,
- this.config
- );
- }
- }
- class MySqlDecimal extends MySqlColumnWithAutoIncrement {
- static [entityKind] = "MySqlDecimal";
- precision = this.config.precision;
- scale = this.config.scale;
- unsigned = this.config.unsigned;
- mapFromDriverValue(value) {
- if (typeof value === "string") return value;
- return String(value);
- }
- getSQLType() {
- let type = "";
- if (this.precision !== void 0 && this.scale !== void 0) {
- type += `decimal(${this.precision},${this.scale})`;
- } else if (this.precision === void 0) {
- type += "decimal";
- } else {
- type += `decimal(${this.precision})`;
- }
- type = type === "decimal(10,0)" || type === "decimal(10)" ? "decimal" : type;
- return this.unsigned ? `${type} unsigned` : type;
- }
- }
- class MySqlDecimalNumberBuilder extends MySqlColumnBuilderWithAutoIncrement {
- static [entityKind] = "MySqlDecimalNumberBuilder";
- constructor(name, config) {
- super(name, "number", "MySqlDecimalNumber");
- this.config.precision = config?.precision;
- this.config.scale = config?.scale;
- this.config.unsigned = config?.unsigned;
- }
- /** @internal */
- build(table) {
- return new MySqlDecimalNumber(
- table,
- this.config
- );
- }
- }
- class MySqlDecimalNumber extends MySqlColumnWithAutoIncrement {
- static [entityKind] = "MySqlDecimalNumber";
- precision = this.config.precision;
- scale = this.config.scale;
- unsigned = this.config.unsigned;
- mapFromDriverValue(value) {
- if (typeof value === "number") return value;
- return Number(value);
- }
- mapToDriverValue = String;
- getSQLType() {
- let type = "";
- if (this.precision !== void 0 && this.scale !== void 0) {
- type += `decimal(${this.precision},${this.scale})`;
- } else if (this.precision === void 0) {
- type += "decimal";
- } else {
- type += `decimal(${this.precision})`;
- }
- type = type === "decimal(10,0)" || type === "decimal(10)" ? "decimal" : type;
- return this.unsigned ? `${type} unsigned` : type;
- }
- }
- class MySqlDecimalBigIntBuilder extends MySqlColumnBuilderWithAutoIncrement {
- static [entityKind] = "MySqlDecimalBigIntBuilder";
- constructor(name, config) {
- super(name, "bigint", "MySqlDecimalBigInt");
- this.config.precision = config?.precision;
- this.config.scale = config?.scale;
- this.config.unsigned = config?.unsigned;
- }
- /** @internal */
- build(table) {
- return new MySqlDecimalBigInt(
- table,
- this.config
- );
- }
- }
- class MySqlDecimalBigInt extends MySqlColumnWithAutoIncrement {
- static [entityKind] = "MySqlDecimalBigInt";
- precision = this.config.precision;
- scale = this.config.scale;
- unsigned = this.config.unsigned;
- mapFromDriverValue = BigInt;
- mapToDriverValue = String;
- getSQLType() {
- let type = "";
- if (this.precision !== void 0 && this.scale !== void 0) {
- type += `decimal(${this.precision},${this.scale})`;
- } else if (this.precision === void 0) {
- type += "decimal";
- } else {
- type += `decimal(${this.precision})`;
- }
- type = type === "decimal(10,0)" || type === "decimal(10)" ? "decimal" : type;
- return this.unsigned ? `${type} unsigned` : type;
- }
- }
- function decimal(a, b = {}) {
- const { name, config } = getColumnNameAndConfig(a, b);
- const mode = config?.mode;
- return mode === "number" ? new MySqlDecimalNumberBuilder(name, config) : mode === "bigint" ? new MySqlDecimalBigIntBuilder(name, config) : new MySqlDecimalBuilder(name, config);
- }
- export {
- MySqlDecimal,
- MySqlDecimalBigInt,
- MySqlDecimalBigIntBuilder,
- MySqlDecimalBuilder,
- MySqlDecimalNumber,
- MySqlDecimalNumberBuilder,
- decimal
- };
- //# sourceMappingURL=decimal.js.map
|