当前位置:网站首页>egg-ts-sequelize-CLI
egg-ts-sequelize-CLI
2022-07-26 04:20:00 【YY小怪兽】
详情可见
1.安装 sequelize-cli
npm install sequelize-cli
2.在项目根目录下编写.sequelizerc 配置文件
'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.初始化配置文件
npx sequelize init:config
4.修改配置文件database/config.json
根据要求设置数据库 目前由于是开发阶段所以只设置开发阶段 ,需要其他就修改
development:开发阶段
test:测试阶段
production:上线阶段
{
"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.初始化配置目录
npx sequelize init:migrations
6.创建配置文件
npx sequelize migration:generate --name=users
7.修改迁移文件为TS语法 直接修改database/migration下的创建的js文件重命名为.ts文件
'use strict';
import {
QueryInterface } from 'sequelize';
module.exports = {
// 在执行数据库升级时调用的函数,创建 users 表
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,
});
},
// 在执行数据库降级时调用的函数,删除 users 表
down: async (queryInterface:QueryInterface) => {
await queryInterface.dropTable('users');
},
};
8.在package.json中新增执行TS迁移文件脚本
"scripts": {
"sequelize-cli-ts": "node -r ts-node/register ./node_modules/sequelize-cli/lib/sequelize"
},
9.执行迁移文件
npm run sequelize-cli-ts db:migrate
10.数据库users创建成功
边栏推荐
- 零售连锁门店收银系统源码管理商品分类的功能逻辑分享
- Acwing brush questions
- LeetCode. 6115 count the number of ideal arrays
- How to make your language academic when writing a thesis? Just remember four sentences!
- [binary tree] the longest interleaved path in a binary tree
- The era of smart clothes has come. Zhinar invites you to discuss swords in Yangcheng. Guangya Exhibition is waiting for you on August 4
- (translation) timing of website flow chart and user flow chart
- 雅迪高端之后开始变慢
- Overview of wavelet packet transform methods
- How is the launch of ros2 different?
猜你喜欢

Acwing刷题

Comprehensive evaluation and decision-making method

低成本、快速、高效搭建数字藏品APP、H5系统,扇贝科技专业开发更放心!

Pat class a 1039 course list for student

机器学习之桑基图(用于用户行为分析)

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

Recommendation | DBT skills training manual: baby, you are the reason why you live

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

p-范数(2-范数 即 欧几里得范数)
![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](/img/84/e5cb5199fe4602440b50dfc4afe963.gif)
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
随机推荐
Acwing刷题
[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
LeetCode:1184. 公交站间的距离————简单
低成本、快速、高效搭建数字藏品APP、H5系统,扇贝科技专业开发更放心!
Go plus security: an indispensable security ecological infrastructure for build Web3
Overview of wavelet packet transform methods
Small ball and box model, arrangement and combination
How to transfer English documents to Chinese?
Functions of anonymous functions
Recommendation | scholar's art and Tao: writing papers is a skill
Low cost, fast and efficient construction of digital collection app and H5 system, professional development of scallop technology is more assured!
匿名函数的作用
Firewall command simple operation
Mantium 如何在 Amazon SageMaker 上使用 DeepSpeed 实现低延迟 GPT-J 推理
【二叉树】二叉树中的最长交错路径
P-norm (2-norm is Euclidean norm)
Comprehensive evaluation and decision-making method
SEGGER Embedded Studio找不到xxx.c或者xxx.h文件
Dijikstra (preprocessing first) +dfs, relocation truncated to fit
Communication protocol and message format between microservices