Впервые используя MySQL, я создал простое приложение для входа / регистрации.
Я очень смущен, потому что в моих глазах нуб кажется, что ошибка не указывает на место, которое я могу найти. Кроме того, данные вставляются в таблицу правильно, поэтому ошибка, по-видимому, отсутствует в запросе MySQL.
Это ошибка, которую я получаю:
/Users/pablosouza/Desktop/Projects/Tests/db2/node_modules/mysql/lib/protocol/Parser.js:437
throw err; // Rethrow non-MySQL errors
^
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 ', `affectedRows` = 1, `insertId` = 15, `serverStatus` = 2, `warningCount` = 0, `' at line 1
at Query.Sequence._packetToError (/Users/pablosouza/Desktop/Projects/Tests/db2/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
at Query.ErrorPacket (/Users/pablosouza/Desktop/Projects/Tests/db2/node_modules/mysql/lib/protocol/sequences/Query.js:77:18)
at Protocol._parsePacket (/Users/pablosouza/Desktop/Projects/Tests/db2/node_modules/mysql/lib/protocol/Protocol.js:291:23)
at Parser._parsePacket (/Users/pablosouza/Desktop/Projects/Tests/db2/node_modules/mysql/lib/protocol/Parser.js:433:10)
at Parser.write (/Users/pablosouza/Desktop/Projects/Tests/db2/node_modules/mysql/lib/protocol/Parser.js:43:10)
at Protocol.write (/Users/pablosouza/Desktop/Projects/Tests/db2/node_modules/mysql/lib/protocol/Protocol.js:38:16)
at Socket.<anonymous> (/Users/pablosouza/Desktop/Projects/Tests/db2/node_modules/mysql/lib/Connection.js:91:28)
at Socket.<anonymous> (/Users/pablosouza/Desktop/Projects/Tests/db2/node_modules/mysql/lib/Connection.js:525:10)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
--------------------
at Pool.query (/Users/pablosouza/Desktop/Projects/Tests/db2/node_modules/mysql/lib/Pool.js:199:23)
at Promise (internal/util.js:274:30)
at new Promise (<anonymous>)
at Pool.query (internal/util.js:273:12)
at User.find (/Users/pablosouza/Desktop/Projects/Tests/db2/core/user.js:18:14)
at /Users/pablosouza/Desktop/Projects/Tests/db2/routes/pages.js:58:22
at Query.<anonymous> (/Users/pablosouza/Desktop/Projects/Tests/db2/core/user.js:43:13)
at Query.<anonymous> (/Users/pablosouza/Desktop/Projects/Tests/db2/node_modules/mysql/lib/Connection.js:525:10)
at Query._callback (/Users/pablosouza/Desktop/Projects/Tests/db2/node_modules/mysql/lib/Connection.js:491:16)
at Query.Sequence.end (/Users/pablosouza/Desktop/Projects/Tests/db2/node_modules/mysql/lib/protocol/sequences/Sequence.js:83:24)
[nodemon] app crashed - waiting for file changes before starting...
Есть мысли?
//User class to send queries to database
const pool = require ('./pool');
const bcrypt = require ('bcrypt'); //to hash the password
function User () {}; //creating on object
User.prototype = {
// Find user data by id or username
find: function(user = null, callback)
{
if(user) {
var field = Number.isInteger(user) ? 'id' : 'username';
}
let sql = `SELECT * FROM users1 WHERE ${field} = ?`;
pool.query(sql, user, function(err,result){
if(err) throw err
if(result.length) {
callback(result[0]);
}else {
callback(null);
}
});
},
create : function(body, callback) {
let pwd = body.password;
body.password = bcrypt.hashSync(pwd,10);
var bind = [];
for (prop in body){
bind.push(body[prop]);
}
let sql = "INSERT INTO users1 (username, fullname, password) VALUES(?, ?, ?)";
pool.query(sql, bind, function(err, lastId){
if(err)
console.log("oops this is bullshit");
callback(lastId);
});
},
login: function(username, password, callback){
this.find(username, function(user){
if(user) {
if (bcrypt.compareSync(password, user.password)) {
callback(user);
return;
}
}
callback(null);
})
}
}
module.exports = User;