@dudousxd/nestjs-media-database-drizzle
Drizzle media store (sqlite), migration-first.
A MediaStore backed by Drizzle ORM. The store is a POJO that receives your drizzle db handle.
import { DrizzleMediaStore, createMediaTable, mediaTable } from '@dudousxd/nestjs-media-database-drizzle';
createMediaTable(db); // dev/test helper — see below
MediaModule.forRoot({ default: 's3', disks: { s3 }, store: new DrizzleMediaStore(db) });Migration-first
Drizzle is migration-first by design — there's no runtime auto-schema. In production you manage the table with drizzle-kit using the exported mediaTable schema; createMediaTable(db) is a convenience for tests and quick dev setups that issues the CREATE TABLE IF NOT EXISTS.
sqlite-first by design
Drizzle's schema is dialect-specific (sqliteTable vs pgTable vs mysqlTable), so this adapter ships the sqlite/libSQL schema — matching the ecosystem's other Drizzle adapters (e.g. durable-store-drizzle). For Postgres/MySQL, define the equivalent table with that dialect's drizzle core and pass it; the store's query logic (insert/onConflictDoUpdate/select/orderBy) is the same.
Attachment column
For the attachment column model — a single file as a JSON value object on your own table — use the attachment() custom column:
import { sqliteTable, text } from 'drizzle-orm/sqlite-core';
import { attachment } from '@dudousxd/nestjs-media-database-drizzle';
export const users = sqliteTable('users', {
id: text('id').primaryKey(),
avatar: attachment('avatar'), // Attachment | null, stored as JSON text
});On write it JSON.stringifys the Attachment (or stores null); on read it rehydrates an Attachment. Like the media store, the column is sqlite/libSQL — for Postgres/MySQL define the equivalent JSON column in that dialect and (de)serialize with the value object's toJSON() / Attachment.fromJSON().
Peer dependencies
drizzle-orm (^0.38) and @dudousxd/nestjs-media-core, plus a driver (better-sqlite3, libsql, …). See Concepts → Persistence and Concepts → Attachments.