| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- import { entityKind } from "../../entity.js";
- import { getColumnNameAndConfig } from "../../utils.js";
- import { PgColumn, PgColumnBuilder } from "./common.js";
- class PgNumericBuilder extends PgColumnBuilder {
- static [entityKind] = "PgNumericBuilder";
- constructor(name, precision, scale) {
- super(name, "string", "PgNumeric");
- this.config.precision = precision;
- this.config.scale = scale;
- }
- /** @internal */
- build(table) {
- return new PgNumeric(table, this.config);
- }
- }
- class PgNumeric extends PgColumn {
- static [entityKind] = "PgNumeric";
- precision;
- scale;
- constructor(table, config) {
- super(table, config);
- this.precision = config.precision;
- this.scale = config.scale;
- }
- mapFromDriverValue(value) {
- if (typeof value === "string") return value;
- return String(value);
- }
- getSQLType() {
- if (this.precision !== void 0 && this.scale !== void 0) {
- return `numeric(${this.precision}, ${this.scale})`;
- } else if (this.precision === void 0) {
- return "numeric";
- } else {
- return `numeric(${this.precision})`;
- }
- }
- }
- class PgNumericNumberBuilder extends PgColumnBuilder {
- static [entityKind] = "PgNumericNumberBuilder";
- constructor(name, precision, scale) {
- super(name, "number", "PgNumericNumber");
- this.config.precision = precision;
- this.config.scale = scale;
- }
- /** @internal */
- build(table) {
- return new PgNumericNumber(
- table,
- this.config
- );
- }
- }
- class PgNumericNumber extends PgColumn {
- static [entityKind] = "PgNumericNumber";
- precision;
- scale;
- constructor(table, config) {
- super(table, config);
- this.precision = config.precision;
- this.scale = config.scale;
- }
- mapFromDriverValue(value) {
- if (typeof value === "number") return value;
- return Number(value);
- }
- mapToDriverValue = String;
- getSQLType() {
- if (this.precision !== void 0 && this.scale !== void 0) {
- return `numeric(${this.precision}, ${this.scale})`;
- } else if (this.precision === void 0) {
- return "numeric";
- } else {
- return `numeric(${this.precision})`;
- }
- }
- }
- class PgNumericBigIntBuilder extends PgColumnBuilder {
- static [entityKind] = "PgNumericBigIntBuilder";
- constructor(name, precision, scale) {
- super(name, "bigint", "PgNumericBigInt");
- this.config.precision = precision;
- this.config.scale = scale;
- }
- /** @internal */
- build(table) {
- return new PgNumericBigInt(
- table,
- this.config
- );
- }
- }
- class PgNumericBigInt extends PgColumn {
- static [entityKind] = "PgNumericBigInt";
- precision;
- scale;
- constructor(table, config) {
- super(table, config);
- this.precision = config.precision;
- this.scale = config.scale;
- }
- mapFromDriverValue = BigInt;
- mapToDriverValue = String;
- getSQLType() {
- if (this.precision !== void 0 && this.scale !== void 0) {
- return `numeric(${this.precision}, ${this.scale})`;
- } else if (this.precision === void 0) {
- return "numeric";
- } else {
- return `numeric(${this.precision})`;
- }
- }
- }
- function numeric(a, b) {
- const { name, config } = getColumnNameAndConfig(a, b);
- const mode = config?.mode;
- 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);
- }
- const decimal = numeric;
- export {
- PgNumeric,
- PgNumericBigInt,
- PgNumericBigIntBuilder,
- PgNumericBuilder,
- PgNumericNumber,
- PgNumericNumberBuilder,
- decimal,
- numeric
- };
- //# sourceMappingURL=numeric.js.map
|