@graffy/pg 0.15.6-alpha.1 → 0.15.8-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/Db.js +392 -0
- package/cjs/filter/filterObject.js +3 -18
- package/cjs/filter/getAst.js +3 -1
- package/cjs/filter/getSql.js +33 -22
- package/cjs/index.js +65 -174
- package/cjs/link/index.js +0 -47
- package/cjs/sql/clauses.js +92 -0
- package/cjs/sql/getArgSql.js +98 -84
- package/cjs/sql/{getIdMeta.js → getMeta.js} +24 -6
- package/cjs/sql/select.js +9 -24
- package/cjs/sql/upsert.js +19 -156
- package/cjs/{sql → test}/expectSql.js +1 -0
- package/cjs/test/setup.js +189 -147
- package/package.json +5 -6
- package/types/Db.d.ts +9 -0
- package/types/index.d.ts +7 -2
- package/types/link/index.d.ts +0 -3
- package/types/sql/clauses.d.ts +8 -0
- package/types/sql/getArgSql.d.ts +17 -18
- package/types/sql/getMeta.d.ts +4 -0
- package/types/sql/select.d.ts +2 -7
- package/cjs/dbRead.js +0 -228
- package/cjs/dbWrite.js +0 -158
- package/cjs/options.js +0 -160
- package/cjs/pool.js +0 -42
- package/cjs/sql/getSelectCols.js +0 -47
- package/types/dbRead.d.ts +0 -1
- package/types/dbWrite.d.ts +0 -1
- package/types/options.d.ts +0 -23
- package/types/pool.d.ts +0 -2
- package/types/sql/getIdMeta.d.ts +0 -4
- package/types/sql/getSelectCols.d.ts +0 -1
package/cjs/index.js
CHANGED
|
@@ -1,187 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _sliceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/slice");
|
|
4
|
-
|
|
5
|
-
var _Array$from = require("@babel/runtime-corejs3/core-js-stable/array/from");
|
|
6
|
-
|
|
7
|
-
var _Symbol = require("@babel/runtime-corejs3/core-js-stable/symbol");
|
|
8
|
-
|
|
9
|
-
var _getIteratorMethod = require("@babel/runtime-corejs3/core-js/get-iterator-method");
|
|
10
|
-
|
|
11
|
-
var _bindInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/bind");
|
|
12
|
-
|
|
13
|
-
var _Array$isArray = require("@babel/runtime-corejs3/core-js-stable/array/is-array");
|
|
14
|
-
|
|
15
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
16
4
|
|
|
17
5
|
exports.__esModule = true;
|
|
18
|
-
exports.
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var _stream = require("@graffy/stream");
|
|
39
|
-
|
|
40
|
-
var _dbRead = _interopRequireDefault(require("./dbRead.js"));
|
|
41
|
-
|
|
42
|
-
var _dbWrite = _interopRequireDefault(require("./dbWrite.js"));
|
|
43
|
-
|
|
44
|
-
var _pool = _interopRequireDefault(require("./pool.js"));
|
|
45
|
-
|
|
46
|
-
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var _context4; var it = typeof _Symbol !== "undefined" && _getIteratorMethod(o) || o["@@iterator"]; if (it) return _bindInstanceProperty(_context4 = (it = it.call(o)).next).call(_context4, it); if (_Array$isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
47
|
-
|
|
48
|
-
function _unsupportedIterableToArray(o, minLen) { var _context3; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = _sliceInstanceProperty(_context3 = Object.prototype.toString.call(o)).call(_context3, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return _Array$from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
49
|
-
|
|
50
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
51
|
-
|
|
52
|
-
// import debug from 'debug';
|
|
53
|
-
// const log = debug('graffy:pg:index');
|
|
54
|
-
// import { format } from '@graffy/testing';
|
|
55
|
-
var _default = function _default(opts) {
|
|
56
|
-
if (opts === void 0) {
|
|
57
|
-
opts = {};
|
|
58
|
-
}
|
|
59
|
-
|
|
6
|
+
exports.pg = void 0;
|
|
7
|
+
|
|
8
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/objectWithoutPropertiesLoose"));
|
|
9
|
+
|
|
10
|
+
var _Db = _interopRequireDefault(require("./Db.js"));
|
|
11
|
+
|
|
12
|
+
var _excluded = ["transactionDb"],
|
|
13
|
+
_excluded2 = ["transactionDb"];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param {{table?: string, idCol?: string, verCol?: string, links?: object, connection?: any}} param0
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
var pg = function pg(_ref) {
|
|
21
|
+
var table = _ref.table,
|
|
22
|
+
idCol = _ref.idCol,
|
|
23
|
+
verCol = _ref.verCol,
|
|
24
|
+
links = _ref.links,
|
|
25
|
+
connection = _ref.connection;
|
|
60
26
|
return function (store) {
|
|
61
27
|
store.on('read', read);
|
|
62
|
-
store.on('write', write);
|
|
63
|
-
|
|
64
|
-
var
|
|
65
|
-
var
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
case 0:
|
|
80
|
-
if (watchers.size) {
|
|
81
|
-
_context.next = 2;
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return _context.abrupt("return");
|
|
86
|
-
|
|
87
|
-
case 2:
|
|
88
|
-
_context.next = 4;
|
|
89
|
-
return (0, _index.readSql)((0, _index.selectUpdatedSince)(timestamp, pgOptions), _pool.default);
|
|
90
|
-
|
|
91
|
-
case 4:
|
|
92
|
-
res = _context.sent;
|
|
93
|
-
|
|
94
|
-
for (_iterator = _createForOfIteratorHelperLoose(res); !(_step = _iterator()).done;) {
|
|
95
|
-
_step$value = _step.value, object = _step$value[0];
|
|
96
|
-
|
|
97
|
-
for (_iterator2 = _createForOfIteratorHelperLoose(watchers); !(_step2 = _iterator2()).done;) {
|
|
98
|
-
_step2$value = _step2.value, query = _step2$value.query, push = _step2$value.push;
|
|
99
|
-
payload = [];
|
|
100
|
-
|
|
101
|
-
for (_iterator3 = _createForOfIteratorHelperLoose(query); !(_step3 = _iterator3()).done;) {
|
|
102
|
-
node = _step3.value;
|
|
103
|
-
args = (0, _common.decodeArgs)(node);
|
|
104
|
-
|
|
105
|
-
if ((0, _common.isPlainObject)(args)) {
|
|
106
|
-
if ((0, _index2.filterObject)(args, object)) payload.push(object);
|
|
107
|
-
} else {
|
|
108
|
-
if (object.id === node.key) payload.push(object);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
push((0, _common.wrap)((0, _sliceInstanceProperty(_common))((0, _common.encodeGraph)(payload), query).known, store.path));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
case 6:
|
|
117
|
-
case "end":
|
|
118
|
-
return _context.stop();
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}, _callee);
|
|
122
|
-
}));
|
|
123
|
-
return _poll.apply(this, arguments);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
(0, _setInterval2.default)(poll, pgOptions.pollInterval);
|
|
127
|
-
|
|
128
|
-
function read(query) {
|
|
129
|
-
return (0, _dbRead.default)(query, pgOptions, store); // log(format(rootQuery));
|
|
130
|
-
// const query = unwrap(rootQuery, store.path);
|
|
131
|
-
// const result = await dbRead(query, pgOptions);
|
|
132
|
-
// const rootResult = slice(
|
|
133
|
-
// finalize(encodeGraph(wrapObject(result, store.path)), rootQuery),
|
|
134
|
-
// rootQuery,
|
|
135
|
-
// ).known;
|
|
136
|
-
// log(format(rootResult));
|
|
137
|
-
// return rootResult;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function write(_x) {
|
|
141
|
-
return _write.apply(this, arguments);
|
|
28
|
+
store.on('write', write); // TODO: Make the defaults smarter using introspection.
|
|
29
|
+
|
|
30
|
+
var prefix = store.path;
|
|
31
|
+
var tableOpts = {
|
|
32
|
+
prefix: prefix,
|
|
33
|
+
table: table || prefix[prefix.length - 1] || 'default',
|
|
34
|
+
idCol: idCol || 'id',
|
|
35
|
+
verCol: verCol || 'updatedAt',
|
|
36
|
+
links: links || {}
|
|
37
|
+
};
|
|
38
|
+
var defaultDb = new _Db.default(connection);
|
|
39
|
+
|
|
40
|
+
function read(query, options) {
|
|
41
|
+
var _options$transactionD = options.transactionDb,
|
|
42
|
+
transactionDb = _options$transactionD === void 0 ? defaultDb : _options$transactionD,
|
|
43
|
+
readOpts = (0, _objectWithoutPropertiesLoose2.default)(options, _excluded);
|
|
44
|
+
return transactionDb.read(query, tableOpts, readOpts);
|
|
142
45
|
}
|
|
143
46
|
|
|
144
|
-
function
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
case 0:
|
|
150
|
-
change = (0, _common.unwrap)(change, store.path);
|
|
151
|
-
_context2.next = 3;
|
|
152
|
-
return (0, _dbWrite.default)(change, pgOptions);
|
|
153
|
-
|
|
154
|
-
case 3:
|
|
155
|
-
return _context2.abrupt("return", (0, _common.wrap)(change, store.path));
|
|
156
|
-
|
|
157
|
-
case 4:
|
|
158
|
-
case "end":
|
|
159
|
-
return _context2.stop();
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}, _callee2);
|
|
163
|
-
}));
|
|
164
|
-
return _write.apply(this, arguments);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function watch(query) {
|
|
168
|
-
query = (0, _common.unwrap)(query, store.path);
|
|
169
|
-
return (0, _stream.makeStream)(function (push) {
|
|
170
|
-
var watcher = {
|
|
171
|
-
query: query,
|
|
172
|
-
push: push
|
|
173
|
-
};
|
|
174
|
-
(0, _dbRead.default)(query, pgOptions).then(function (init) {
|
|
175
|
-
push((0, _common.wrap)((0, _common.finalize)((0, _common.encodeGraph)(init), query), store.path));
|
|
176
|
-
watchers.add(watcher);
|
|
177
|
-
});
|
|
178
|
-
return function () {
|
|
179
|
-
return watchers.delete(watcher);
|
|
180
|
-
};
|
|
181
|
-
});
|
|
47
|
+
function write(change, options) {
|
|
48
|
+
var _options$transactionD2 = options.transactionDb,
|
|
49
|
+
transactionDb = _options$transactionD2 === void 0 ? defaultDb : _options$transactionD2,
|
|
50
|
+
writeOpts = (0, _objectWithoutPropertiesLoose2.default)(options, _excluded2);
|
|
51
|
+
return transactionDb.write(change, tableOpts, writeOpts);
|
|
182
52
|
}
|
|
183
53
|
};
|
|
184
54
|
};
|
|
55
|
+
/*
|
|
56
|
+
TODO: Uncomment and test in another PR.
|
|
57
|
+
|
|
58
|
+
export const transaction = ({ connection }) => {
|
|
59
|
+
store.on('write', (change, options, next) => {
|
|
60
|
+
const client = await pool.connect();
|
|
61
|
+
await client.query('BEGIN');
|
|
62
|
+
const transactionDb = new Db(client);
|
|
63
|
+
|
|
64
|
+
nextOptions = { ...options, transactionDb };
|
|
65
|
+
try {
|
|
66
|
+
const response = await next(change, nextOptions);
|
|
67
|
+
await client.query('COMMIT');
|
|
68
|
+
} catch (e) {
|
|
69
|
+
await client.query('ROLLBACK')
|
|
70
|
+
} finally {
|
|
71
|
+
await client.release();
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
*/
|
|
76
|
+
|
|
185
77
|
|
|
186
|
-
exports.
|
|
187
|
-
module.exports = exports.default;
|
|
78
|
+
exports.pg = pg;
|
package/cjs/link/index.js
CHANGED
|
@@ -16,7 +16,6 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
|
|
|
16
16
|
|
|
17
17
|
exports.__esModule = true;
|
|
18
18
|
exports.linkResult = linkResult;
|
|
19
|
-
exports.linkChange = linkChange;
|
|
20
19
|
|
|
21
20
|
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
|
22
21
|
|
|
@@ -30,8 +29,6 @@ var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-sta
|
|
|
30
29
|
|
|
31
30
|
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
|
|
32
31
|
|
|
33
|
-
var _some = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/some"));
|
|
34
|
-
|
|
35
32
|
var _common = require("@graffy/common");
|
|
36
33
|
|
|
37
34
|
var _testing = require("@graffy/testing");
|
|
@@ -132,48 +129,4 @@ function linkResult(objects, query, _ref) {
|
|
|
132
129
|
|
|
133
130
|
log('Linked Result', (0, _stringify.default)(objects, null, 2), (0, _testing.format)(refQueries));
|
|
134
131
|
return refQueries;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function linkChange(object, _ref2) {
|
|
138
|
-
var linkSpecs = _ref2.links;
|
|
139
|
-
|
|
140
|
-
for (var linkProp in linkSpecs) {
|
|
141
|
-
var _linkSpecs$linkProp = linkSpecs[linkProp],
|
|
142
|
-
target = _linkSpecs$linkProp.target,
|
|
143
|
-
prop = _linkSpecs$linkProp.prop,
|
|
144
|
-
back = _linkSpecs$linkProp.back;
|
|
145
|
-
if (back) continue;
|
|
146
|
-
var targetPath = (0, _common.encodePath)(target);
|
|
147
|
-
var linkPath = (0, _common.encodePath)(linkProp);
|
|
148
|
-
var idPath = (0, _common.encodePath)(prop);
|
|
149
|
-
var link = (0, _common.unwrapObject)(object, linkPath);
|
|
150
|
-
|
|
151
|
-
if (link) {
|
|
152
|
-
var _ret = function () {
|
|
153
|
-
// Remove the link from the object; we don't write it.
|
|
154
|
-
(0, _common.mergeObject)(object, (0, _common.wrapObject)(null, linkPath)); // If the prop of this link is alread present, do nothing more.
|
|
155
|
-
|
|
156
|
-
if ((0, _common.unwrapObject)(object, idPath) !== undefined) return "continue";
|
|
157
|
-
|
|
158
|
-
if (!link.$ref) {
|
|
159
|
-
throw Error("pg_write.missing_ref: " + linkPath.join('.') + " " + (0, _stringify.default)(link));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
var ref = (0, _common.encodePath)(link.$ref);
|
|
163
|
-
|
|
164
|
-
if (ref.length !== targetPath.length + 1 || (0, _some.default)(targetPath).call(targetPath, function (tkey, i) {
|
|
165
|
-
return ref[i] !== tkey;
|
|
166
|
-
})) {
|
|
167
|
-
throw Error("pg_write.incompatible_ref: " + linkPath.join('.') + " " + link.$ref + " " + targetPath.join('.'));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
var value = ref[ref.length - 1];
|
|
171
|
-
(0, _common.mergeObject)(object, (0, _common.wrapObject)(value, idPath));
|
|
172
|
-
}();
|
|
173
|
-
|
|
174
|
-
if (_ret === "continue") continue;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return object;
|
|
179
132
|
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");
|
|
4
|
+
|
|
5
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
6
|
+
|
|
7
|
+
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
|
8
|
+
|
|
9
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
10
|
+
|
|
11
|
+
exports.__esModule = true;
|
|
12
|
+
exports.getUpdates = exports.getInsert = exports.getSelectCols = exports.getJsonBuildObject = exports.nowTimestamp = void 0;
|
|
13
|
+
|
|
14
|
+
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
15
|
+
|
|
16
|
+
var _entries = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/entries"));
|
|
17
|
+
|
|
18
|
+
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
|
19
|
+
|
|
20
|
+
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
21
|
+
|
|
22
|
+
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
|
23
|
+
|
|
24
|
+
var _taggedTemplateLiteralLoose2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/taggedTemplateLiteralLoose"));
|
|
25
|
+
|
|
26
|
+
var _sqlTemplateTag = _interopRequireWildcard(require("sql-template-tag"));
|
|
27
|
+
|
|
28
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8;
|
|
29
|
+
|
|
30
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
31
|
+
|
|
32
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
33
|
+
|
|
34
|
+
var nowTimestamp = (0, _sqlTemplateTag.default)(_templateObject || (_templateObject = (0, _taggedTemplateLiteralLoose2.default)(["cast(extract(epoch from now()) as integer)"])));
|
|
35
|
+
exports.nowTimestamp = nowTimestamp;
|
|
36
|
+
|
|
37
|
+
var getJsonBuildObject = function getJsonBuildObject(variadic) {
|
|
38
|
+
var _context;
|
|
39
|
+
|
|
40
|
+
var args = (0, _sqlTemplateTag.join)((0, _map.default)(_context = (0, _entries.default)(variadic)).call(_context, function (_ref) {
|
|
41
|
+
var name = _ref[0],
|
|
42
|
+
value = _ref[1];
|
|
43
|
+
return (0, _sqlTemplateTag.default)(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteralLoose2.default)(["'", "', ", ""])), (0, _sqlTemplateTag.raw)(name), value);
|
|
44
|
+
}));
|
|
45
|
+
return (0, _sqlTemplateTag.default)(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteralLoose2.default)(["jsonb_build_object(", ")"])), args);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
exports.getJsonBuildObject = getJsonBuildObject;
|
|
49
|
+
|
|
50
|
+
var getSelectCols = function getSelectCols(table) {
|
|
51
|
+
// TODO: When we have a query object, get only the requested columns.
|
|
52
|
+
return (0, _sqlTemplateTag.default)(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteralLoose2.default)(["to_jsonb(\"", "\")"])), (0, _sqlTemplateTag.raw)(table));
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
exports.getSelectCols = getSelectCols;
|
|
56
|
+
|
|
57
|
+
var getInsert = function getInsert(row, options) {
|
|
58
|
+
var _context2, _context3, _context4;
|
|
59
|
+
|
|
60
|
+
var cols = [];
|
|
61
|
+
var vals = [];
|
|
62
|
+
(0, _forEach.default)(_context2 = (0, _concat.default)(_context3 = (0, _filter.default)(_context4 = (0, _entries.default)(row)).call(_context4, function (_ref2) {
|
|
63
|
+
var name = _ref2[0];
|
|
64
|
+
return name !== options.verCol && name[0] !== '$';
|
|
65
|
+
})).call(_context3, [[options.verCol, nowTimestamp]])).call(_context2, function (_ref3) {
|
|
66
|
+
var col = _ref3[0],
|
|
67
|
+
val = _ref3[1];
|
|
68
|
+
cols.push((0, _sqlTemplateTag.default)(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteralLoose2.default)(["\"", "\""])), (0, _sqlTemplateTag.raw)(col)));
|
|
69
|
+
vals.push(val);
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
cols: (0, _sqlTemplateTag.join)(cols, ', '),
|
|
73
|
+
vals: (0, _sqlTemplateTag.join)(vals, ', ')
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
exports.getInsert = getInsert;
|
|
78
|
+
|
|
79
|
+
var getUpdates = function getUpdates(row, options) {
|
|
80
|
+
var _context5, _context6, _context7;
|
|
81
|
+
|
|
82
|
+
return (0, _sqlTemplateTag.join)((0, _concat.default)(_context5 = (0, _map.default)(_context6 = (0, _filter.default)(_context7 = (0, _entries.default)(row)).call(_context7, function (_ref4) {
|
|
83
|
+
var name = _ref4[0];
|
|
84
|
+
return name !== options.idCol && name[0] !== '$';
|
|
85
|
+
})).call(_context6, function (_ref5) {
|
|
86
|
+
var name = _ref5[0],
|
|
87
|
+
value = _ref5[1];
|
|
88
|
+
return (0, _sqlTemplateTag.default)(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteralLoose2.default)(["\"", "\" = ", ""])), (0, _sqlTemplateTag.raw)(name), typeof value === 'object' && value ? (0, _sqlTemplateTag.default)(_templateObject7 || (_templateObject7 = (0, _taggedTemplateLiteralLoose2.default)(["\"", "\" || ", ""])), (0, _sqlTemplateTag.raw)(name), value) : value);
|
|
89
|
+
})).call(_context5, (0, _sqlTemplateTag.default)(_templateObject8 || (_templateObject8 = (0, _taggedTemplateLiteralLoose2.default)(["\"", "\" = ", ""])), (0, _sqlTemplateTag.raw)(options.verCol), nowTimestamp)), ', ');
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
exports.getUpdates = getUpdates;
|