@dudousxd/nestjs-media-database-mikro-orm
MikroORM media store with safe auto-schema.
A MediaStore backed by MikroORM. The store is a POJO that receives an EntityManager; each operation runs on a fork() to avoid cross-request identity-map bleed.
import { MikroOrmMediaStore, ensureMediaSchema } from '@dudousxd/nestjs-media-database-mikro-orm';
await ensureMediaSchema(orm); // orm.schema.updateSchema({ safe: true })
const store = new MikroOrmMediaStore(orm.em);
MediaModule.forRoot({ default: 's3', disks: { s3 }, store });Auto-schema
MikroORM gives non-destructive create + add-column for free via updateSchema({ safe: true }) — ensureMediaSchema(orm) is a thin wrapper over it. Run it at boot, or manage the schema with MikroORM migrations and skip it.
The entity is an EntitySchema with order mapped to a position column. JSON columns carry customProperties and conversions.
Verified by an integration suite running the store against real Postgres (testcontainers), in addition to the in-memory and sqlite unit runs.
Attachment column
For the attachment column model — a single file as a JSON value object on your entity — register the AttachmentType custom type on a property:
import { Entity, PrimaryKey, Property } from '@mikro-orm/core';
import type { Attachment } from '@dudousxd/nestjs-media-core';
import { AttachmentType } from '@dudousxd/nestjs-media-database-mikro-orm';
@Entity()
export class User {
@PrimaryKey() id!: string;
@Property({ type: AttachmentType, nullable: true })
avatar?: Attachment | null;
}AttachmentType serializes to a json column on write and rehydrates an Attachment on load — accepting both already-parsed JSON (postgres json) and string values (sqlite). The round-trip is verified against real sqlite in the package's test suite.
Peer dependencies
@mikro-orm/core (^6) and @dudousxd/nestjs-media-core — plus your driver package (@mikro-orm/postgresql, @mikro-orm/mysql, @mikro-orm/better-sqlite, …). See Concepts → Persistence and Concepts → Attachments.