In case we want to update a record within a table through KNEX, we can use the following code:
updateRecord();
function updateRecord(){
knex('depts')
.where("deptno","40")
.update({
dname: 'TEST DEPARTMENT'
})
.then(count=>{
console.log("record updated"+count);
});
}
The above code calls a function updateRecord that updates the deptno = 40's department name to 'TEST DEPARTMENT'. Also in the Promise '.then', it prints out number of records that were updated.
Happy Coding !!!
updateRecord();
function updateRecord(){
knex('depts')
.where("deptno","40")
.update({
dname: 'TEST DEPARTMENT'
})
.then(count=>{
console.log("record updated"+count);
});
}
The above code calls a function updateRecord that updates the deptno = 40's department name to 'TEST DEPARTMENT'. Also in the Promise '.then', it prints out number of records that were updated.
Happy Coding !!!
Comments