Search code examples
javascriptmysqlknex.js

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.

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

Solution

  • I think you should use update instead of insert

    .where('id', petId)
    .update({image :file.path})