zoukankan      html  css  js  c++  java
  • egg 使用手记(一)

    1. 文件加载规则

    引用官方的说法:

    框架在加载文件时会进行转换,因为文件命名风格和 API 风格存在差异。我们推荐文件使用下划线,而 API 使用驼峰。比如 app/service/user_info.js 会转换成 app.service.userInfo

    框架也支持连字符和驼峰的方式

    • app/service/user-info.js => app.service.userInfo
    • app/service/userInfo.js => app.service.userInfo

    Loader 还提供了 caseStyle 强制指定首字母大小写,比如加载 model 时 API 首字母大写,app/model/user.js=> app.model.User,就可以指定 caseStyle: 'upper'

    *** controller、service 文件加载 小驼峰对应文件名而不是类名,model 文件加载 大驼峰对应文件名而不是类名 ***

    2. egg-sequelize

     1 'use strict';
     2 const snowflake = require('node-snowflake').Snowflake;
     3 
     4 module.exports = app => {
     5   const { STRING, INTEGER, DATE } = app.Sequelize;
     6 
     7   const SysUser = app.model.define(
     8     'sys_user',
     9     {
    10       id: {
    11         type: STRING(36),
    12         primaryKey: true,
    13         defaultValue: snowflake.nextId(),
    14       },
    15       createBy: { type: STRING(36), field: 'create_by' },
    16       createDate: { type: DATE, field: 'create_date' },
    17       updateBy: { type: STRING(36), field: 'update_by' },
    18       updateDate: { type: DATE, field: 'update_date' },
    19       enableFlag: { type: INTEGER, defaultValue: '1', field: 'enable_flag' },
    20       rules: STRING,
    21       userName: { type: STRING, field: 'user_name' },
    22       passWord: { type: STRING, field: 'pass_word' },
    23       notes: STRING,
    24       userCode: { type: STRING, field: 'user_code' },
    25       lastLoginTime: { type: STRING, field: 'last_login_time' },
    26     },
    27     {
    28       timestamps: false,
    29       freezeTableName: true,
    30       underscored: false,
    31       createdAt: 'create_date',
    32       updatedAt: 'update_date',
    33     }
    34   ); // underscored:不使用驼峰样式自动添加属性,而是下划线样式 [ createdAt => created_at ]
    35   // timestamps:去除createAt updateAt
    36   // freezeTableName : 使用自定义表名,
    37 
    38   return SysUser;
    39 };
    field:数据库字段名
    defaultValue:默认值


      

  • 相关阅读:
    杭电ACM 2052 Picture
    杭电ACM求平均成绩
    杭电ACM水仙花数
    cigarettes
    分数加减法
    推荐几个sql server牛人的博客
    npm 介绍
    centos Flash Player插件的安装
    node.js学习(1)
    查询功能:yum [list|info|search|provides|whatprovides] 参数
  • 原文地址:https://www.cnblogs.com/sephiroth-wzc/p/10106584.html
Copyright © 2011-2022 走看看