最糟糕的是,它之前正在运作!这是代码
DataBase.prototype.execute = function execute(type, query, response, parameters) {
this.sequelize = new Sequelize('inmobiliaria', 'root', 'root',
{
host: 'localhost',
port: 3306,
dialect: 'mysql'
}
);
//this.users.logIn(response.post['user'], response.post['pass']);
/*
from the sequelize docs:
Options is an object with the following keys:
{
logging: console.log, // a function (or false) for logging your queries
plain: false, // if plain is true, then sequelize will return all of the records within an array, otherwise it will return a single object/first record returned.
raw: true // Set this to true if you don't have a model definition for your query
}
*/
var options = { raw: true };
var result = this.sequelize.query(query, null, options, parameters)
.success(function (rows) {
if (type == 'select') {
response.writeHead(200, { 'Content-Type': 'application/json' });
response.write(parameters.callback + '(' + JSON.stringify(rows) + ')');//wrap the json inside the callback function to make a jsonp
response.end();
} else if (type == 'modify') {
response.writeHead(200, { 'Content-Type': 'text/html' });
response.write('Query was successful');
response.end();
}
}
).error(function (e) {
console.log('An error occured: ', e);
response.writeHead(404, { 'Content-Type': 'text/html' });
response.write('There was an error man, shits on fire yo ---> ' + e);
response.end();
}
);
}
错误出现在第一行的response.writeHead() 你可以看到我不使用.next()或任何太花哨的东西,并认为调用的顺序是正确的。目前没有其他类正在修改它,这是我查询db并写入结果以便返回它的地方。即时通讯使用手动查询,因为我的数据库查询很复杂,我更喜欢使用sql。
答案 0 :(得分:0)
我发现了这个问题,在另一个类中,我有一些测试代码,按照Aaron的建议再次编写了标题。猜猜深夜代码发挥了作用,无论如何都要感谢阅读。