AK-21/Graphite-Industrial-Intelligence
0
1import { entityKind } from "../../entity.js";2import { getColumnNameAndConfig } from "../../utils.js";3import { SQLiteColumn, SQLiteColumnBuilder } from "./common.js";4class SQLiteNumericBuilder extends SQLiteColumnBuilder {5 static [entityKind] = "SQLiteNumericBuilder";6 constructor(name) {7 super(name, "string", "SQLiteNumeric");8 }9 /** @internal */10 build(table) {11 return new SQLiteNumeric(12 table,13 this.config14 );15 }16}17class SQLiteNumeric extends SQLiteColumn {18 static [entityKind] = "SQLiteNumeric";19 mapFromDriverValue(value) {20 if (typeof value === "string") return value;21 return String(value);22 }23 getSQLType() {24 return "numeric";25 }26}27class SQLiteNumericNumberBuilder extends SQLiteColumnBuilder {28 static [entityKind] = "SQLiteNumericNumberBuilder";29 constructor(name) {30 super(name, "number", "SQLiteNumericNumber");31 }32 /** @internal */33 build(table) {34 return new SQLiteNumericNumber(35 table,36 this.config37 );38 }39}40class SQLiteNumericNumber extends SQLiteColumn {41 static [entityKind] = "SQLiteNumericNumber";42 mapFromDriverValue(value) {43 if (typeof value === "number") return value;44 return Number(value);45 }46 mapToDriverValue = String;47 getSQLType() {48 return "numeric";49 }50}51class SQLiteNumericBigIntBuilder extends SQLiteColumnBuilder {52 static [entityKind] = "SQLiteNumericBigIntBuilder";53 constructor(name) {54 super(name, "bigint", "SQLiteNumericBigInt");55 }56 /** @internal */57 build(table) {58 return new SQLiteNumericBigInt(59 table,60 this.config61 );62 }63}64class SQLiteNumericBigInt extends SQLiteColumn {65 static [entityKind] = "SQLiteNumericBigInt";66 mapFromDriverValue = BigInt;67 mapToDriverValue = String;68 getSQLType() {69 return "numeric";70 }71}72function numeric(a, b) {73 const { name, config } = getColumnNameAndConfig(a, b);74 const mode = config?.mode;75 return mode === "number" ? new SQLiteNumericNumberBuilder(name) : mode === "bigint" ? new SQLiteNumericBigIntBuilder(name) : new SQLiteNumericBuilder(name);76}77export {78 SQLiteNumeric,79 SQLiteNumericBigInt,80 SQLiteNumericBigIntBuilder,81 SQLiteNumericBuilder,82 SQLiteNumericNumber,83 SQLiteNumericNumberBuilder,84 numeric85};86//# sourceMappingURL=numeric.js.map