Advertisement
Guest User

Untitled

a guest
Mar 5th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. const dbClient = require('knex')({
  2. client: 'pg',
  3. connection: {
  4. host: '127.0.0.1',
  5. user: 'user',
  6. password: 'password',
  7. database: 'staging',
  8. port: '5431'
  9. }
  10. })
  11.  
  12. module.exports = dbClient
  13.  
  14. const knex = require('./dbClient.js')
  15.  
  16. async function doThis(email) {
  17. const last = await knex('users').where({email}).first('last_name').then(res => res.last_name)
  18. // knex.destroy()
  19. return last
  20. }
  21.  
  22. async function doThat(email) {
  23. const first = await knex('users').where({email}).first('first_name').then(res => res.first_name)
  24. // knex.destroy()
  25. return first
  26. }
  27.  
  28. module.exports = {
  29. doThat,
  30. doThis
  31. }
  32.  
  33. const {doThis, doThat} = require('./libs.js');
  34.  
  35. (async () => {
  36. try {
  37. const res1 = await doThis('user53@gmail.com')
  38. console.log(res1)
  39. const res2 = await doThat('user53@gmail.com')
  40. console.log(res2)
  41. } catch (err) {
  42. console.log(err)
  43. }
  44. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement