← Files RivetARCHIVED FILE

node_modules/drizzle-orm/sqlite-core/columns/blob.cjs

3.92 KB · Nov 5, 2026 · 12:09 UTC

↓ Download file

Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
const require_sqlite_core_columns_common = require('./common.cjs');
let __entity_ts = require("../../entity.cjs");
let __utils_ts = require("../../utils.cjs");

//#region src/sqlite-core/columns/blob.ts
function hexToText(hexString) {
	let result = "";
	for (let i = 0; i < hexString.length; i += 2) {
		const hexPair = hexString.slice(i, i + 2);
		const decimalValue = Number.parseInt(hexPair, 16);
		result += String.fromCodePoint(decimalValue);
	}
	return result;
}
var SQLiteBigIntBuilder = class extends require_sqlite_core_columns_common.SQLiteColumnBuilder {
	static [__entity_ts.entityKind] = "SQLiteBigIntBuilder";
	constructor(name) {
		super(name, "bigint int64", "SQLiteBigInt");
	}
	/** @internal */
	build(table) {
		return new SQLiteBigInt(table, this.config);
	}
};
var SQLiteBigInt = class extends require_sqlite_core_columns_common.SQLiteColumn {
	static [__entity_ts.entityKind] = "SQLiteBigInt";
	getSQLType() {
		return "blob";
	}
	mapFromDriverValue = (value) => {
		if (typeof value === "string") return BigInt(hexToText(value));
		if (typeof Buffer !== "undefined" && Buffer.from) {
			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);
			return BigInt(buf.toString("utf8"));
		}
		return BigInt(__utils_ts.textDecoder.decode(value));
	};
	mapToDriverValue = (value) => {
		return Buffer.from(value.toString());
	};
};
var SQLiteBlobJsonBuilder = class extends require_sqlite_core_columns_common.SQLiteColumnBuilder {
	static [__entity_ts.entityKind] = "SQLiteBlobJsonBuilder";
	constructor(name) {
		super(name, "object json", "SQLiteBlobJson");
	}
	/** @internal */
	build(table) {
		return new SQLiteBlobJson(table, this.config);
	}
};
var SQLiteBlobJson = class extends require_sqlite_core_columns_common.SQLiteColumn {
	static [__entity_ts.entityKind] = "SQLiteBlobJson";
	getSQLType() {
		return "blob";
	}
	mapFromDriverValue = (value) => {
		if (typeof value === "string") return JSON.parse(hexToText(value));
		if (typeof Buffer !== "undefined" && Buffer.from) {
			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);
			return JSON.parse(buf.toString("utf8"));
		}
		return JSON.parse(__utils_ts.textDecoder.decode(value));
	};
	mapToDriverValue = (value) => {
		return Buffer.from(JSON.stringify(value));
	};
};
var SQLiteBlobBufferBuilder = class extends require_sqlite_core_columns_common.SQLiteColumnBuilder {
	static [__entity_ts.entityKind] = "SQLiteBlobBufferBuilder";
	constructor(name) {
		super(name, "object buffer", "SQLiteBlobBuffer");
	}
	/** @internal */
	build(table) {
		return new SQLiteBlobBuffer(table, this.config);
	}
};
var SQLiteBlobBuffer = class extends require_sqlite_core_columns_common.SQLiteColumn {
	static [__entity_ts.entityKind] = "SQLiteBlobBuffer";
	mapFromDriverValue = (value) => {
		if (Buffer.isBuffer(value)) return value;
		if (typeof value === "string") return Buffer.from(value, "hex");
		return Buffer.from(value);
	};
	getSQLType() {
		return "blob";
	}
};
function blob(a, b) {
	const { name, config } = (0, __utils_ts.getColumnNameAndConfig)(a, b);
	if (config?.mode === "bigint") return new SQLiteBigIntBuilder(name);
	if (config?.mode === "buffer") return new SQLiteBlobBufferBuilder(name);
	return new SQLiteBlobJsonBuilder(name);
}

//#endregion
exports.SQLiteBigInt = SQLiteBigInt;
exports.SQLiteBigIntBuilder = SQLiteBigIntBuilder;
exports.SQLiteBlobBuffer = SQLiteBlobBuffer;
exports.SQLiteBlobBufferBuilder = SQLiteBlobBufferBuilder;
exports.SQLiteBlobJson = SQLiteBlobJson;
exports.SQLiteBlobJsonBuilder = SQLiteBlobJsonBuilder;
exports.blob = blob;
//# sourceMappingURL=blob.cjs.map

SHA-256: da05a05d8e4dd8c6d3b230a619449a92b3d2b956a0d4103dde9e90fed357e303