当前位置:网站首页>egg-sequelize JS编写
egg-sequelize JS编写
2022-07-26 04:20:00 【YY小怪兽】
1.安装Egg脚手架
npm i egg-init -g
2.通过脚手架创建Egg TS项目
egg-init xxx(项目名称) --type=ts
cd xxx
npm install
3.安装egg-requelize(当前安装的为js版本)
npm install --save egg-sequelize mysql2
4.在 config/plugin.js中引入 egg-sequelize 插件
exports.sequelize = {
enable: true,
package: 'egg-sequelize',
};
ts项目为config/plugin.ts
sequelize: {
enable: true,
package: 'egg-sequelize',
}
4.在 config/config.local.ts 中编写 sequelize 配置
config.sequelize = {
dialect: 'mysql',
host: '127.0.0.1',
username: 'root',
password: '',
port: 3306,
database: 'it666',
};
ts项目为config/config.local.ts
config.sequelize = {
dialect: 'mysql',
host: '127.0.0.1',
username: 'root',
password: '',
port: 3306,
database: 'it666',
};
5.在app目录下创建model目录,在model目录下创建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目录下的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.终端运得到数据库中users表的全部数据
npm run dev
边栏推荐
- Acwing game 61 [End]
- Matrix and Gauss elimination [matrix multiplication, Gauss elimination, solving linear equations, solving determinants] the most detailed in the whole network, with examples and sister chapters of 130
- Yadi started to slow down after high-end
- Firewall command simple operation
- Luoda development - audio stream processing - AAC / loopbacktest as an example
- Yuansaka Lin wallpaper
- Small ball and box model, arrangement and combination
- 1. Mx6u system migration-6-uboot graphical configuration
- Educational Codeforces Round 132 (Rated for Div. 2) E. XOR Tree
- Life related -- the heartfelt words of a graduate tutor of Huake (mainly applicable to science and Engineering)
猜你喜欢

Design and implementation of smart campus applet based on cloud development

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

Life related - ten years of career experience (turn)

1. Mx6u-alpha development board (main frequency and clock configuration experiment)

解析Steam教育的课程设计测评体系

Pathmatchingresourcepatternresolver parsing configuration file resource file

MySQL - multi table query - Cartesian product sum, correct multi table query, equivalent connection and unequal connection, inner connection and outer connection

支持代理直连Oracle数据库,JumpServer堡垒机v2.24.0发布

Support proxy direct connection to Oracle database, jumpserver fortress v2.24.0 release

TIA botu WinCC Pro controls the display and hiding of layers through scripts
随机推荐
How to write the summary? (including 7 easily ignored precautions and a summary of common sentence patterns in 80% of review articles)
This article takes you to graph transformers
Luoda development - audio stream processing - AAC / loopbacktest as an example
How engineers treat open source -- the heartfelt words of an old engineer
Tutorial on using the one click upgrade function of the rtsp/onvif protocol video platform easynvr service
规则引擎Drools的使用
Go plus security: an indispensable security ecological infrastructure for build Web3
Wu Enda's machine learning after class exercises - logical regression
Getting started with mongodb Basics
生活相关——一个华科研究生导师的肺腑之言(主要适用于理工科)
Credit card fraud detection based on machine learning
Share | 2022 big data white paper of digital security industry (PDF attached)
Web测试方法大全
Acwing_ 12. Find a specific solution for the knapsack problem_ dp
How to write the abbreviation of the thesis?
When you try to delete all bad code in the program | daily anecdotes
Use of rule engine drools
Write a paper for help, how to write the discussion part?
Firewall command simple operation
匿名函数的作用