Skip to content

Instantly share code, notes, and snippets.

@johnfkneafsey
Created January 5, 2017 03:53
Show Gist options
  • Save johnfkneafsey/e781190af1d0d3665a67b3980ee1a93e to your computer and use it in GitHub Desktop.
Save johnfkneafsey/e781190af1d0d3665a67b3980ee1a93e to your computer and use it in GitHub Desktop.
1) What is Knex used for?
Knex is used to make SQL queries using JS.
2) How do you connect to a Postgres Database using Knex?
const knex = require('knex')({
client: 'pg',
connection: {
user: 'username',
password: 'password',
database: 'database'
},
});
3) How do you insert a row using Knex?
knex.insert({
name: 'name,
description: 'description'
}).into('table').then();
4) Howq do you query for rows using Knex?
knex.select('rowName').from('table').where({
name: 'name'
}).then('table' => {
console.log(table[0]);
});
5)How is a join performed in Knex?
join — .join(table, first, [operator], second)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment