@adminjs/prisma

中文文档
5.0.4发布于 2025/06/18MITTypeScriptESM + CJS零依赖近 30 天下载 6.5万

Prisma adapter for AdminJS

原始使用文档
文档目录10 节
  1. adminjs-prisma
  2. Installation
  3. Usage
  4. Example (Basic)
  5. Example (Custom Client Output Path)
  6. ManyToOne / ManyToMany
  7. Pull request
  8. Running example app with local code modifications
  9. License
  10. About rst.software

adminjs-prisma

This is an official AdminJS adapter which integrates Prisma into AdminJS.

Installation

  • yarn: yarn add @adminjs/prisma

  • npm: npm install @adminjs/prisma

Usage

The plugin can be registered using standard AdminJS.registerAdapter method.

import { Database, Resource } from '@adminjs/prisma'
import AdminJS from 'adminjs'

AdminJS.registerAdapter({ Database, Resource })

Example (Basic)

Whole code can be found in example-app directory in the repository.

import express from 'express'
import AdminJS from 'adminjs'
import AdminJSExpress from '@adminjs/express'
import { Database, Resource, getModelByName } from '@adminjs/prisma'
import { PrismaClient } from '@prisma/client'
import { DMMFClass } from '@prisma/client/runtime'

const PORT = process.env.port || 3000

const prisma = new PrismaClient()

AdminJS.registerAdapter({ Database, Resource })

const run = async () => {
  const app = express()

  const admin = new AdminJS({
    resources: [{
      resource: { model: getModelByName('Post'), client: prisma },
      options: {},
    }, {
      resource: { model: getModelByName('Profile'), client: prisma },
      options: {},
    }, {
      resource: { model: getModelByName('Publisher'), client: prisma },
      options: {},
    }],
  })

  const router = AdminJSExpress.buildRouter(admin)

  app.use(admin.options.rootPath, router)

  app.listen(PORT, () => {
    console.log(`Example app listening at http://localhost:${PORT}`)
  })
}

run()
  .finally(async () => {
    await prisma.$disconnect()
  })

Example (Custom Client Output Path)

If you defined a custom client output path in your Prisma's schema, for example:

generator client {
  provider = "prisma-client-js"
  output = "./client-prisma"
}

You must:

  • import your custom Prisma client
  • provide it to each resource which uses that Prisma client

Example:

// other imports
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 },
    options: {
      properties: {
        someJson: { type: 'mixed', isArray: true },
        'someJson.number': { type: 'number' },
        'someJson.string': { type: 'string' },
        'someJson.boolean': { type: 'boolean' },
        'someJson.date': { type: 'datetime' },
      },
    },
  }, {
    resource: { model: getModelByName('Profile', PrismaModule), client: prisma, clientModule: PrismaModule },
    options: {},
  }, {
    resource: { model: getModelByName('Publisher', PrismaModule), client: prisma, clientModule: PrismaModule },
    options: {},
  }],
});

// ...

ManyToOne / ManyToMany

These relationships are currently not supported by default. You can manage them using custom actions and components.

Pull request

Before you make a PR make sure all tests pass and your code won't cause linter errors. You can do this by running:

yarn lint
yarn test

Make sure you have an .env file with DATABASE_URL specified.

Running example app with local code modifications

MySQL database is required. You can use the database from adminjs-example-app: https://github.com/SoftwareBrothers/adminjs-example-app/blob/master/docker-compose.yaml#L24

$ yarn
$ yarn build                  # after making changes or run "yarn dev" and open a new terminal for next command
$ yarn link
$ cd example-app
$ yarn
$ npx prisma generate
$ npx prisma migrate dev

Now copy example-app/node_modules/.prisma folder into node_modules/.prisma. This is required because installing library dependencies detects a different Prisma schema in test folder.

Continue in example-app folder:

$ yarn link "@adminjs/prisma"
$ yarn build
$ yarn start

The app should start at port 3000.

License

AdminJS is copyrighted © 2023 rst.software. It is a free software, and may be redistributed under the terms specified in the LICENSE file.

About rst.software

We’re an open, friendly team that helps clients from all over the world to transform their businesses and create astonishing products.

  • We are available for hire.
  • If you want to work for us - check out the career page.

版本与发布记录

@adminjs/prisma 共发布 17 个版本,首次发布于 2021/10/15;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.0.4latest2025/06/181.4 年前
5.0.32024/02/122 年前
5.0.22024/02/062 年前
5.0.12023/07/243 年前
5.0.02023/07/183 年前
4.0.12023/07/123 年前

其他发布通道:beta → 4.0.0-beta.1。

关于 @adminjs/prisma 的常见问题

@adminjs/prisma 是什么?

Prisma adapter for AdminJS

如何安装 @adminjs/prisma?

在项目目录运行 npm install @adminjs/prisma,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@prisma/client(^5.0.0 || ^6.0.0)、adminjs(^7.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@adminjs/prisma 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@adminjs/prisma 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@adminjs/prisma 可以商用吗?

@adminjs/prisma 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@adminjs/prisma 的下载量有多少?

根据 npm 官方下载统计,@adminjs/prisma 在 2026/10/05 – 2026/11/03 这 30 天内被下载 64,906 次,日均约 2,164 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adminjs/prisma 还在维护吗?

最新版本 5.0.4 发布于 2025/06/18(1.4 年前);至今共发布 17 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/10/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。