entity

数据库模型实体,以typeorm为例。 在根目录下创建entity文件夹,在文件夹下面创建user.js文件:

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

@Entity()
class User extends BaseEntity {

    @PrimaryGeneratedColumn()
    id = undefined;

    @Column('varchar')
    name = '';
  
}

module.exports = User;

common/orm.js配置连接:

'use strict';

const typeorm = require('typeorm');

(async () => {
  console.log('create connection');
  await typeorm.createConnection();
})();

在启动入口文件引入:

require('./common/orm');

使用:

// server/user.js

async users() {
  const {user} = this.app.entity;
  return user.find();
}
Last Updated: 11/13/2018, 2:21:20 AM