当前位置:网站首页>egg-ts-sequelize-CLI
egg-ts-sequelize-CLI
2022-07-26 04:22:00 【YY little monster】
Details visible
1. install sequelize-cli
npm install sequelize-cli
2. Write... In the project root directory .sequelizerc The configuration file
'use strict';
const path = require('path');
module.exports = {
config: path.join(__dirname, 'database/config.json'),
'migrations-path': path.join(__dirname, 'database/migrations'),
'seeders-path': path.join(__dirname, 'database/seeders'),
'models-path': path.join(__dirname, 'app/model'),
};
3. Initialize configuration file
npx sequelize init:config
4. Modify the configuration file database/config.json
Set up the database as required At present, because it is the development stage, only the development stage is set , If you need anything else, modify
development: The development phase
test: Testing phase
production: Go live
{
"development": {
"username": "root",
"password": "",
"database": "it666",
"host": "127.0.0.1",
"dialect": "mysql"
},
"test": {
"username": "root",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
},
"production": {
"username": "root",
"password": null,
"database": "database_production",
"host": "127.0.0.1",
"dialect": "mysql"
}
}
5. Initialize the configuration directory
npx sequelize init:migrations
6. create profile
npx sequelize migration:generate --name=users
7. Modify the migration file to TS grammar Directly modifying database/migration Created under js Rename file to .ts file
'use strict';
import {
QueryInterface } from 'sequelize';
module.exports = {
// Functions called during database upgrade , establish users surface
up: async (queryInterface:QueryInterface, Sequelize) => {
const {
INTEGER, DATE, STRING } = Sequelize;
await queryInterface.createTable('users', {
id: {
type: INTEGER, primaryKey: true, autoIncrement: true },
name: STRING(30),
age: INTEGER,
created_at: DATE,
updated_at: DATE,
});
},
// Functions called when performing database demotion , Delete users surface
down: async (queryInterface:QueryInterface) => {
await queryInterface.dropTable('users');
},
};
8. stay package.json Add execution in TS Migration file script
"scripts": {
"sequelize-cli-ts": "node -r ts-node/register ./node_modules/sequelize-cli/lib/sequelize"
},
9. Perform migration file
npm run sequelize-cli-ts db:migrate
10. database users Create success 
边栏推荐
- Recommendation | scholar's art and Tao: writing papers is a skill
- This article takes you to graph transformers
- Wu Enda's machine learning after class exercises - linear regression
- Low cost, fast and efficient construction of digital collection app and H5 system, professional development of scallop technology is more assured!
- What model is good for the analysis of influencing factors?
- 图论:拓扑排序
- Life related - ten years of career experience (turn)
- Acwing brush questions
- Acwing_ 12. Find a specific solution for the knapsack problem_ dp
- 远坂凛壁纸
猜你喜欢

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

力扣每日一题-第42天-661. 图片平滑器

Segger embedded studio cannot find xxx.c or xxx.h file

Acwing刷题

Huawei executives talk about the 35 year old crisis. How can programmers overcome the worry of age?

荐书|《DBT技巧训练手册》:宝贝,你就是你活着的原因

理性认知教育机器人寓教于乐的辅助作用

生活相关——十年的职业历程(转)

VM virtual machine has no un bridged host network adapter, unable to restore the default configuration

TIA botu WinCC Pro controls the display and hiding of layers through scripts
随机推荐
Life related -- the heartfelt words of a graduate tutor of Huake (mainly applicable to science and Engineering)
Recommendation | scholar's art and Tao: writing papers is a skill
【二叉树】二叉树中的最长交错路径
零售连锁门店收银系统源码管理商品分类的功能逻辑分享
Sorting and searching
makefile知识再整理(超详细)
旋转数组最小数字
I.MX6U-系统移植-6-uboot图形化配置
dijikstra(先预处理)+dfs,relocation truncated to fit
Comprehensive evaluation and decision-making method
MySQL日志分类:错误日志、二进制日志、查询日志、慢查询日志
[binary tree] the longest interleaved path in a binary tree
How to choose the key words of the thesis?
文献|关系研究能得出因果性结论吗
Dijango learning
规则引擎Drools的使用
Write a paper for help, how to write the discussion part?
VM虚拟机 没有未桥接的主机网络适配器 无法还原默认配置
What if win11 cannot wake up from sleep? Solution of win11 unable to wake up during sleep
JS get some attributes of the object