drizzle-orm
Version:
Drizzle ORM package for SQL databases
46 lines • 1.27 kB
JavaScript
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;
}
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);
return new PgNumericBuilder(name, config?.precision, config?.scale);
}
const decimal = numeric;
export {
PgNumeric,
PgNumericBuilder,
decimal,
numeric
};
//# sourceMappingURL=numeric.js.map