New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@midwayjs/orm

Package Overview
Dependencies
Maintainers
7
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@midwayjs/orm

## How to use

latest
Source
npmnpm
Version
3.4.3
Version published
Weekly downloads
228
-28.53%
Maintainers
7
Weekly downloads
 
Created
Source

midway orm component

How to use

in Configuration.ts file

import * as orm from '@midwayjs/orm';
import { join } from 'path';

@Configuration({
  imports: [
    orm,
  ],
  importConfigs: [
    join(__dirname, './config')
  ]
})
export class ContainerConfiguration {
}

Configuration

in config files

export default {
  orm: {
    type: 'mysql',
    host: '',
    port: 3306,
    username: '',
    password: '',
    database: undefined,
    synchronize: true,
    logging: false,
 }
};

or

export const orm = {
  type: 'sqlite',  // or use mysql see typeorm docs
  database: join(__dirname, './test.sqlite'),
  logging: true,
}

Define EntityModel

// model/user.ts
import { EntityModel } from '@midwayjs/orm';
import { PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm';

@EntityModel('test_user')
export class Photo {
  @PrimaryGeneratedColumn({ name: "id" })
  id: number;

  @Column({ name: "name" })
  name: string;

  @OneToMany(type => Message, message => message.sender)
  messages: Message[];
}

Use Model

in code files

import { InjectEntityModel } from '@midwayjs/orm';
import { User } from './model/user';
import { Repository } from 'typeorm';

@Provide()
export class UserService {

  @InjectEntityModel(User)
  userModel: Repository<User>;

  async testUser() {
    const u = new User();
    u.name = 'oneuser1';
    const uu = await this.userModel.save(u);
    console.log('user one id = ', uu.id);

    const user = new User();
    user.id = 1;
    const users = await this.userModel.findAndCount(user);
    return 'hello world' + JSON.stringify(users);
  }
}

FAQs

Package last updated on 21 Jul 2022

Did you know?

Socket

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