【发布时间】:2019-12-08 22:28:42
【问题描述】:
我想在从 sql 文件迁移时运行 mysql 命令。谁能帮帮我,怎么解决?
import {MigrationInterface, QueryRunner} from "typeorm";
import * as fs from "fs";
var queries = fs.readFileSync(__dirname + '/geoinfo.sql').toString()
.replace(/(\r\n|\n|\r)/gm," ") // remove newlines
.replace(/\s+/g, ' '); // excess white space
export class HungarianStatesAndCities1564393283405 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(queries.toString() );
}
public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query("");
}
}
【问题讨论】:
-
这似乎是一个可行的解决方案。似乎是什么问题?
-
它不工作。有人有可行的解决方案吗?它因语法错误而失败,但在文件中代码很好。
-
错误是什么?就像我说的,代码看起来很正确,但是如果您不知道 什么 在您尝试运行脚本时具体发生了什么,它将无法提供帮助。