2014-09-01 17:18:45 +02:00
|
|
|
'use strict';
|
|
|
|
|
2014-06-09 16:27:03 -04:00
|
|
|
// MySQL2 Client
|
|
|
|
// -------
|
2015-04-19 16:31:52 -04:00
|
|
|
var inherits = require('inherits')
|
|
|
|
var Client_MySQL = require('../mysql')
|
|
|
|
var Promise = require('../../promise')
|
|
|
|
var pick = require('lodash/object/pick')
|
|
|
|
var configOptions = ['user', 'database', 'host', 'password', 'ssl', 'connection', 'stream']
|
2014-09-03 10:48:25 +02:00
|
|
|
|
2014-06-09 16:27:03 -04:00
|
|
|
var mysql2;
|
|
|
|
|
|
|
|
// Always initialize with the "QueryBuilder" and "QueryCompiler"
|
|
|
|
// objects, which extend the base 'lib/query/builder' and
|
|
|
|
// 'lib/query/compiler', respectively.
|
2015-04-17 15:00:08 -04:00
|
|
|
function Client_MySQL2(config) {
|
2015-04-19 16:31:52 -04:00
|
|
|
Client_MySQL.call(this, config)
|
2014-06-09 16:27:03 -04:00
|
|
|
}
|
2015-04-19 16:31:52 -04:00
|
|
|
inherits(Client_MySQL2, Client_MySQL)
|
2014-06-09 16:27:03 -04:00
|
|
|
|
|
|
|
// The "dialect", for reference elsewhere.
|
2015-04-19 16:31:52 -04:00
|
|
|
Client_MySQL2.prototype.driverName = 'mysql2';
|
2014-06-09 16:27:03 -04:00
|
|
|
|
|
|
|
// Get a raw connection, called by the `pool` whenever a new
|
|
|
|
// connection needs to be added to the pool.
|
|
|
|
Client_MySQL2.prototype.acquireRawConnection = function() {
|
2015-04-19 16:31:52 -04:00
|
|
|
var connection = mysql2.createConnection(pick(this.connectionSettings, configOptions))
|
2014-10-03 11:03:34 -04:00
|
|
|
this.databaseName = connection.config.database;
|
2014-06-09 16:27:03 -04:00
|
|
|
return new Promise(function(resolver, rejecter) {
|
|
|
|
connection.connect(function(err) {
|
2015-04-19 16:31:52 -04:00
|
|
|
if (err) return rejecter(err)
|
|
|
|
resolver(connection)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2014-06-09 16:27:03 -04:00
|
|
|
|
2014-09-03 10:48:25 +02:00
|
|
|
module.exports = Client_MySQL2;
|