Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@adminjs/sql
Advanced tools
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 631 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 0 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.