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/sequelize as described in Getting started section.
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 AdminJSSequelize adapter and register it
You must import the entities you want to use and pass them to AdminJS resources options
app.ts
// ... other importsimport*as AdminJSSequelize from'@adminjs/sequelize'import { Category } from'./category.entity.js'AdminJS.registerAdapter({ Resource:AdminJSSequelize.Resource, Database:AdminJSSequelize.Database,})// ... other codeconststart=async () => {constadminOptions= {// We pass Category to `resources` resources: [Category], }// 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"constadmin=newAdminJS(adminOptions)// ... other code}start()
Your app.module.ts should have imports option which contains:
SequelizeModule.forRoot({ uri: '...', dialect: '...' }) to set up Sequelize
AdminModule.createAdminAsync({ ... }
You should also be able to get Sequelize to work if you set it up using a Nest.js database provider. The main point is to have a database connection established before AdminJS is initialized.
In your app.module.ts add these imports at the top of the file:
This will allow you to pass Sequelize models for AdminJS to load. If we use the Category entity that we used as en example earlier, you should import it into app.module.ts and pass it into resources in your adminJsOptions:
app.module.ts
// ... other importsimport { Category } from'./category.entity.js'// ... other codeAdminModule.createAdminAsync({useFactory: () => ({ adminJsOptions: { rootPath:'/admin', resources: [Category], }, }),}),// ... other code