Data persistence uses PostgreSQL. Raw SQL builds fluency for interviews and debugging; Knex adds migrations, seeds, and a query builder your Express services call. Learn both: SQL shows what the database actually runs; Knex shows how the app stays maintainable.

How to update and delete with Knex — Basic

Change or remove rows using update(), del(), or delete() with filters.
Learn: update(patch) and del() (or delete()) should always include where filters. Check the number of affected rows to distinguish 404 from success.

Supplementary examples

Update and delete by id

function update(id, patch) {
  return knex("pastes").where({ paste_id: id }).update(patch);
}

function remove(id) {
  return knex("pastes").where({ paste_id: id }).del();
}

Course example

function read(supplier_id) {
return knex("suppliers").select("*").where({ supplier_id }).first();
}
function update(updatedSupplier) {
return knex("suppliers")
.select("*")
.where({ supplier_id: updatedSupplier.supplier_id })
.update(updatedSupplier, "*");
}

Additional references & examples

← All Knex queries · SQL / Knex