Skip to Content
ReferenceServer APIPrismaAdapter

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): DatabaseAdapter

Parameters

config: PrismaAdapterConfig

PropertyTypeRequiredDescription
prismaPrismaClientYesPrisma client instance
autoDiscoverAutoDiscoverConfigNoAuto-discover models from schema
modelsModelConfigMapNoManual model configuration
serializationSerializationConfigNoField serialization rules

autoDiscover: AutoDiscoverConfig

PropertyTypeDefaultDescription
enabledboolean-Enable auto-discovery
ownershipFieldsstring[]['userId']Fields to check for ownership
versionFieldstring'version'Field for versioning
excludestring[][]Models to skip

Examples

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

Last updated on