当前位置:网站首页>Compiled by egg serialize JS
Compiled by egg serialize JS
2022-07-26 04:22:00 【YY little monster】
1. install Egg The scaffold
npm i egg-init -g
2. Create... Through scaffolding Egg TS project
egg-init xxx( Project name ) --type=ts
cd xxx
npm install
3. install egg-requelize( Currently installed is js edition )
npm install --save egg-sequelize mysql2
4. stay config/plugin.js Introduction in egg-sequelize plug-in unit
exports.sequelize = {
enable: true,
package: 'egg-sequelize',
};
ts The project is config/plugin.ts
sequelize: {
enable: true,
package: 'egg-sequelize',
}
4. stay config/config.local.ts Written in sequelize To configure
config.sequelize = {
dialect: 'mysql',
host: '127.0.0.1',
username: 'root',
password: '',
port: 3306,
database: 'it666',
};
ts The project is config/config.local.ts
config.sequelize = {
dialect: 'mysql',
host: '127.0.0.1',
username: 'root',
password: '',
port: 3306,
database: 'it666',
};
5. stay app Create under directory model Catalog , stay model Create under directory user.ts
'use strict';
module.exports = app => {
const {
STRING, INTEGER, DATE } = app.Sequelize;
const User = app.model.define('user', {
id: {
type: INTEGER, primaryKey: true, autoIncrement: true },
name: STRING(30),
age: INTEGER,
created_at: DATE,
updated_at: DATE,
});
return User;
};
6.control In the catalog home.ts
import {
Controller } from 'egg';
export default class HomeController extends Controller {
public async index() {
const {
ctx } = this;
// ctx.body = await ctx.service.test.sayHi('egg');
ctx.body = await ctx.model.User.findAll();
}
}
7. The terminal is transported to the database users All the data in the table
npm run dev
边栏推荐
- Huawei issued another global convening order of "genius youth", and some people once gave up their annual salary of 3.6 million to join
- Life related -- the heartfelt words of a graduate tutor of Huake (mainly applicable to science and Engineering)
- 测试用例设计方法之——招式组合,因果判定
- Web Test Method Encyclopedia
- Firewall command simple operation
- 力扣每日一题-第42天-661. 图片平滑器
- Unable to find sygwin.s file during vscode debugging
- Write a paper for help, how to write the discussion part?
- What are the duplicate check rules for English papers?
- 机器学习之桑基图(用于用户行为分析)
猜你喜欢

Helloworld案例分析

Acwing_ 12. Find a specific solution for the knapsack problem_ dp

第三篇如何使用SourceTree提交代码

Pathmatchingresourcepatternresolver parsing configuration file resource file

What are the consequences and problems of computer system restoration

Leetcode:1184. Distance between bus stops -- simple

How does win11 change the power mode? Win11 method of changing power mode

When you try to delete all bad code in the program | daily anecdotes

吴恩达机器学习课后习题——逻辑回归

How does win11 set the theme color of the status bar? Win11 method of setting theme color of status bar
随机推荐
香甜的黄油
Function knowledge points
Unable to find sygwin.s file during vscode debugging
[project chapter - how to write and map the business model? (3000 word graphic summary suggestions)] project plan of innovation and entrepreneurship competition and application form of national Entrep
Wu Enda's machine learning after class exercises - logical regression
The difference between positive samples, negative samples, simple samples and difficult samples in deep learning (simple and easy to understand)
理性认知教育机器人寓教于乐的辅助作用
Recommendation | DBT skills training manual: baby, you are the reason why you live
当你尝试删除程序中所有烂代码时 | 每日趣闻
TIA botu WinCC Pro controls the display and hiding of layers through scripts
Small ball and box model, arrangement and combination
吴恩达机器学习课后习题——线性回归
【SVN】一直出现 Please execute the ‘Cleanup‘ command,cleanup以后没有反应的解决办法
图互译模型
规则引擎Drools的使用
机器学习之信用卡欺诈检测
Tutorial on using the one click upgrade function of the rtsp/onvif protocol video platform easynvr service
What model is good for the analysis of influencing factors?
Design and implementation of smart campus applet based on cloud development
What are the consequences and problems of computer system restoration