Socket
Socket
Sign inDemoInstall

@aex/typeorm

Package Overview
Dependencies
260
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @aex/typeorm

typeorm


Version published
Maintainers
1
Install size
22.9 MB
Created

Readme

Source

Build Status Coverage Status MIT license

@aex/typeorm

Aex middleware for typeorm.

Usage

Prepare models

# ./models
├── Photo.ts
└── User.ts

Photo.ts:

import {BaseEntity, Column, Entity, PrimaryGeneratedColumn} from "typeorm";

@Entity()
export class Photo extends BaseEntity {

    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    name: string;

    @Column()
    description: string;

    @Column()
    filename: string;

    @Column()
    views: number;

    @Column()
    isPublished: boolean;
}

User.ts

import { BaseEntity, Column, Entity, PrimaryGeneratedColumn } from "typeorm";

@Entity()
export class User extends BaseEntity {

  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  firstName: string;

  @Column()
  lastName: string;

  @Column()
  age: number;

}

Create a Aex middleware for typeorm

import { createTypeorm } from "@aex/typeorm";
const options = {
  database: path.resolve(__dirname, "./store/project.db"),
  synchronize: true,
  type: "sqlite"
};
const middleware = await createTypeorm("./models/", options);

Add the middleware to aex

const aex = new Aex();
aex.use(middleware);

Use typeorm in the subsequence middlewares

aex.use(async (_req: any, res, scope: any) => {
  const { connection, models } = scope.outer.typeorm;
  const User = models.User;
  const user = new User();
  user.age = 100;
  user.firstName = "hello";
  user.lastName = "world!";
  await user.save();
  console.log(user.id);
  await connection.close();
  res.end("ok");
});

FAQs

Last updated on 19 Mar 2020

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc