当前位置:网站首页>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 
边栏推荐
- Function knowledge points
- MySQL only checks the reasons for the slow execution of one line statements
- How is the launch of ros2 different?
- How to write the summary? (including 7 easily ignored precautions and a summary of common sentence patterns in 80% of review articles)
- 再获认可 | 赛宁网安连续上榜《CCSIP 2022中国网络安全产业全景图》
- Retail chain store cashier system source code management commodity classification function logic sharing
- Sorting and searching
- What format should be adopted when the references are foreign documents?
- The difference between positive samples, negative samples, simple samples and difficult samples in deep learning (simple and easy to understand)
- Use of rule engine drools
猜你喜欢

Mantium 如何在 Amazon SageMaker 上使用 DeepSpeed 实现低延迟 GPT-J 推理

p-范数(2-范数 即 欧几里得范数)

Pat class a 1039 course list for student

Li Kou daily question - day 42 -661. Picture smoother

Life related - ten years of career experience (turn)

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

Helloworld案例分析

How does win11 22h2 skip networking and Microsoft account login?

Share | 2022 big data white paper of digital security industry (PDF attached)

低成本、快速、高效搭建数字藏品APP、H5系统,扇贝科技专业开发更放心!
随机推荐
Postman 导入curl 、导出成curl、导出成对应语言代码
I.MX6U-ALPHA开发板(GPIO中断实验)
Low cost, fast and efficient construction of digital collection app and H5 system, professional development of scallop technology is more assured!
1. Mx6u-alpha development board (GPIO interrupt experiment)
[SVN] please execute the 'cleanup' command appears all the time. The solution is that there is no response after cleanup
Several methods of realizing high-low byte or high-low word exchange in TIA botu s7-1200
firewall 命令简单操作
1. Excel的IF函数
dijikstra(先预处理)+dfs,relocation truncated to fit
理性认知教育机器人寓教于乐的辅助作用
[binary tree] the longest interleaved path in a binary tree
Which websites can I visit to check the latest medical literature?
Sangi diagram of machine learning (for user behavior analysis)
图论:拓扑排序
MySQL - multi table query - Cartesian product sum, correct multi table query, equivalent connection and unequal connection, inner connection and outer connection
Dijango learning
数据库连接数查看和修改
机器学习之桑基图(用于用户行为分析)
Support proxy direct connection to Oracle database, jumpserver fortress v2.24.0 release
Yuansaka Lin wallpaper