@bight-ts/storage-drizzle
import { createDrizzleStorageAdapter, createSqliteStorageTables, createPostgresStorageTables, createMysqlStorageTables,} from "@bight-ts/storage-drizzle";createDrizzleStorageAdapter(options)
Section titled “createDrizzleStorageAdapter(options)”Creates a StorageAdapter that persists Bight state in Drizzle-managed SQL tables.
DrizzleStorageAdapterOptions
Section titled “DrizzleStorageAdapterOptions”| Property | Type | Required | Description |
|---|---|---|---|
db | Drizzle database instance | Yes | Your Drizzle DB client |
tables | { globalConfigs, guildConfigs } | Yes | Table references (from the helpers below) |
serialize | (value: StorageValue) => string | No | Custom serializer. Defaults to JSON.stringify |
deserialize | (value: string) => StorageValue | No | Custom deserializer. Defaults to JSON.parse |
Table helpers
Section titled “Table helpers”Each helper creates two Drizzle tables: global_configs (key → value) and guild_configs (guild_id → value).
| Function | SQL dialect | Column types |
|---|---|---|
createSqliteStorageTables(prefix?) | SQLite | TEXT |
createPostgresStorageTables(prefix?) | PostgreSQL | TEXT |
createMysqlStorageTables(prefix?) | MySQL | VARCHAR(191) for keys, TEXT for values |
The optional prefix argument namespaces table names: createPostgresStorageTables("bight") creates bight_global_configs and bight_guild_configs.
Behavior
Section titled “Behavior”- Values are serialized as JSON strings into the
valuecolumn. - Upserts use
onConflictDoUpdate(SQLite/Postgres) oronDuplicateKeyUpdate(MySQL).