不要怂,就是干,撸起袖子干!

Commit 033e9a4a by Mick Hansen

remove mariadb connector, use mysql instead

1 parent f5f58ec7
"use strict";
var AbstractConnectionManager = require('../abstract/connection-manager')
, ConnectionManager
, Utils = require('../../utils')
, Promise = require('../../promise')
, sequelizeErrors = require('../../errors');
ConnectionManager = function(dialect, sequelize) {
AbstractConnectionManager.call(this, dialect, sequelize);
this.sequelize = sequelize;
this.sequelize.config.port = this.sequelize.config.port || 3306;
try {
this.lib = require(sequelize.config.dialectModulePath || 'mariasql');
} catch (err) {
throw new Error('Please install mariasql package manually');
}
};
Utils._.extend(ConnectionManager.prototype, AbstractConnectionManager.prototype);
ConnectionManager.prototype.connect = function(config) {
var self = this;
return new Promise(function (resolve, reject) {
var connectionConfig = {
host: config.host,
port: config.port,
user: config.username,
password: config.password,
db: config.database,
metadata: true
};
if (config.dialectOptions) {
Object.keys(config.dialectOptions).forEach(function(key) {
connectionConfig[key] = config.dialectOptions[key];
});
}
if (connectionConfig.unixSocket) {
delete connectionConfig.host;
delete connectionConfig.port;
}
var connection = new self.lib();
connection.connect(connectionConfig);
connection.on('error', function(err) {
return reject(new sequelizeErrors.ConnectionError(err));
});
connection.on('connect', function() {
return resolve(connection);
});
}).tap(function (connection) {
connection.query("SET time_zone = '" + self.sequelize.options.timezone + "'");
});
};
ConnectionManager.prototype.disconnect = function(connection) {
return new Promise(function (resolve, reject) {
connection.end();
resolve();
});
};
ConnectionManager.prototype.validate = function(connection) {
return connection && connection.state !== 'disconnected';
};
module.exports = ConnectionManager;
'use strict';
var _ = require('lodash')
, MySQL = require('../mysql')
, ConnectionManager = require('./connection-manager')
, Query = require('./query')
, QueryGenerator = require('./query-generator');
var MySQLDialect = require('../mysql');
var MariaDialect = function(sequelize) {
this.sequelize = sequelize;
this.connectionManager = new ConnectionManager(this, sequelize);
this.connectionManager.initPools();
this.QueryGenerator = _.extend({}, QueryGenerator, {
options: sequelize.options,
_dialect: this,
sequelize: sequelize
});
MySQLDialect.call(this, sequelize);
};
MariaDialect.prototype = MySQL.prototype;
MariaDialect.prototype.Query = Query;
MariaDialect.prototype = MySQLDialect.prototype;
MariaDialect.prototype.name = 'mariadb';
module.exports = MariaDialect;
'use strict';
var Utils = require('../../utils');
module.exports = (function() {
var QueryGenerator = {
dialect: 'mariadb',
};
// "MariaDB is a drop-in replacement for MySQL." - so thats exactly what we do, drop in the mysql query generator
return Utils._.extend(Utils._.clone(require('../mysql/query-generator')), QueryGenerator);
})();
'use strict';
var Utils = require('../../utils')
, MysqlQuery = require('../mysql/query');
module.exports = (function() {
var Query = function(client, sequelize, callee, options) {
this.client = client;
this.callee = callee;
this.sequelize = sequelize;
this.options = Utils._.extend({
logging: console.log,
plain: false,
raw: false
}, options || {});
var self = this;
this.checkLoggingOption();
this.promise = new Utils.Promise(function(resolve, reject) {
self.resolve = resolve;
self.reject = reject;
});
};
Utils.inherit(Query, MysqlQuery);
Query.prototype.run = function(sql) {
this.sql = sql;
this.sequelize.log('Executing (' + this.client.uuid + '): ' + this.sql, this.options);
var resultSet = [],
errorDetected = false,
alreadyEnded = false, // This is needed because CALL queries emit 'end' twice...
self = this;
this.client.query(this.sql)
.on('result', function(results) {
results
.on('row', function(row, metadata) {
var type;
for (var prop in row) {
if (row.hasOwnProperty(prop)) {
if (row[prop] === null) {
continue;
}
type = metadata.types[prop];
switch (type) {
case 'TINYINT':
case 'SMALLINT':
case 'INTEGER':
case 'MEDIUMINT':
case 'BIGINT':
case 'YEAR':
row[prop] = parseInt(row[prop], 10);
break;
case 'DECIMAL':
case 'FLOAT':
case 'DOUBLE':
row[prop] = parseFloat(row[prop]);
break;
case 'DATE':
row[prop] = new Date(row[prop]);
break;
case 'TIMESTAMP':
case 'DATETIME':
row[prop] = new Date(row[prop] + self.sequelize.options.timezone);
break;
case 'BIT':
case 'BLOB':
case 'TINYBLOB':
case 'MEDIUMBLOB':
case 'LONGBLOB':
if (metadata.charsetNrs[prop] === 63) { // binary
row[prop] = new Buffer(row[prop]);
}
break;
case 'TIME':
case 'CHAR':
case 'VARCHAR':
case 'SET':
case 'ENUM':
case 'GEOMETRY':
case 'NULL':
break;
default:
// blank
}
}
}
resultSet.push(row);
})
.on('error', function(err) {
errorDetected = true;
self.promise.emit('sql', self.sql);
err.sql = sql;
self.reject(self.formatError(err));
})
.on('end', function(info) {
if (alreadyEnded || errorDetected) {
return;
}
alreadyEnded = true;
self.promise.emit('sql', self.sql);
// we need to figure out whether to send the result set
// or info depending upon the type of query
if (/^call/.test(self.sql.toLowerCase())) {
self.resolve(resultSet);
} else if (/^show/.test(self.sql.toLowerCase()) ||
/^select/.test(self.sql.toLowerCase()) ||
/^describe/.test(self.sql.toLowerCase())) {
self.resolve(self.formatResults(resultSet));
} else {
self.resolve(self.formatResults(info));
}
});
})
.on('error', function(err) {
if (errorDetected) {
return;
}
errorDetected = true;
self.promise.emit('sql', self.sql);
self.reject(err);
})
.setMaxListeners(100);
return this.promise;
};
return Query;
})();
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!