Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@adminjs/typeorm
Advanced tools
This is an official AdminJS adapter which integrates TypeORM into AdminJS. (originally forked from Arteha/admin-bro-typeorm)
Installation: yarn add @adminjs/typeorm
The plugin can be registered using standard AdminJS.registerAdapter
method.
import { Database, Resource } from '@adminjs/typeorm'
import AdminJS from 'adminjs'
AdminJS.registerAdapter({ Database, Resource });
// Optional: if you use class-validator you have to inject this to resource.
import { validate } from 'class-validator'
Resource.validate = validate
import {
BaseEntity,
Entity, PrimaryGeneratedColumn, Column,
ManyToOne,
RelationId
} from 'typeorm'
import { MyDataSource } from './my-data-source'
import * as express from 'express'
import { Database, Resource } from '@adminjs/typeorm'
import { validate } from 'class-validator'
import AdminJS from 'adminjs'
import * as AdminJSExpress from '@adminjs/express'
Resource.validate = validate
AdminJS.registerAdapter({ Database, Resource })
@Entity()
export class Person extends BaseEntity
{
@PrimaryGeneratedColumn()
public id: number;
@Column({type: 'varchar'})
public firstName: string;
@Column({type: 'varchar'})
public lastName: string;
@ManyToOne(type => CarDealer, carDealer => carDealer.cars)
organization: Organization;
// in order be able to fetch resources in adminjs - we have to have id available
@RelationId((person: Person) => person.organization)
organizationId: number;
// For fancy clickable relation links:
public toString(): string
{
return `${firstName} ${lastName}`;
}
}
( async () =>
{
await MyDataSource.initialize();
const adminJs = new AdminJS({
// databases: [MyDataSource],
resources: [
{ resource: Person, options: { parent: { name: 'foobar' } } }
],
rootPath: '/admin',
})
const app = express()
const router = AdminJSExpress.buildRouter(adminJs)
app.use(adminJs.options.rootPath, router)
app.listen(3000)
})()
Admin supports ManyToOne relationship but you also have to define @RealationId as stated in the example above.
If you want to set this up locally this is the suggested process:
yarn install
yarn link
Install all dependencies and use previously linked version of @adminjs/typeorm
.
cd example-app
yarn install
yarn link @adminjs/typeorm
Optionally you might want to link your local version of adminjs
package
Make sure you have all the envs set (which are defined in example-app/ormconfig.js
)
Build the package in watch mode
(in the root folder)
yarn dev
cd example-app
yarn dev
Before you make a PR make sure all tests pass and your code wont causes linter errors. You can do this by running:
yarn lint
yarn test
or with proper envs: POSTGRES_USER=yourtestuser POSTGRES_DATABASE="database_test" yarn test
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
TypeORM adapter for AdminJS
The npm package @adminjs/typeorm receives a total of 4,168 weekly downloads. As such, @adminjs/typeorm popularity was classified as popular.
We found that @adminjs/typeorm 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.