Wie kann ich mehrere raw-Abfragen mit sequelize in MySql?

Ich versuche, ein Skript ausführen, löschen Sie alle Tabellen aus der Datenbank vor sequelize synchronisiert über sequelize.sync({ force: true });

Läuft das script ohne Probleme, wenn ich es aus der Konsole, das problem passiert, wenn ich versuche, führen Sie es aus meiner node.js Anwendung; MySql gibt einen parse error.

node.js

var dropAllTables = [
    'SET FOREIGN_KEY_CHECKS = 0;',
    'SET GROUP_CONCAT_MAX_LEN = 32768;',
    'SET @tables = NULL;',
    "SELECT GROUP_CONCAT('`', table_name, '`') INTO @tables FROM information_schema.tables WHERE table_schema = (SELECT DATABASE());",
    "SET @tables = CONCAT('DROP TABLE IF EXISTS ', @tables);",
    "SELECT IFNULL(@tables, 'SELECT 1') INTO @tables;",
    'PREPARE stmt FROM @tables;',
    'EXECUTE stmt;',
    'DEALLOCATE PREPARE stmt;',
    'SET FOREIGN_KEY_CHECKS = 1;',
    "SET GLOBAL sql_mode = 'STRICT_ALL_TABLES';"
].join(' ');

sequelize.query(dropAllTables, {
    raw: true
}).then(function() {
    return sequelize.sync({ force: true });
}).then(function() {
    console.log('Database recreated!');
    callback();
}, function(err) {
    throw err;
});

Fehler

{ [Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET GROUP_CONCAT_MAX_LEN = 32768; SET @tables = NULL; SELECT GROUP_CONCAT('`', t' at line 1]
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlState: '42000',
index: 0,
sql: 'SET FOREIGN_KEY_CHECKS = 0; SET GROUP_CONCAT_MAX_LEN = 32768; SET @tables = NULL; SELECT GROUP_CONCAT(\'`\', table_name, \'`\') INTO @tables FROM information_schema.tables WHERE table_schema = (SELECT DATABASE()); SET @tables = CONCAT(\'DROP TABLE IF EXISTS \', @tables); SELECT IFNULL(@tables, \'SELECT 1\') INTO @tables; PREPARE stmt FROM @tables; EXECUTE stmt; DEALLOCATE PREPARE stmt; SET FOREIGN_KEY_CHECKS = 1; SET GLOBAL sql_mode = \'STRICT_ALL_TABLES\';' }

Ich nichts gefunden in Bezug auf mehrere raw-Abfragen mit sequelize in Google noch bei sequelize docs-Seite (ich sah für einen spezifischen parameter für die query - Methode).

EDIT:

Fand ich dieser thread von einem SO-Klon, wo die Menschen scheinen das gleiche problem haben, aber ich kann nicht herausfinden, was die Lösung war.

InformationsquelleAutor Renato Gama | 2014-09-26
Schreibe einen Kommentar