当前位置:网站首页>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 
边栏推荐
- 机器学习之桑基图(用于用户行为分析)
- 1. Excel的IF函数
- Can literature | relationship research draw causal conclusions
- Life related - ten years of career experience (turn)
- Postman 导入curl 、导出成curl、导出成对应语言代码
- MySQL日志分类:错误日志、二进制日志、查询日志、慢查询日志
- AcWing. 102 best cattle fence
- Tutorial on using the one click upgrade function of the rtsp/onvif protocol video platform easynvr service
- ASP. Net core actionfilter filter details
- p-范数(2-范数 即 欧几里得范数)
猜你喜欢

I.MX6U-系统移植-6-uboot图形化配置

Unable to find sygwin.s file during vscode debugging
![[C language foundation] 13 preprocessor](/img/4c/ab25d88e9a0cf29bde6e33a2b14225.jpg)
[C language foundation] 13 preprocessor

华为高层谈 35 岁危机,程序员如何破年龄之忧?

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

RTSP/Onvif协议视频平台EasyNVR服务一键升级功能的使用教程

零售连锁门店收银系统源码管理商品分类的功能逻辑分享

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

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

Getting started with mongodb Basics
随机推荐
How to download the supplementary literature?
Helloworld案例分析
Firewall command simple operation
[binary tree] the longest interleaved path in a binary tree
Soft simulation rasterization renderer
测试用例设计方法之:入门试招,等价边界初探
What are the consequences and problems of computer system restoration
This article takes you to graph transformers
APISIX 在 API 和微服务领域的探索
MySQL only checks the reasons for the slow execution of one line statements
Acwing brush questions
Use of anonymous functions
数据库连接数查看和修改
Functions of anonymous functions
工程师如何对待开源 --- 一个老工程师的肺腑之言
零售连锁门店收银系统源码管理商品分类的功能逻辑分享
LeetCode. 6115 count the number of ideal arrays
Recommendation Book Educational Psychology: a book for tomorrow's teachers~
动态规划 爬楼梯
dijikstra(先预处理)+dfs,relocation truncated to fit