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 insert with Knex — Basic

Insert one or more records using knex('table').insert() and optional returning().
Learn: insert() accepts an object or array for bulk inserts. Use returning('*') on PostgreSQL to get the inserted row back for your 201 response.

Supplementary examples

Insert with returning

function create(data) {
  return knex("pastes")
    .insert(data)
    .returning("*")
    .then((rows) => rows[0]);
}

Course example

const knex = require("../db/connection");
function create(supplier) {
return knex("suppliers")
.insert(supplier)
.returning("*")
.then((createdRecords) => createdRecords[0]);
}
module.exports = {
create,
};

Additional references & examples

← All Knex queries · SQL / Knex