当前位置:网站首页>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创建成功
边栏推荐
- Function knowledge points
- 力扣每日一题-第42天-661. 图片平滑器
- How to make your language academic when writing a thesis? Just remember four sentences!
- 低成本、快速、高效搭建数字藏品APP、H5系统,扇贝科技专业开发更放心!
- Acwing刷题
- How to write abstract in English thesis?
- LeetCode. 6115 count the number of ideal arrays
- Unable to find sygwin.s file during vscode debugging
- Comprehensive evaluation and decision-making method
- Write a paper for help, how to write the discussion part?
猜你喜欢

dijango学习

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

Recommendation Book Educational Psychology: a book for tomorrow's teachers~

PathMatchingResourcePatternResolver解析配置文件 资源文件

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

APISIX 在 API 和微服务领域的探索

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

荐书丨《教育心理学》:送给明日教师的一本书~
随机推荐
机器学习之信用卡欺诈检测
Soft simulation rasterization renderer
MySQL的优化分析及效率执行
When you try to delete all bad code in the program | daily anecdotes
makefile知识再整理(超详细)
Sangi diagram of machine learning (for user behavior analysis)
APISIX 在 API 和微服务领域的探索
TIA botu WinCC Pro controls the display and hiding of layers through scripts
Communication protocol and message format between microservices
Function knowledge points
This article takes you to graph transformers
Share | 2022 big data white paper of digital security industry (PDF attached)
[binary tree] the longest interleaved path in a binary tree
支持代理直连Oracle数据库,JumpServer堡垒机v2.24.0发布
How to transfer English documents to Chinese?
Apisex's exploration in the field of API and microservices
Design and implementation of smart campus applet based on cloud development
荐书|《DBT技巧训练手册》:宝贝,你就是你活着的原因
JS get some attributes of the object
Pathmatchingresourcepatternresolver parsing configuration file resource file