query.js
1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
var Utils = require('../../utils')
, AbstractQuery = require('../abstract/query')
, uuid = require('node-uuid');
module.exports = (function() {
var Query = function(connection, sequelize, callee, options) {
this.connection = connection;
this.callee = callee;
this.sequelize = sequelize;
this.uuid = uuid.v4();
this.options = Utils._.extend({
logging: console.log,
plain: false,
raw: false
}, options || {});
var self = this;
this.checkLoggingOption();
};
Utils.inherit(Query, AbstractQuery);
Query.prototype.run = function(sql) {
var self = this;
this.sql = sql;
if (this.options.logging !== false) {
this.sequelize.log('Executing (' + this.connection.uuid + '): ' + this.sql);
}
var promise = new Utils.Promise(function(resolve, reject) {
console.log(self.sql);
self
.connection
.lib
.execute(self.connection.config, { query: self.sql })
.then(
function (data) { resolve(data.result); },
function (err) { reject(err); }
);
});
return promise;
};
return Query;
})();