interface.js
3.16 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
'use strict';
exports.__esModule = true;
var _each2 = require('lodash/each');
var _each3 = _interopRequireDefault(_each2);
var _clone2 = require('lodash/clone');
var _clone3 = _interopRequireDefault(_clone2);
var _map2 = require('lodash/map');
var _map3 = _interopRequireDefault(_map2);
var _isArray2 = require('lodash/isArray');
var _isArray3 = _interopRequireDefault(_isArray2);
exports.default = function (Target) {
Target.prototype.toQuery = function (tz) {
var _this = this;
var data = this.toSQL(this._method, tz);
if (!(0, _isArray3.default)(data)) data = [data];
return (0, _map3.default)(data, function (statement) {
return _this.client._formatQuery(statement.sql, statement.bindings, tz);
}).join(';\n');
};
// Create a new instance of the `Runner`, passing in the current object.
Target.prototype.then = function () /* onFulfilled, onRejected */{
var result = this.client.runner(this).run();
return result.then.apply(result, arguments);
};
// Add additional "options" to the builder. Typically used for client specific
// items, like the `mysql` and `sqlite3` drivers.
Target.prototype.options = function (opts) {
this._options = this._options || [];
this._options.push((0, _clone3.default)(opts) || {});
return this;
};
// Sets an explicit "connnection" we wish to use for this query.
Target.prototype.connection = function (connection) {
this._connection = connection;
return this;
};
// Set a debug flag for the current schema query stack.
Target.prototype.debug = function (enabled) {
this._debug = arguments.length ? enabled : true;
return this;
};
// Set the transaction object for this query.
Target.prototype.transacting = function (t) {
if (t && t.client) {
if (!t.client.transacting) {
helpers.warn('Invalid transaction value: ' + t.client);
} else {
this.client = t.client;
}
}
return this;
};
// Initializes a stream.
Target.prototype.stream = function (options) {
return this.client.runner(this).stream(options);
};
// Initialize a stream & pipe automatically.
Target.prototype.pipe = function (writable, options) {
return this.client.runner(this).pipe(writable, options);
};
// Creates a method which "coerces" to a promise, by calling a
// "then" method on the current `Target`
(0, _each3.default)(['bind', 'catch', 'finally', 'asCallback', 'spread', 'map', 'reduce', 'tap', 'thenReturn', 'return', 'yield', 'ensure', 'reflect', 'get', 'mapSeries', 'delay'], function (method) {
Target.prototype[method] = function () {
var promise = this.then();
return promise[method].apply(promise, arguments);
};
});
};
var _helpers = require('./helpers');
var helpers = _interopRequireWildcard(_helpers);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
module.exports = exports['default'];