@adminjs/mikroorm

中文文档
4.1.0发布于 2025/09/24MITTypeScriptESM + CJS零依赖近 30 天下载 3770

MikroORM adapter for AdminJS

原始使用文档
文档目录10 节
  1. adminjs-mikroorm
  2. Installation
  3. Usage
  4. Example
  5. Associations
  6. Contribution
  7. Running the example app
  8. Pull request
  9. License
  10. About rst.software

adminjs-mikroorm

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

Installation

yarn

$ yarn add @adminjs/mikroorm

npm

$ npm i @adminjs/mikroorm

Usage

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

import { Database, Resource } from '@adminjs/mikroorm';
import AdminJS from 'adminjs';
import { validate } from 'class-validator';

const setupAdminJs = async () => {
  const orm = await MikroORM.init({
    entities: [User],
    dbName: process.env.DATABASE_NAME,
    type: 'postgresql',
    clientUrl: process.env.DATABASE_URL,
  });

  // If your entities use `class-validator` to validate data, you can inject it's validate method into the resource.
  Resource.validate = validate;
  AdminJS.registerAdapter({ Database, Resource });

  // You can instantiate AdminJS either by specifying all resources separately:
  const adminJs = new AdminJS({
    resources: [{ resource: { model: User, orm }, options: {} }],
  });

  // Or by passing your ORM instance into `databases` property.
  const adminJs = new AdminJS({
    databases: [orm],
  });
  // You should choose to use either `resources` or `databases`
};

Example

An example project can be found in example-app directory.

Associations

Currently only ManyToOne and OneToOne relationships are supported due to current AdminJS's core limitations for adapter integrations. OneToMany and ManyToMany relationships can still be achieved through a combination of custom components and hooks.

Contribution

Running the example app

If you want to set this up locally this is the suggested process:

  1. Fork the repo
  2. Install dependencies
yarn install
  1. Register this package as a linked package
yarn link
  1. Setup example app

Install all dependencies and use previously linked version of @adminjs/mikroorm.

cd example-app
yarn install
yarn link "@adminjs/mikroorm"

Optionally you might want to link your local version of adminjs package

  1. Make sure you have all the envs set (see ./example-app/example.env and create an .env file based on that)

  2. Build the package in watch mode

(in the root folder)

yarn dev
  1. Run the app in the dev mode
cd example-app
yarn dev

Pull request

Before you make a PR make sure all tests pass and your code wont causes linter errors. You can do this by running:

yarn lint
yarn test

Make sure you have an .env file in project's root directory for the test runner to use:

DATABASE_URL=postgres://postgres:@localhost:5433/mikroorm_test
DATABASE_NAME=mikroorm_test

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/mikroorm 共发布 8 个版本,首次发布于 2021/10/22;过去 12 个月发布了 0 个版本。

版本发布日期距今
4.1.0latest2025/09/241.1 年前
4.0.02024/03/052 年前
3.0.02023/04/183 年前
3.0.0-beta.1beta2023/03/203 年前
2.0.02022/07/134 年前
1.1.22022/06/234 年前

关于 @adminjs/mikroorm 的常见问题

@adminjs/mikroorm 是什么?

MikroORM adapter for AdminJS

如何安装 @adminjs/mikroorm?

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

@adminjs/mikroorm 支持 TypeScript 吗?

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

@adminjs/mikroorm 支持 ESM 还是 CommonJS?

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

@adminjs/mikroorm 可以商用吗?

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

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

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

@adminjs/mikroorm 还在维护吗?

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