Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. 'use strict';
  2.  
  3. const extend = require('lodash').assign;
  4. const mysql = require('mysql');
  5. const config = require('../../config');
  6.  
  7. getlists();
  8.  
  9. function getConnection () {
  10. const options = {
  11. user: config.get('MYSQL_USER'),
  12. password: config.get('MYSQL_PASSWORD'),
  13. database: 'cloud-computing-db'
  14. };
  15.  
  16. if (config.get('INSTANCE_CONNECTION_NAME') && config.get('NODE_ENV') === 'production') {
  17. options.socketPath = `/cloudsql/${config.get('INSTANCE_CONNECTION_NAME')}`;
  18. }
  19.  
  20. return mysql.createConnection(options);
  21. }
  22.  
  23. function createnote (name, pos, cards_id) {
  24. const connection = getConnection();
  25. var maxid = connection.query('SELECT max(id) FROM `lists`');
  26. var data = {name:name, pos:pos, cards_id:cards_id, id: maxid + 1};
  27. connection.query('INSERT INTO `lists` SET ?' , data);
  28. connection.end();
  29. }
  30.  
  31. function getlists () {
  32. const connection = getConnection();
  33. var list = connection.query(
  34. 'SELECT * FROM `lists'
  35. );
  36. connection.end();
  37. }
  38.  
  39.  
  40.  
  41. function updatelist (name, id) {
  42. const connection = getConnection();
  43. connection.query('UPDATE `lists` SET ? WHERE `id` = ?', [name, id]);
  44. connection.end();
  45. }
  46.  
  47. function deletelist(id){
  48. const connection = getConnection();
  49. connection.query('DELETE * from `lists` WHERE `id` = ?', [id]);
  50. connection.end();
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement