/**
 * Created by user on 06/10/2017.
 */

'use strict'

var mysql = require("../../node_modules/sails-mysql/node_modules/mysql");
var dbConf = require("../../config/connections");

module.exports = {
    run : function (next) {
        console.log("Using MySQL DB Adapter.");
        return this.create(next);
    },


    create : function(next) {

        var connection = mysql.createConnection({
            host     : dbConf.connections.mysql.host,
            port     : dbConf.connections.mysql.port,
            user     : dbConf.connections.mysql.user,
            password : dbConf.connections.mysql.password
        });

        console.log("Creating database `" + dbConf.connections.postgres.database + "` if not exists.");

        connection.query('CREATE DATABASE IF NOT EXISTS ' + dbConf.connections.postgres.database, function (error, results, fields) {
            if (error) {
                console.error(error);
                return next(error);
            }

            return next();
        });
    }
}

@@ -178,226 +178,715 @@
 %22);%0A
-%0Amodule.exports = %7B%0A    run : function (next) %7B%0A        console.log(%22Using MySQL DB Adapter.%22);%0A        return this.create(next);%0A    %7D,%0A%0A%0A    create : function(next) %7B%0A%0A        var connection = mysql.createConnection(
+var URL = require('url');%0Avar _ = require('lodash');%0A%0A%0Afunction parse(uri) %7B%0A%0A  var parsed =  URL.parse(uri);%0A%0A  return %7B%0A    user: parsed.auth.split(%22:%22)%5B0%5D,%0A    password: parsed.auth.split(%22:%22)%5B1%5D %7C%7C null,%0A    host: parsed.hostname,%0A    port: parsed.port,%0A    database: parsed.pathname.replace('/', '')%0A  %7D%0A%7D%0A%0Amodule.exports = %7B%0A    run : function (next) %7B%0A        console.log(%22Using MySQL DB Adapter.%22);%0A        return this.create(next);%0A    %7D,%0A%0A%0A    create : function(next) %7B%0A%0A        var parsedOpts;%0A        var url = dbConf.connections.mysql.url;%0A        if(url) %7B%0A          parsedOpts = parse(url);%0A        %7D%0A%0A%0A%0A        var connection = mysql.createConnection(url ? _.omit(parsedOpts,%5B'database'%5D) : 
 %7B%0A  
@@ -1158,16 +1158,53 @@
 ase %60%22 +
+ ( parsedOpts ? parsedOpts.database :
  dbConf.
@@ -1211,32 +1211,29 @@
 connections.
-postgres
+mysql
 .database + 
@@ -1229,16 +1229,18 @@
 database
+ )
  + %22%60 if
@@ -1315,16 +1315,53 @@
 ISTS ' +
+ ( parsedOpts ? parsedOpts.database :
  dbConf.
@@ -1376,16 +1376,13 @@
 ons.
-postgres
+mysql
 .dat
@@ -1386,16 +1386,18 @@
 database
+ )
 , functi

Fix create db hook