import express from 'express';
import path from 'path';
import {settings, connection} from './database';

// Connect to the database
connection.connect(err => {
  // If there is an error, display the message and exit the program
  if(err) {
    console.error('Error connection' + err.stack);
    process.exit();
  }
  console.log('Succesfully connected as id %d', connection.threadId);
});

// Init the express server
let app = express();

// The public directory for static files is public
app.use(express.static('public'));
// Setup views
app.set('view engine', 'pug');

/**
 * TODO: make promise out of this
 */
function getResults(cb, id = 0, howMany = 25) {
  let query = ' SELECT tijd_gaan_slapen, tijd_opgestaan, gewenste_slaaptijd'
            + ' FROM `' + settings.schema + '`.`hours` '
            + ' WHERE `id` = ' + id
            + ' LIMIT ' + howMany;

  connection.query(query, (err, results) => {
    if(err) console.error(err);
    cb(results);
  });
}

/**
 * GET: ./
 * The front page with a table
 */
app.get('/', (req, res) => {
  getResults((results) => {
    console.log(results);
    res.render('index.pug', results);
  });
});

/**
 * GET: ./api
 * Get all the data from the database.
 */
app.get('/api', (req, res) => {
  connection.query('SELECT tijd_gaan_slapen, tijd_opgestaan, gewenste_slaaptijd FROM `hours`', (err, results) => {
    res.json(results);
  });
});

// Listen for requests on port 3000
app.listen(3000, () => {
  console.log('Listening on port 3000');
});

@@ -49,16 +49,43 @@
 'path';%0A
+import mysql from 'mysql';%0A
 import %7B
@@ -689,29 +689,30 @@
 %7B%0A  
-let query = ' 
+const sql = %60
 SELECT 
+%5C%60
 tijd
@@ -715,34 +715,38 @@
 tijd_gaan_slapen
-, 
+%5C%60, %5C%60
 tijd_opgestaan, 
@@ -735,34 +735,38 @@
 %5C%60tijd_opgestaan
-, 
+%5C%60, %5C%60
 gewenste_slaapti
@@ -767,17 +767,18 @@
 laaptijd
-'
+%5C%60
 %0A       
@@ -786,53 +786,30 @@
     
-+ '
+  
  FROM 
-%60' + settings.schema + '%60.
+??.%5C
 %60hours
-%60 '%0A
+%5C%60%0A 
     
@@ -820,31 +820,26 @@
     
-+ '
+ 
  WHERE 
+%5C
 %60id
+%5C
 %60 = 
-' + id
+?
 %0A   
@@ -851,29 +851,113 @@
     
-+ '
+  
  LIMIT 
-' + howMany
+?%60;%0A  const inserts = %5Bsettings.schema, id, howMany%5D;%0A  const query = mysql.format(sql, inserts)
 ;%0A%0A 

Use inserts on my query