Created
August 3, 2017 04:58
-
-
Save bvenkatr/525c957736106374b2a12e1ca60b6fb4 to your computer and use it in GitHub Desktop.
testing a transaction with natvie sql query and built in ORM methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
let uuid = require("uuid"); | |
/** | |
* 'use strict'; | |
let uuid = require("uuid"); | |
module.exports = function (Todos) { | |
Todos.testTransaction = function () { | |
Todos.beginTransaction(Todos.Transaction.READ_COMMITTED, function (err, tx) { | |
let q1 = `insert into ifdev.todos values('${uuid.v1()}', '10001 note', false)`; | |
// Todos.dataSource.connector.execute(q1, function (err, data) { | |
Todos.create({ | |
id: `${uuid.v1()}`, | |
text: "some dkfjdlskfjldsf", | |
done: false | |
}, {transaction: tx}, function (err, data) { | |
console.log(`errris i `, err); | |
console.log(`data is s`, data); | |
tx.rollback(function (res) { | |
console.log("rollback res is ", res); | |
}); | |
}); | |
}); | |
}; | |
}; | |
* @param Todos | |
*/ | |
module.exports = function (Todos) { | |
Todos.testTransaction = function () { | |
Todos.beginTransaction(Todos.Transaction.READ_COMMITTED, function (err, tx) { | |
let q1 = `insert into ifdev.todos values('${uuid.v1()}', '10001 note', false)`; | |
/** | |
* Sharing transactions between native sql and loopback models. | |
* https://groups.google.com/forum/#!topic/loopbackjs/cFbkpZvs9bg | |
*/ | |
Todos.dataSource.connector.execute(q1, [], {transaction: tx}, function (err, data) { | |
console.log(`errris i `, err); | |
console.log(`data is s`, data); | |
tx.rollback(function (res) { | |
console.log("rollback res is ", res); | |
}); | |
}); | |
}); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment