toSqlite (db/serialize.ts)

the-engineer · src/db/serialize.ts · typescript · MIT
database

Utility functions to convert JS values to SQLite bindable types and back.

// Source: https://github.com/FarzamMohammadi/the-engineer | License: MIT | Copyright 2026 Farzam Mohammadi
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * Shared SQLite serialization utilities.
 *
 * better-sqlite3 only accepts: number, string, bigint, Buffer, null.
 * These helpers centralize the conversion between JS types and SQLite-bindable
 * values so every component uses the same safe patterns.
 */

// ── Types ──────────────────────────────────────────────────────────────────

/** SQLite column type with semantic boolean distinction. */
export type SqliteColumnType = "text" | "integer" | "boolean" | "real" | "json";

/** The value types better-sqlite3 actually accepts for parameter binding. */
export type SqliteBindable = string | number | bigint | Buffer |

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key