PrismaAdapter
Database adapter for Prisma ORM - works with PostgreSQL, MySQL, SQLite, MongoDB, SQL Server, and CockroachDB.
Import
import { PrismaAdapter } from '@gluonic/server-prisma'Signature
function PrismaAdapter(config: PrismaAdapterConfig): DatabaseAdapterParameters
config: PrismaAdapterConfig
| Property | Type | Required | Description |
|---|---|---|---|
prisma | PrismaClient | Yes | Prisma client instance |
autoDiscover | AutoDiscoverConfig | No | Auto-discover models from schema |
models | ModelConfigMap | No | Manual model configuration |
serialization | SerializationConfig | No | Field serialization rules |
autoDiscover: AutoDiscoverConfig
| Property | Type | Default | Description |
|---|---|---|---|
enabled | boolean | - | Enable auto-discovery |
ownershipFields | string[] | ['userId'] | Fields to check for ownership |
versionField | string | 'version' | Field for versioning |
exclude | string[] | [] | Models to skip |
Examples
Auto-Discovery (Recommended)
const database = PrismaAdapter({
prisma,
autoDiscover: {
enabled: true,
ownershipFields: ['userId', 'orgId'],
versionField: 'version',
exclude: ['Session', '_prisma_migrations']
}
})Manual Configuration
const database = PrismaAdapter({
prisma,
models: {
user: {
ownership: 'userId',
versioning: 'version'
},
post: {
ownership: 'userId',
versioning: 'version',
batchIndexKeys: ['authorId', 'categoryId']
},
tag: {
// Public model (no ownership)
versioning: 'version'
}
}
})With Custom Serialization
const database = PrismaAdapter({
prisma,
autoDiscover: { enabled: true },
serialization: {
dateFields: ['createdAt', 'updatedAt', 'publishedAt'],
bigIntFields: ['timestamp'],
exclude: ['password', 'secretKey']
}
})See Also
- SyncServer - Server configuration
- Database Adapters Guide - Full guide
- Custom Adapters - Build your own
Last updated on