2014-04-15 11:43:47 -04:00
|
|
|
// MySQL Query Builder & Compiler
|
|
|
|
// ------
|
2014-04-08 16:25:57 -04:00
|
|
|
module.exports = function(client) {
|
|
|
|
|
|
|
|
var inherits = require('inherits');
|
|
|
|
var QueryBuilder = require('../../query/builder');
|
|
|
|
var QueryCompiler = require('../../query/compiler');
|
|
|
|
|
|
|
|
// Query Builder
|
2014-04-15 11:43:47 -04:00
|
|
|
// -------
|
2014-04-08 16:25:57 -04:00
|
|
|
|
|
|
|
// Extend the QueryBuilder base class to include the "Formatter"
|
|
|
|
// which has been defined on the client, as well as the
|
|
|
|
function QueryBuilder_MySQL() {
|
|
|
|
this.client = client;
|
|
|
|
QueryBuilder.apply(this, arguments);
|
|
|
|
}
|
|
|
|
inherits(QueryBuilder_MySQL, QueryBuilder);
|
|
|
|
|
|
|
|
// Query Compiler
|
2014-04-15 11:43:47 -04:00
|
|
|
// -------
|
2014-04-08 16:25:57 -04:00
|
|
|
|
|
|
|
// Set the "Formatter" to use for the queries,
|
|
|
|
// ensuring that all parameterized values (even across sub-queries)
|
|
|
|
// are properly built into the same query.
|
|
|
|
function QueryCompiler_MySQL() {
|
|
|
|
this.formatter = new client.Formatter();
|
|
|
|
QueryCompiler.apply(this, arguments);
|
|
|
|
}
|
2014-04-15 13:10:32 -04:00
|
|
|
inherits(QueryCompiler_MySQL, QueryCompiler);
|
2014-04-08 16:25:57 -04:00
|
|
|
|
2014-04-16 01:23:50 -04:00
|
|
|
QueryCompiler_MySQL.prototype._emptyInsertValue = '() values ()';
|
2014-04-08 16:25:57 -04:00
|
|
|
|
2014-04-15 13:10:32 -04:00
|
|
|
// Update method, including joins, wheres, order & limits.
|
|
|
|
QueryCompiler_MySQL.prototype.update = function() {
|
|
|
|
var join = this.join();
|
|
|
|
var updates = this._prepUpdate(this.single.update);
|
|
|
|
var where = this.where();
|
|
|
|
var order = this.order();
|
|
|
|
var limit = this.limit();
|
|
|
|
return 'update ' + this.tableName +
|
|
|
|
(join ? ' ' + join : '') +
|
|
|
|
' set ' + updates.join(', ') +
|
|
|
|
(where ? ' ' + where : '') +
|
|
|
|
(order ? ' ' + order : '') +
|
|
|
|
(limit ? ' ' + limit : '');
|
|
|
|
};
|
2014-04-08 16:25:57 -04:00
|
|
|
|
2014-04-15 13:10:32 -04:00
|
|
|
QueryCompiler_MySQL.prototype.forUpdate = function() {
|
|
|
|
return 'for update';
|
|
|
|
};
|
|
|
|
QueryCompiler_MySQL.prototype.forShare = function() {
|
|
|
|
return 'lock in share mode';
|
2014-04-08 16:25:57 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Set the QueryBuilder & QueryCompiler on the client object,
|
|
|
|
// incase anyone wants to modify things to suit their own purposes.
|
|
|
|
client.QueryBuilder = QueryBuilder_MySQL;
|
|
|
|
client.QueryCompiler = QueryCompiler_MySQL;
|
|
|
|
|
|
|
|
};
|