Created
January 5, 2017 03:53
-
-
Save johnfkneafsey/e781190af1d0d3665a67b3980ee1a93e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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