使用sequelize.js读取SQL文件时出现错误

时间:2018-12-25 14:38:06

标签: mysql node.js sequelize.js

我正在使用sequelize.js读取sql文件,但是sql条件注释始终出错。

我有一个超过2000行的大型原始sql文件。如果仅将整个文件传递给sequlize.query()函数,它将失败,因此我将查询分隔为“;”。并使其成为数组,然后使用promise对其进行顺序迭代。

const sequelize = new Sequelize(dbName, userName, password, packageJsonDbConfig.options);
let promises = [];
let queries = fs.readFileSync(path.join(__dirname, 'data.sql'));
let splitQueries = queries.toString().replace(/^\s*[\r\n]/gm, '').split(';');
splitQueries.forEach((splitQuery) => {
    promises.push(sequelize.query(splitQuery));
});
Promise.seq(promises.map(p => p.catch((err) => console.log(err))));

对于以下sql条件注释,我一直{无法将变量'collat​​ion_connection'设置为'NULL'}

/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

还有

Executing (default): --
-- Dumping data for table `TeamMatchScores`
--
LOCK TABLES `TeamMatchScores` WRITE
Executing (default): /*!40000 ALTER TABLE `TeamMatchScores` DISABLE KEYS */
{ SequelizeDatabaseError: Table 'arthurmurray.teammatchentries' doesn't exist }

对于以下sql语句

--
-- Table structure for table `TeamMatchEntries`
--

DROP TABLE IF EXISTS `TeamMatchEntries`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `TeamMatchEntries` (
    `TeamMatchEntryID` int(11) DEFAULT NULL,
    `EventID` int(11) DEFAULT NULL,
    `TeamName` int(11) DEFAULT NULL,
    `TeamStudioID` int(11) DEFAULT NULL,
    `TeamID` int(11) DEFAULT NULL,
    `ScoreType` int(11) DEFAULT NULL,
    `TeamOrder` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `TeamMatchEntries`
--

LOCK TABLES `TeamMatchEntries` WRITE;
/*!40000 ALTER TABLE `TeamMatchEntries` DISABLE KEYS */;
/*!40000 ALTER TABLE `TeamMatchEntries` ENABLE KEYS */;
UNLOCK TABLES;"

0 个答案:

没有答案