npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

adminjs-typeorm-ows

v2.0.1

Published

TypeORM adapter for AdminJS

Downloads

27

Readme

adminjs-typeorm

This is an official AdminJS adapter which integrates TypeORM into AdminJS. (originally forked from Arteha/admin-bro-typeorm)

Installation: yarn add @adminjs/typeorm

Usage

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

Example

import {
  BaseEntity,
  Entity, PrimaryGeneratedColumn, Column,
  createConnection,
  ManyToOne,
  RelationId
} from 'typeorm'
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 () =>
{
  const connection = await createConnection({/* ... */})

  // Applying connection to model
  Person.useConnection(connection)

  const adminJs = new AdminJS({
    // databases: [connection],
    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)
})()

ManyToOne

Admin supports ManyToOne relationship but you also have to define @RealationId as stated in the example above.

Contribution

Running the example app

If you want to set this up locally this is the suggested process:

  1. fork the repo
  2. Install dependencies
yarn install
  1. register this package as a (linked package)[https://classic.yarnpkg.com/en/docs/cli/link/]
yarn link
  1. Setup example app

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

  1. Make sure you have all the envs set (which are defined in example-app/ormconfig.js)

  2. Build the package in watch mode

(in the root folder)

yarn dev
  1. run the app in the dev mode
cd example-app
yarn dev

Pull request

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