Prisma
@adminjs/prisma
Last updated
// ... other imports
import { Database, Resource, getModelByName } from '@adminjs/prisma'
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
AdminJS.registerAdapter({ Database, Resource })
// ... other code
const start = async () => {
const adminOptions = {
resources: [{
resource: { model: getModelByName('Post'), client: prisma },
options: {},
}, {
resource: { model: getModelByName('Profile'), client: prisma },
options: {},
}, {
resource: { model: getModelByName('Publisher'), client: prisma },
options: {},
}],
}
// Please note that some plugins don't need you to create AdminJS instance manually,
// instead you would just pass `adminOptions` into the plugin directly,
// an example would be "@adminjs/hapi"
const admin = new AdminJS(adminOptions)
// ... other code
}
start()import { Database, Resource, getModelByName } from '@adminjs/prisma'
import AdminJS from 'adminjs'
import { PrismaService } from './prisma.service.js' // PrismaService from Nest.js documentationAdminJS.registerAdapter({ Database, Resource })// ... other imports
import { Category } from './category.entity.js'
// ... other code
AdminModule.createAdminAsync({
useFactory: () => {
// Note: Feel free to contribute to this documentation if you find a Nest-way of
// injecting PrismaService into AdminJS module
const prisma = new PrismaService()
return {
adminJsOptions: {
rootPath: '/admin',
resources: [{
resource: { model: getModelByName('Post'), client: prisma },
options: {},
}],
},
}
}
}),
// ... other code// other imports
// your custom prisma module
import PrismaModule from '../prisma/client-prisma/index.js';
// ...
const prisma = new PrismaModule.PrismaClient();
// ...
// Notice `clientModule` per resource
const admin = new AdminJS({
resources: [{
resource: {
model: getModelByName('Post', PrismaModule),
client: prisma,
clientModule: PrismaModule,
},
}],
});