AK-21/Graphite-Industrial-Intelligence
0
1import { entityKind } from "../../entity.js";2import { getColumnNameAndConfig, textDecoder } from "../../utils.js";3import { SQLiteColumn, SQLiteColumnBuilder } from "./common.js";4class SQLiteBigIntBuilder extends SQLiteColumnBuilder {5 static [entityKind] = "SQLiteBigIntBuilder";6 constructor(name) {7 super(name, "bigint", "SQLiteBigInt");8 }9 /** @internal */10 build(table) {11 return new SQLiteBigInt(table, this.config);12 }13}14class SQLiteBigInt extends SQLiteColumn {15 static [entityKind] = "SQLiteBigInt";16 getSQLType() {17 return "blob";18 }19 mapFromDriverValue(value) {20 if (typeof Buffer !== "undefined" && Buffer.from) {21 const buf = Buffer.isBuffer(value) ? value : value instanceof ArrayBuffer ? Buffer.from(value) : value.buffer ? Buffer.from(value.buffer, value.byteOffset, value.byteLength) : Buffer.from(value);22 return BigInt(buf.toString("utf8"));23 }24 return BigInt(textDecoder.decode(value));25 }26 mapToDriverValue(value) {27 return Buffer.from(value.toString());28 }29}30class SQLiteBlobJsonBuilder extends SQLiteColumnBuilder {31 static [entityKind] = "SQLiteBlobJsonBuilder";32 constructor(name) {33 super(name, "json", "SQLiteBlobJson");34 }35 /** @internal */36 build(table) {37 return new SQLiteBlobJson(38 table,39 this.config40 );41 }42}43class SQLiteBlobJson extends SQLiteColumn {44 static [entityKind] = "SQLiteBlobJson";45 getSQLType() {46 return "blob";47 }48 mapFromDriverValue(value) {49 if (typeof Buffer !== "undefined" && Buffer.from) {50 const buf = Buffer.isBuffer(value) ? value : value instanceof ArrayBuffer ? Buffer.from(value) : value.buffer ? Buffer.from(value.buffer, value.byteOffset, value.byteLength) : Buffer.from(value);51 return JSON.parse(buf.toString("utf8"));52 }53 return JSON.parse(textDecoder.decode(value));54 }55 mapToDriverValue(value) {56 return Buffer.from(JSON.stringify(value));57 }58}59class SQLiteBlobBufferBuilder extends SQLiteColumnBuilder {60 static [entityKind] = "SQLiteBlobBufferBuilder";61 constructor(name) {62 super(name, "buffer", "SQLiteBlobBuffer");63 }64 /** @internal */65 build(table) {66 return new SQLiteBlobBuffer(table, this.config);67 }68}69class SQLiteBlobBuffer extends SQLiteColumn {70 static [entityKind] = "SQLiteBlobBuffer";71 mapFromDriverValue(value) {72 if (Buffer.isBuffer(value)) {73 return value;74 }75 return Buffer.from(value);76 }77 getSQLType() {78 return "blob";79 }80}81function blob(a, b) {82 const { name, config } = getColumnNameAndConfig(a, b);83 if (config?.mode === "json") {84 return new SQLiteBlobJsonBuilder(name);85 }86 if (config?.mode === "bigint") {87 return new SQLiteBigIntBuilder(name);88 }89 return new SQLiteBlobBufferBuilder(name);90}91export {92 SQLiteBigInt,93 SQLiteBigIntBuilder,94 SQLiteBlobBuffer,95 SQLiteBlobBufferBuilder,96 SQLiteBlobJson,97 SQLiteBlobJsonBuilder,98 blob99};100//# sourceMappingURL=blob.js.map