AK-21/Graphite-Industrial-Intelligence
0
1import { entityKind } from "../../entity.js";2import { getColumnNameAndConfig } from "../../utils.js";3import { SQLiteColumn, SQLiteColumnBuilder } from "./common.js";4class SQLiteCustomColumnBuilder extends SQLiteColumnBuilder {5 static [entityKind] = "SQLiteCustomColumnBuilder";6 constructor(name, fieldConfig, customTypeParams) {7 super(name, "custom", "SQLiteCustomColumn");8 this.config.fieldConfig = fieldConfig;9 this.config.customTypeParams = customTypeParams;10 }11 /** @internal */12 build(table) {13 return new SQLiteCustomColumn(14 table,15 this.config16 );17 }18}19class SQLiteCustomColumn extends SQLiteColumn {20 static [entityKind] = "SQLiteCustomColumn";21 sqlName;22 mapTo;23 mapFrom;24 constructor(table, config) {25 super(table, config);26 this.sqlName = config.customTypeParams.dataType(config.fieldConfig);27 this.mapTo = config.customTypeParams.toDriver;28 this.mapFrom = config.customTypeParams.fromDriver;29 }30 getSQLType() {31 return this.sqlName;32 }33 mapFromDriverValue(value) {34 return typeof this.mapFrom === "function" ? this.mapFrom(value) : value;35 }36 mapToDriverValue(value) {37 return typeof this.mapTo === "function" ? this.mapTo(value) : value;38 }39}40function customType(customTypeParams) {41 return (a, b) => {42 const { name, config } = getColumnNameAndConfig(a, b);43 return new SQLiteCustomColumnBuilder(44 name,45 config,46 customTypeParams47 );48 };49}50export {51 SQLiteCustomColumn,52 SQLiteCustomColumnBuilder,53 customType54};55//# sourceMappingURL=custom.js.map