karliatto karliatto - 1 year ago 113
MySQL Question

insert into existing row using where() with knex

I want to insert data into an existing row with knex.js but I do not see it is clear in the documentation, trying with Where() as in the code below doesn't work. I've seen that there is a npm package called knex-filter that may help in doing so, but I guess there should be a way to do it with knex.js
If anyone knows how to proceed I would be very gratefull.

.where({id : petId})
.insert({image: file.path})
.then(function(result) {
console.log('knexjs works!!');
.catch(function(error) {

Answer Source

I think you should use update instead of insert

.where('id', petId)
.update({image :file.path})
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download