Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. require('dotenv').config()
  2. const knex = require('knex')
  3.  
  4. const knexInstance = knex({
  5. client: 'pg',
  6. connection: process.env.DB_URL
  7. });
  8.  
  9.  
  10. function searchName(searchTerm) {
  11. knexInstance
  12. .select('*')
  13. .from('shopping_list')
  14. .where('name', 'ILIKE', `%${searchTerm}%`)
  15. .then(result => {
  16. console.log({ searchTerm })
  17. console.log(result)
  18. })
  19. };
  20.  
  21. searchName('urger');
  22.  
  23.  
  24.  
  25. function getAllItemsPaginated(pageNumber) {
  26. const itemLimit = 6
  27. const offset = itemLimit * (pageNumber - 1);
  28. knexInstance
  29. .select('*')
  30. .from('shopping_list')
  31. .limit(itemLimit)
  32. .offset(offset)
  33. .then(result => {
  34. console.log('PAGINATE ITEMS', { pageNumber })
  35. console.log(result)
  36. })
  37. };
  38.  
  39. getAllItemsPaginated(2);
  40.  
  41.  
  42.  
  43. // function addedProducts(daysAgo) {
  44. // knexInstance
  45. // .select('*')
  46. // .from('shopping_list')
  47. // .where('date_added' '>' )
  48. // }
  49.  
  50.  
  51.  
  52. function costPerCategory() {
  53. knexInstance
  54. .select('category')
  55. .count('price as total')
  56. .from('shopping_list')
  57. .groupBy('category')
  58. .then(result => {
  59. console.log(result)
  60. })
  61. }
  62.  
  63. costPerCategory()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement