@adminjs/ sql (英语)
这是SQL数据库的官方AdminJS适配器. 它不要求您使用任何ORM,而是只提供数据库连接,并且使用AdminJS配置来模拟数据源.
支持的数据库 :
- 邮递SQL
- MySQL 数据
- 马上就要来了
这个适配器的灵感很大 有线康的管理员 它是 MySQL 数据库的非官方适配器.
安装
$ yarn add @adminjs/sql
用快车
以下实例显示使用 @adminjs/express。使用 Adapter 课程需要解析数据库的图案.
import AdminJS from 'adminjs'
import express from 'express'
import Plugin from '@adminjs/express'
import Adapter, { Database, Resource } from '@adminjs/sql'
AdminJS.registerAdapter({
Database,
Resource,
})
const start = async () => {
const app = express()
const db = await new Adapter('postgresql', {
connectionString: '<your database connection string>', // postgresql://[user]:[password]@[netloc]:[port]/[dbname]
database: '<your database name>',
}).init();
const admin = new AdminJS({
resources: [
{
resource: db.table('users'),
options: { /* any resource options, rbac, etc */ },
},
],
// databases: [db] <- you can also provide the DB connection to register all tables at once
});
admin.watch()
const router = Plugin.buildRouter(admin)
app.use(admin.options.rootPath, router)
app.listen(8080, () => {
console.log('app started')
})
}
start()
数据库关系
目前仅 many-to-one 如果您在数据库中指定了外国密钥限制,则关系会在框外工作。 其他关系需要您进行UI/后端定制. 请看我们的 文档 学习更多.
数字
截至版本 1.0.0 数据库中未自动检测和装入。 您可以在资源选项中手动分配 :
// ...
const admin = new AdminJS({
resources: [{
resource: db.table('users'),
options: {
properties: {
role: {
availableValues: [
{ label: 'Admin', value: 'ADMIN' },
{ label: 'Client', value: 'CLIENT' },
],
},
},
},
}],
})
// ...
时间戳
如果您的数据库表格自动带有默认设置的时间戳( E)created_at, (中文(简体) ), updated_at等)它们默认会在创建/编辑形式中可见. 您可以将它们隐藏在资源选项中 :
// ...
const admin = new AdminJS({
resources: [{
resource: db.table('users'),
options: {
properties: {
created_at: { isVisible: false },
},
},
}],
})
// ...
许可证
AdminJS拥有2023rst.software的版权. 它是一种自由软件,可按下列规定重新分配: 自由主义 文档.
关于 rst. 软件
我们是一个开放、友好的团队.