Knex

SQL query builder, install plugins like pg lib separately

npm install knex

Initialization

Initializing the Library

var knex = require('knex')({
  client: 'mysql',
  connection: {
    host : '127.0.0.1',
    user : 'your_database_user',
    password : 'your_database_password',
    database : 'myapp_test'
  }
});

Usage

Select

await knex.select('title', 'author').from('books') 
#Only first record
await knex.first('title', 'author').from('books')

select returns a list of json

first returns a single json

if no entry, returns undefined or empty list

Insert

Add .returning('*') to return data

Query

Where

Order

Update

returns true on success confirmed, idk else

Add .returning('*') to return data

Count

Join

Last updated