TypeORM
@adminjs/typeorm
Before reading this article, make sure you have set up an AdminJS instance using one of the supported Plugins.
Additionally, you should have installed @adminjs/typeorm
as described in Getting started section.
This guide will assume you have set up TypeORM using it's documentation or Nest.js documentation.
@adminjs/typeorm
currently only supports entities that extend BaseEntity
as shown on the example below:
There are small differences in how you connect TypeORM to Nest.js vs other plugins, so the guide will be split into two sections accordingly.
Standard
Make sure you have followed the tutorial for the framework you are using in the Plugins section.
The configuration for non-Nest.js plugins is basically the same for each one of them:
You must import the data source and initialize it
You must import
AdminJSTypeorm
adapter and register itYou must import the entities you want to use and pass them to AdminJS
resources
options
Nest.js
Make sure you have set up your app.module.ts
according to Nest.js documentation and you have followed Nest.js plugin tutorial as well.
Your app.module.ts
should have imports
option which contains:
TypeOrmModule.forRoot(params)
to set up TypeORMAdminModule.createAdminAsync({ ... }
In your app.module.ts
add these imports at the top of the file:
Following this, register AdminJSTypeorm
adapter somewhere after your imports:
This will allow you to pass TypeORM models for AdminJS to load. If we use the Organization
entity that we used as en example earlier, you should import it into app.module.ts
and pass it into resources
in your adminJsOptions
:
Last updated