Skip to content

@bight-ts/storage-drizzle

import {
createDrizzleStorageAdapter,
createSqliteStorageTables,
createPostgresStorageTables,
createMysqlStorageTables,
} from "@bight-ts/storage-drizzle";

Creates a StorageAdapter that persists Bight state in Drizzle-managed SQL tables.

PropertyTypeRequiredDescription
dbDrizzle database instanceYesYour Drizzle DB client
tables{ globalConfigs, guildConfigs }YesTable references (from the helpers below)
serialize(value: StorageValue) => stringNoCustom serializer. Defaults to JSON.stringify
deserialize(value: string) => StorageValueNoCustom deserializer. Defaults to JSON.parse

Each helper creates two Drizzle tables: global_configs (key → value) and guild_configs (guild_id → value).

FunctionSQL dialectColumn types
createSqliteStorageTables(prefix?)SQLiteTEXT
createPostgresStorageTables(prefix?)PostgreSQLTEXT
createMysqlStorageTables(prefix?)MySQLVARCHAR(191) for keys, TEXT for values

The optional prefix argument namespaces table names: createPostgresStorageTables("bight") creates bight_global_configs and bight_guild_configs.

  • Values are serialized as JSON strings into the value column.
  • Upserts use onConflictDoUpdate (SQLite/Postgres) or onDuplicateKeyUpdate (MySQL).