我正在尝试将sequelize 与typescript 一起使用,但不知道如何操作。我安装了一个名为sequelize-cli-typescript 的软件包,但它不适用于sequelize v6。我知道最好使用迁移来执行我的数据库。我怎样才能做到这一点?
我想在我的express api上使用sequelize播种机和迁移,目前所有模型都是使用sequelize-typescript以typescript编写的
我尝试使用打字稿添加我的第一个种子文件,但运行时出现错误
20221028050116-feeds.ts播种文件
'use strict';
import { QueryInterface } from 'sequelize';
const feedTypes = [
{ id: 'b871a455-fddb-414c-ac02-2cdee07fa671', name: 'crypto' },
{ id: '68b15f90-19ca-4971-a2c6-67e66dc88f77', name: 'general' },
];
const feeds = [
{
id: 1,
name: 'cointelegraph',
url: 'https://cointelegraph.com/rss',
feed_type_id: 'b871a455-fddb-414c-ac02-2cdee07fa671',
},
];
module.exports = {
up: (queryInterface: QueryInterface): Promise<number | object> =>
queryInterface.sequelize.transaction(async (transaction) => {
// here go all migration changes
return Promise.all([
queryInterface.bulkInsert('feed_types', feedTypes, { transaction }),
queryInterface.bulkInsert('feeds', feeds, { transaction }),
]);
}), …
Run Code Online (Sandbox Code Playgroud) database-migration node.js sequelize.js typescript sequelize-cli