Hey everyone i have the following code that retrieves data from cloud, then i need to save it to a database. I did it using Knex to make a seed file, and also using a regular function, but i need to do it using transactions with Knex.
Here is what i did :
function addPatient(){
return knex.transaction((t) => {
return knex('patients').insert({
uid: patient.uid,
first_name: patient.first_name,
last_name: patient.last_name,
birth_date: patient.birth_date,
code: patient.code,
birthsex: patient.birthsex,
})
}).then(t.commit)
.catch(function(e) {
t.rollback();
throw e;
})
}
Although sometimes i replaced the json by a variable object that gets all the data.
And i imported knex as following :
const knex = require(path.join(__dirname, 'knexfile.js'));
What intrigues me is i get this error : knex.transaction is not a function, can anyone please hint or help or point to me where i am wrong ?
Thank you