Closed danielabar closed 11 years ago
Right. You need to use mysql.createConnection
for node-mysql 2.0. I fixed the code sample in the README. Thanks!
Thanks using mysql.createConnection got me past that error.
But now I'm having an issue where no inserts are happening. I turned on debugging for both this project on node-mysql, not getting any errors, but also not seeing any inserts.
Here is my code:
var client = mysql.createConnection({
host: config.db_host,
user: config.db_user,
password: config.db_pswd,
database: config.db_schema,
connectionLimit: config.db_pool_connection_limit,
debug: config.db_debug_sql
});
var queues = require('mysql-queues');
const DEBUG = true;
queues(client, DEBUG);
module.exports = {
executeTrans: function(queryStrings, queryParams) {
var trans = client.startTransaction();
function error(err) {
if(err && trans.rollback) {trans.rollback(); throw err;}
}
for(var i = 0; i < queryStrings.length; i++)
trans.query(queryStrings[i], queryParams[i], error);
trans.commit();
},
// other dao functions...
And here is the mocha test (not asserting anything at the moment, just using it to exercise the code, then manually checking in the database if any new records were inserted)
it.only('Transaction support works', function() {
var today = new Date();
var query1 = 'insert into ld set ?';
var queryParam1 = {
"user_id": 1,
"ld_model_id": null,
"name": "LD Trans Test 1",
"scope": "Lesson",
"publication": 1,
"students_profile": "SP Trans Test 1",
"creation_date": today
};
var queryParam2 = {
"user_id": 1,
"ld_model_id": null,
"name": "LD Trans Test 2",
"scope": "Lesson",
"publication": 1,
"students_profile": "SP Trans Test 2",
"creation_date": today
};
try {
Dao.executeTrans([query1, query1], [queryParam1, queryParam2]);
} catch (e) {
console.log(e);
}
});
And here is debug output:
<-- HandshakeInitializationPacket
{ protocolVersion: 10,
serverVersion: '5.5.24',
threadId: 42,
scrambleBuff1: <Buffer 70 79 30 21 54 62 6f 29>,
filler1: <Buffer 00>,
serverCapabilities1: 63487,
serverLanguage: 8,
serverStatus: 2,
serverCapabilities2: 32783,
scrambleLength: 21,
filler2: <Buffer 00 00 00 00 00 00 00 00 00 00>,
scrambleBuff2: <Buffer 7a 4f 5a 58 29 60 2b 53 41 2a 4f 30>,
filler3: <Buffer 00>,
pluginData: 'mysql_native_password',
protocol41: true }
--> ClientAuthenticationPacket
{ clientFlags: 193487,
maxPacketSize: 0,
charsetNumber: 33,
filler: undefined,
user: 'ledita',
scrambleBuff: <Buffer 13 a1 78 c5 1e a7 c2 79 3b ab be d1 00 6c e5 21 ad be ba b1>,
database: 'ledita-web-app',
protocol41: true }
<-- OkPacket
{ fieldCount: 0,
affectedRows: 0,
insertId: 0,
serverStatus: 2,
warningCount: 0,
message: '',
protocol41: true,
changedRows: 0 }
--> ComQueryPacket
{ command: 3, sql: 'START TRANSACTION' }
I'm using node-mysql 2.0.0-alpha8 and can't get the sample code in the readme working regarding
mysql.createClient
Running the code generates a has no method error. Is there a different syntax to use to get this working with node-mysql 2.0.0? (Note that mysql is otherwise working for me using the connection pool)