Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- const extend = require('lodash').assign;
- const mysql = require('mysql');
- const config = require('../../config');
- getlists();
- function getConnection () {
- const options = {
- user: config.get('MYSQL_USER'),
- password: config.get('MYSQL_PASSWORD'),
- database: 'cloud-computing-db'
- };
- if (config.get('INSTANCE_CONNECTION_NAME') && config.get('NODE_ENV') === 'production') {
- options.socketPath = `/cloudsql/${config.get('INSTANCE_CONNECTION_NAME')}`;
- }
- return mysql.createConnection(options);
- }
- function createnote (name, pos, cards_id) {
- const connection = getConnection();
- var maxid = connection.query('SELECT max(id) FROM `lists`');
- var data = {name:name, pos:pos, cards_id:cards_id, id: maxid + 1};
- connection.query('INSERT INTO `lists` SET ?' , data);
- connection.end();
- }
- function getlists () {
- const connection = getConnection();
- var list = connection.query(
- 'SELECT * FROM `lists'
- );
- connection.end();
- }
- function updatelist (name, id) {
- const connection = getConnection();
- connection.query('UPDATE `lists` SET ? WHERE `id` = ?', [name, id]);
- connection.end();
- }
- function deletelist(id){
- const connection = getConnection();
- connection.query('DELETE * from `lists` WHERE `id` = ?', [id]);
- connection.end();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement