Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
@adminjs/sql
Advanced tools
Readme
This is an official AdminJS adapter for SQL databases. It does not require you to use any ORMs, instead you just provide database connection and you model the data sources using AdminJS configuration.
Supported databases:
This adapter is heavily inspired by wirekang's adminjs-sql which is an unofficial adapter for a MySQL database.
$ yarn add @adminjs/sql
The example below shows usage with @adminjs/express
. The usage of Adapter
class is required to parse your database's schema.
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()
Currently only many-to-one
relation works out of the box if you specify foreign key constraints in your database. Other relations will require you to make UI/backend customizations. Please see our documentation to learn more.
As of version 1.0.0
database enums aren't automatically detected and loaded. You can assign them manually in your resource options:
// ...
const admin = new AdminJS({
resources: [{
resource: db.table('users'),
options: {
properties: {
role: {
availableValues: [
{ label: 'Admin', value: 'ADMIN' },
{ label: 'Client', value: 'CLIENT' },
],
},
},
},
}],
})
// ...
If your database tables have automatically default-set timestamps (created_at
, updated_at
, etc) they will be visible in create/edit forms by default. You can hide them in resource options:
// ...
const admin = new AdminJS({
resources: [{
resource: db.table('users'),
options: {
properties: {
created_at: { isVisible: false },
},
},
}],
})
// ...
AdminJS is copyrighted © 2023 rst.software. It is a free software, and may be redistributed under the terms specified in the LICENSE file.
We’re an open, friendly team that helps clients from all over the world to transform their businesses and create astonishing products.
FAQs
An official AdminJS adapter for SQL databases.
The npm package @adminjs/sql receives a total of 229 weekly downloads. As such, @adminjs/sql popularity was classified as not popular.
We found that @adminjs/sql demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.