query-core 0.1.5 → 0.1.9

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/lib/client.js ADDED
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var build_1 = require("./build");
4
+ var map_1 = require("./map");
5
+ function buildStatements(s) {
6
+ var d = [];
7
+ if (!s || s.length === 0) {
8
+ return d;
9
+ }
10
+ for (var _i = 0, s_1 = s; _i < s_1.length; _i++) {
11
+ var t = s_1[_i];
12
+ var dates = toDates(t.params);
13
+ var j = { query: t.query, params: t.params, dates: dates };
14
+ d.push(j);
15
+ }
16
+ return d;
17
+ }
18
+ exports.buildStatements = buildStatements;
19
+ function toDates(args) {
20
+ var d = [];
21
+ if (!args || args.length === 0) {
22
+ return d;
23
+ }
24
+ var l = args.length;
25
+ for (var i = 0; i < l; i++) {
26
+ if (args[i] && args[i] instanceof Date) {
27
+ d.push(i);
28
+ }
29
+ }
30
+ return d;
31
+ }
32
+ exports.toDates = toDates;
33
+ var ProxyClient = (function () {
34
+ function ProxyClient(httpRequest, url) {
35
+ this.httpRequest = httpRequest;
36
+ this.url = url;
37
+ this.query = this.query.bind(this);
38
+ this.exec = this.exec.bind(this);
39
+ this.execBatch = this.execBatch.bind(this);
40
+ this.insert = this.insert.bind(this);
41
+ this.update = this.update.bind(this);
42
+ this.insertBatch = this.insertBatch.bind(this);
43
+ this.updateBatch = this.updateBatch.bind(this);
44
+ this.insertWithTx = this.insertWithTx.bind(this);
45
+ this.updateWithTx = this.updateWithTx.bind(this);
46
+ this.insertBatchWithTx = this.insertBatchWithTx.bind(this);
47
+ this.updateBatchWithTx = this.updateBatchWithTx.bind(this);
48
+ this.beginTransaction = this.beginTransaction.bind(this);
49
+ this.commitTransaction = this.commitTransaction.bind(this);
50
+ this.rollbackTransaction = this.rollbackTransaction.bind(this);
51
+ this.queryWithTx = this.queryWithTx.bind(this);
52
+ this.execWithTx = this.execWithTx.bind(this);
53
+ this.execBatchWithTx = this.execBatchWithTx.bind(this);
54
+ }
55
+ ProxyClient.prototype.query = function (sql, args, m, bools) {
56
+ var dates = toDates(args);
57
+ var j = { query: sql, params: args, dates: dates };
58
+ if (m || bools) {
59
+ return this.httpRequest.post(this.url + '/query', j).then(function (r) { return map_1.handleResults(r, m, bools); });
60
+ }
61
+ else {
62
+ return this.httpRequest.post(this.url + '/query', j);
63
+ }
64
+ };
65
+ ProxyClient.prototype.exec = function (sql, args) {
66
+ var dates = toDates(args);
67
+ var j = { query: sql, params: args, dates: dates };
68
+ return this.httpRequest.post(this.url + '/exec', j);
69
+ };
70
+ ProxyClient.prototype.execBatch = function (stmts) {
71
+ var d = buildStatements(stmts);
72
+ return this.httpRequest.post(this.url + '/exec-batch', d);
73
+ };
74
+ ProxyClient.prototype.beginTransaction = function (timeout) {
75
+ var st = (timeout && timeout > 0 ? '?timeout=' + timeout : '');
76
+ return this.httpRequest.post(this.url + '/begin' + st, '');
77
+ };
78
+ ProxyClient.prototype.commitTransaction = function (tx) {
79
+ return this.httpRequest.post(this.url + '/end?tx=' + tx, '');
80
+ };
81
+ ProxyClient.prototype.rollbackTransaction = function (tx) {
82
+ return this.httpRequest.post(this.url + '/end?roleback=true&tx=' + tx, '');
83
+ };
84
+ ProxyClient.prototype.queryWithTx = function (tx, commit, sql, args, m, bools) {
85
+ var dates = toDates(args);
86
+ var j = { query: sql, params: args, dates: dates };
87
+ var sc = (commit ? '&commit=true' : '');
88
+ if (m || bools) {
89
+ return this.httpRequest.post(this.url + '/query?tx=' + tx + sc, j).then(function (r) { return map_1.handleResults(r, m, bools); });
90
+ }
91
+ else {
92
+ return this.httpRequest.post(this.url + '/query?tx=' + tx + sc, j);
93
+ }
94
+ };
95
+ ProxyClient.prototype.execWithTx = function (tx, commit, sql, args) {
96
+ var dates = toDates(args);
97
+ var j = { query: sql, params: args, dates: dates };
98
+ var sc = (commit ? '&commit=true' : '');
99
+ return this.httpRequest.post(this.url + '/exec?tx=' + tx + sc, j);
100
+ };
101
+ ProxyClient.prototype.execBatchWithTx = function (tx, commit, stmts) {
102
+ var d = buildStatements(stmts);
103
+ var sc = (commit ? '&commit=true' : '');
104
+ return this.httpRequest.post(this.url + '/exec-batch?tx=' + tx + sc, d);
105
+ };
106
+ ProxyClient.prototype.insert = function (table, attrs, obj, buildParam, ver) {
107
+ var s = build_1.buildToInsert(obj, table, attrs, buildParam, ver);
108
+ if (s) {
109
+ return this.exec(s.query, s.params);
110
+ }
111
+ else {
112
+ return Promise.resolve(-1);
113
+ }
114
+ };
115
+ ProxyClient.prototype.update = function (table, attrs, obj, buildParam, ver) {
116
+ var s = build_1.buildToUpdate(obj, table, attrs, buildParam, ver);
117
+ if (s) {
118
+ return this.exec(s.query, s.params);
119
+ }
120
+ else {
121
+ return Promise.resolve(-1);
122
+ }
123
+ };
124
+ ProxyClient.prototype.insertBatch = function (table, attrs, objs, buildParam, driver) {
125
+ var s = build_1.buildToInsertBatch(objs, table, attrs, buildParam);
126
+ if (s) {
127
+ return this.exec(s.query, s.params);
128
+ }
129
+ else {
130
+ return Promise.resolve(-1);
131
+ }
132
+ };
133
+ ProxyClient.prototype.updateBatch = function (table, attrs, objs, buildParam, notSkipInvalid) {
134
+ var s = build_1.buildToUpdateBatch(objs, table, attrs, buildParam, notSkipInvalid);
135
+ if (s && s.length > 0) {
136
+ return this.execBatch(s);
137
+ }
138
+ else {
139
+ return Promise.resolve(-1);
140
+ }
141
+ };
142
+ ProxyClient.prototype.insertWithTx = function (tx, commit, table, attrs, obj, buildParam, ver) {
143
+ var s = build_1.buildToInsert(obj, table, attrs, buildParam, ver);
144
+ if (s) {
145
+ return this.execWithTx(tx, commit, s.query, s.params);
146
+ }
147
+ else {
148
+ return Promise.resolve(-1);
149
+ }
150
+ };
151
+ ProxyClient.prototype.updateWithTx = function (tx, commit, table, attrs, obj, buildParam, ver) {
152
+ var s = build_1.buildToUpdate(obj, table, attrs, buildParam, ver);
153
+ if (s) {
154
+ return this.execWithTx(tx, commit, s.query, s.params);
155
+ }
156
+ else {
157
+ return Promise.resolve(-1);
158
+ }
159
+ };
160
+ ProxyClient.prototype.insertBatchWithTx = function (tx, commit, table, attrs, objs, buildParam, driver) {
161
+ var s = build_1.buildToInsertBatch(objs, table, attrs, buildParam);
162
+ if (s) {
163
+ return this.execWithTx(tx, commit, s.query, s.params);
164
+ }
165
+ else {
166
+ return Promise.resolve(-1);
167
+ }
168
+ };
169
+ ProxyClient.prototype.updateBatchWithTx = function (tx, commit, table, attrs, objs, buildParam, notSkipInvalid) {
170
+ var s = build_1.buildToUpdateBatch(objs, table, attrs, buildParam, notSkipInvalid);
171
+ if (s && s.length > 0) {
172
+ return this.execBatchWithTx(tx, commit, s);
173
+ }
174
+ else {
175
+ return Promise.resolve(-1);
176
+ }
177
+ };
178
+ return ProxyClient;
179
+ }());
180
+ exports.ProxyClient = ProxyClient;
package/lib/index.js CHANGED
@@ -4,10 +4,24 @@ function __export(m) {
4
4
  }
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var services_1 = require("./services");
7
+ exports.createGenericSearchRepository = services_1.createSqlSearchWriter;
8
+ exports.createGenericSearchService = services_1.createSqlSearchWriter;
9
+ exports.createRepository = services_1.createSqlSearchWriter;
10
+ exports.createService = services_1.createSqlSearchWriter;
7
11
  exports.createGenericRepository = services_1.createSqlWriter;
8
12
  exports.createGenericService = services_1.createSqlWriter;
9
13
  exports.SqlLoadRepository = services_1.SqlLoader;
10
14
  exports.SqlLoadService = services_1.SqlLoader;
15
+ exports.ViewSearchRepository = services_1.SqlSearchLoader;
16
+ exports.ViewSearchService = services_1.SqlSearchLoader;
17
+ exports.SearchRepository = services_1.SqlSearchLoader;
18
+ exports.SearchService = services_1.SqlSearchLoader;
19
+ exports.GenericSearchRepository = services_1.SqlSearchWriter;
20
+ exports.GenericSearchService = services_1.SqlSearchWriter;
21
+ exports.SqlRepository = services_1.SqlSearchWriter;
22
+ exports.SqlService = services_1.SqlSearchWriter;
23
+ exports.Repository = services_1.SqlSearchWriter;
24
+ exports.Service = services_1.SqlSearchWriter;
11
25
  exports.SqlGenericRepository = services_1.SqlWriter;
12
26
  exports.SqlGenericService = services_1.SqlWriter;
13
27
  __export(require("./build"));
@@ -16,6 +30,7 @@ __export(require("./batch"));
16
30
  __export(require("./query"));
17
31
  __export(require("./search"));
18
32
  __export(require("./SearchBuilder"));
33
+ __export(require("./client"));
19
34
  var resource = (function () {
20
35
  function resource() {
21
36
  }
@@ -69,49 +84,6 @@ function toArray(arr) {
69
84
  return p;
70
85
  }
71
86
  exports.toArray = toArray;
72
- function handleResults(r, m, bools) {
73
- if (m) {
74
- var res = mapArray(r, m);
75
- if (bools && bools.length > 0) {
76
- return handleBool(res, bools);
77
- }
78
- else {
79
- return res;
80
- }
81
- }
82
- else {
83
- if (bools && bools.length > 0) {
84
- return handleBool(r, bools);
85
- }
86
- else {
87
- return r;
88
- }
89
- }
90
- }
91
- exports.handleResults = handleResults;
92
- function handleBool(objs, bools) {
93
- if (!bools || bools.length === 0 || !objs) {
94
- return objs;
95
- }
96
- for (var _i = 0, objs_1 = objs; _i < objs_1.length; _i++) {
97
- var obj = objs_1[_i];
98
- for (var _a = 0, bools_1 = bools; _a < bools_1.length; _a++) {
99
- var field = bools_1[_a];
100
- var value = obj[field.name];
101
- if (value != null && value !== undefined) {
102
- var b = field.true;
103
- if (b == null || b === undefined) {
104
- obj[field.name] = ('1' == value || 'T' == value || 'Y' == value);
105
- }
106
- else {
107
- obj[field.name] = (value == b ? true : false);
108
- }
109
- }
110
- }
111
- }
112
- return objs;
113
- }
114
- exports.handleBool = handleBool;
115
87
  function map(obj, m) {
116
88
  if (!m) {
117
89
  return obj;
@@ -133,30 +105,3 @@ function map(obj, m) {
133
105
  return obj2;
134
106
  }
135
107
  exports.map = map;
136
- function mapArray(results, m) {
137
- if (!m) {
138
- return results;
139
- }
140
- var mkeys = Object.keys(m);
141
- if (mkeys.length === 0) {
142
- return results;
143
- }
144
- var objs = [];
145
- var length = results.length;
146
- for (var i = 0; i < length; i++) {
147
- var obj = results[i];
148
- var obj2 = {};
149
- var keys = Object.keys(obj);
150
- for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) {
151
- var key = keys_2[_i];
152
- var k0 = m[key];
153
- if (!k0) {
154
- k0 = key;
155
- }
156
- obj2[k0] = obj[key];
157
- }
158
- objs.push(obj2);
159
- }
160
- return objs;
161
- }
162
- exports.mapArray = mapArray;
package/lib/map.js ADDED
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function mapArray(results, m) {
4
+ if (!m) {
5
+ return results;
6
+ }
7
+ var mkeys = Object.keys(m);
8
+ if (mkeys.length === 0) {
9
+ return results;
10
+ }
11
+ var objs = [];
12
+ var length = results.length;
13
+ for (var i = 0; i < length; i++) {
14
+ var obj = results[i];
15
+ var obj2 = {};
16
+ var keys = Object.keys(obj);
17
+ for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
18
+ var key = keys_1[_i];
19
+ var k0 = m[key];
20
+ if (!k0) {
21
+ k0 = key;
22
+ }
23
+ obj2[k0] = obj[key];
24
+ }
25
+ objs.push(obj2);
26
+ }
27
+ return objs;
28
+ }
29
+ exports.mapArray = mapArray;
30
+ function handleResults(r, m, bools) {
31
+ if (m) {
32
+ var res = mapArray(r, m);
33
+ if (bools && bools.length > 0) {
34
+ return handleBool(res, bools);
35
+ }
36
+ else {
37
+ return res;
38
+ }
39
+ }
40
+ else {
41
+ if (bools && bools.length > 0) {
42
+ return handleBool(r, bools);
43
+ }
44
+ else {
45
+ return r;
46
+ }
47
+ }
48
+ }
49
+ exports.handleResults = handleResults;
50
+ function handleBool(objs, bools) {
51
+ if (!bools || bools.length === 0 || !objs) {
52
+ return objs;
53
+ }
54
+ for (var _i = 0, objs_1 = objs; _i < objs_1.length; _i++) {
55
+ var obj = objs_1[_i];
56
+ var o = obj;
57
+ for (var _a = 0, bools_1 = bools; _a < bools_1.length; _a++) {
58
+ var field = bools_1[_a];
59
+ if (field.name) {
60
+ var v = o[field.name];
61
+ if (typeof v !== 'boolean' && v != null && v !== undefined) {
62
+ var b = field.true;
63
+ if (b == null || b === undefined) {
64
+ o[field.name] = ('true' == v || '1' == v || 't' == v || 'y' == v || 'on' == v);
65
+ }
66
+ else {
67
+ o[field.name] = (v == b ? true : false);
68
+ }
69
+ }
70
+ }
71
+ }
72
+ }
73
+ return objs;
74
+ }
75
+ exports.handleBool = handleBool;
package/lib/query.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ var build_1 = require("./build");
3
4
  function buildSort(sort, map) {
4
5
  if (!sort || sort.length === 0) {
5
6
  return '';
@@ -44,7 +45,7 @@ function getField(name, map) {
44
45
  }
45
46
  exports.getField = getField;
46
47
  function buildMsSQLParam(i) {
47
- return '@p' + i;
48
+ return '@' + i;
48
49
  }
49
50
  exports.buildMsSQLParam = buildMsSQLParam;
50
51
  function buildOracleParam(i) {
@@ -55,7 +56,11 @@ function buildDollarParam(i) {
55
56
  return '$' + i;
56
57
  }
57
58
  exports.buildDollarParam = buildDollarParam;
58
- function buildQuery(s, bparam, table, attrs, sort, fields, sq, strExcluding, buildSort3) {
59
+ function buildQuery(filter, bparam, table, attrs, sort, fields, sq, strExcluding, buildSort3) {
60
+ if (!table || !attrs) {
61
+ return undefined;
62
+ }
63
+ var s = filter;
59
64
  var like = 'like';
60
65
  var param;
61
66
  if (typeof bparam === 'string') {
@@ -144,7 +149,18 @@ function buildQuery(s, bparam, table, attrs, sort, fields, sq, strExcluding, bui
144
149
  args.push(v);
145
150
  }
146
151
  else if (typeof v === 'object') {
147
- if (attr.type === 'date' || attr.type === 'datetime') {
152
+ if (Array.isArray(v)) {
153
+ if (v.length > 0) {
154
+ var ps = build_1.params(v.length, param, i - 1);
155
+ i = i + v.length;
156
+ for (var _a = 0, v_1 = v; _a < v_1.length; _a++) {
157
+ var sv = v_1[_a];
158
+ args.push(sv);
159
+ }
160
+ filters.push(field + " in (" + ps.join(',') + ")");
161
+ }
162
+ }
163
+ else if (attr.type === 'date' || attr.type === 'datetime') {
148
164
  if (isDateRange(v)) {
149
165
  if (v['max']) {
150
166
  filters.push(field + " <= " + param(i++));
@@ -205,8 +221,8 @@ function buildQuery(s, bparam, table, attrs, sort, fields, sq, strExcluding, bui
205
221
  if (idField && excluding && excluding.length > 0) {
206
222
  var l = excluding.length;
207
223
  var ps = [];
208
- for (var _a = 0, excluding_1 = excluding; _a < excluding_1.length; _a++) {
209
- var k = excluding_1[_a];
224
+ for (var _b = 0, excluding_1 = excluding; _b < excluding_1.length; _b++) {
225
+ var k = excluding_1[_b];
210
226
  if (k != null && k !== undefined) {
211
227
  if (typeof k === 'number') {
212
228
  ps.push(k.toString());
@@ -222,8 +238,8 @@ function buildQuery(s, bparam, table, attrs, sort, fields, sq, strExcluding, bui
222
238
  if (q && attrs) {
223
239
  var qkeys = Object.keys(attrs);
224
240
  var qfilters = [];
225
- for (var _b = 0, qkeys_1 = qkeys; _b < qkeys_1.length; _b++) {
226
- var field = qkeys_1[_b];
241
+ for (var _c = 0, qkeys_1 = qkeys; _c < qkeys_1.length; _c++) {
242
+ var field = qkeys_1[_c];
227
243
  var attr = attrs[field];
228
244
  if (attr.q && (attr.type === undefined || attr.type === 'string') && !ex.includes(field)) {
229
245
  if (attr.match === 'equal') {
@@ -238,7 +254,7 @@ function buildQuery(s, bparam, table, attrs, sort, fields, sq, strExcluding, bui
238
254
  qfilters.push(field + " " + like + " " + param(i++));
239
255
  args.push('%' + q + '%');
240
256
  }
241
- c.push(buildQ(field, attr.match, q));
257
+ c.push(buildQ(field, q, attr.match));
242
258
  }
243
259
  }
244
260
  if (qfilters.length > 0) {
@@ -296,7 +312,7 @@ function isEmpty(s) {
296
312
  return !(s && s.length > 0);
297
313
  }
298
314
  exports.isEmpty = isEmpty;
299
- function buildQ(field, match, q) {
315
+ function buildQ(field, q, match) {
300
316
  var o = {};
301
317
  if (match === 'equal') {
302
318
  o[field] = q;
package/lib/search.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  function buildFromQuery(query, sql, params, limit, offset, mp, bools, provider, totalCol) {
4
- if (limit <= 0) {
4
+ if (!limit || limit <= 0) {
5
5
  return query(sql, params, mp, bools).then(function (list) {
6
6
  var total = (list ? list.length : undefined);
7
7
  return { list: list, total: total };
@@ -78,6 +78,9 @@ function buildPagingQueryForOracle(sql, limit, offset, total) {
78
78
  if (!total || total.length === 0) {
79
79
  total = 'total';
80
80
  }
81
+ if (!offset) {
82
+ offset = 0;
83
+ }
81
84
  var l = d.length;
82
85
  var i = sql.indexOf(d);
83
86
  if (i < 0) {
package/lib/services.js CHANGED
@@ -21,16 +21,19 @@ var SqlLoader = (function () {
21
21
  this.param = param;
22
22
  this.fromDB = fromDB;
23
23
  if (Array.isArray(attrs)) {
24
- this.keys = build_1.attributes(attrs);
24
+ this.primaryKeys = build_1.attributes(attrs);
25
+ this.attributes = {};
25
26
  }
26
27
  else {
27
28
  var m = build_1.metadata(attrs);
28
29
  this.attributes = attrs;
29
- this.keys = m.keys;
30
+ this.primaryKeys = m.keys;
30
31
  this.map = m.map;
31
32
  this.bools = m.bools;
32
33
  }
33
- this.metadata = this.metadata.bind(this);
34
+ if (this.metadata) {
35
+ this.metadata = this.metadata.bind(this);
36
+ }
34
37
  this.all = this.all.bind(this);
35
38
  this.load = this.load.bind(this);
36
39
  this.exist = this.exist.bind(this);
@@ -42,17 +45,20 @@ var SqlLoader = (function () {
42
45
  var sql = "select * from " + this.table;
43
46
  return this.query(sql, [], this.map);
44
47
  };
45
- SqlLoader.prototype.load = function (id) {
46
- var _this = this;
47
- var stmt = build_1.select(id, this.table, this.keys, this.param);
48
- if (this.fromDB) {
49
- return this.query(stmt.query, stmt.params, this.map).then(function (res) {
48
+ SqlLoader.prototype.load = function (id, ctx) {
49
+ var stmt = build_1.select(id, this.table, this.primaryKeys, this.param);
50
+ if (!stmt) {
51
+ throw new Error('cannot build query by id');
52
+ }
53
+ var fn = this.fromDB;
54
+ if (fn) {
55
+ return this.query(stmt.query, stmt.params, this.map, ctx).then(function (res) {
50
56
  if (!res || res.length === 0) {
51
57
  return null;
52
58
  }
53
59
  else {
54
60
  var obj = res[0];
55
- return _this.fromDB(obj);
61
+ return fn(obj);
56
62
  }
57
63
  });
58
64
  }
@@ -60,16 +66,33 @@ var SqlLoader = (function () {
60
66
  return this.query(stmt.query, stmt.params, this.map).then(function (res) { return (!res || res.length === 0) ? null : res[0]; });
61
67
  }
62
68
  };
63
- SqlLoader.prototype.exist = function (id) {
64
- var field = (this.keys[0].field ? this.keys[0].field : this.keys[0].name);
65
- var stmt = build_1.exist(id, this.table, this.keys, this.param, field);
66
- return this.query(stmt.query, stmt.params, this.map).then(function (res) { return (!res || res.length === 0) ? false : true; });
69
+ SqlLoader.prototype.exist = function (id, ctx) {
70
+ var field = (this.primaryKeys[0].field ? this.primaryKeys[0].field : this.primaryKeys[0].name);
71
+ var stmt = build_1.exist(id, this.table, this.primaryKeys, this.param, field);
72
+ if (!stmt) {
73
+ throw new Error('cannot build query by id');
74
+ }
75
+ return this.query(stmt.query, stmt.params, this.map, undefined, ctx).then(function (res) { return (!res || res.length === 0) ? false : true; });
67
76
  };
68
77
  return SqlLoader;
69
78
  }());
70
79
  exports.SqlLoader = SqlLoader;
80
+ var SqlSearchLoader = (function (_super) {
81
+ __extends(SqlSearchLoader, _super);
82
+ function SqlSearchLoader(find, table, query, attrs, param, fromDB) {
83
+ var _this = _super.call(this, table, query, attrs, param, fromDB) || this;
84
+ _this.find = find;
85
+ _this.search = _this.search.bind(_this);
86
+ return _this;
87
+ }
88
+ SqlSearchLoader.prototype.search = function (s, limit, offset, fields) {
89
+ return this.find(s, limit, offset, fields);
90
+ };
91
+ return SqlSearchLoader;
92
+ }(SqlLoader));
93
+ exports.SqlSearchLoader = SqlSearchLoader;
71
94
  function createSqlWriter(table, manager, attrs, buildParam, toDB, fromDB) {
72
- var writer = new SqlWriter(table, manager.query, manager.exec, attrs, buildParam, toDB, fromDB);
95
+ var writer = new SqlWriter(table, manager.query, manager.exec, attrs, buildParam, toDB, fromDB, manager.execBatch);
73
96
  return writer;
74
97
  }
75
98
  exports.createSqlWriter = createSqlWriter;
@@ -90,14 +113,14 @@ var SqlWriter = (function (_super) {
90
113
  _this.delete = _this.delete.bind(_this);
91
114
  return _this;
92
115
  }
93
- SqlWriter.prototype.insert = function (obj) {
116
+ SqlWriter.prototype.insert = function (obj, ctx) {
94
117
  var obj2 = obj;
95
118
  if (this.toDB) {
96
119
  obj2 = this.toDB(obj);
97
120
  }
98
121
  var stmt = build_1.buildToInsert(obj2, this.table, this.attributes, this.param, this.version);
99
122
  if (stmt) {
100
- return this.exec(stmt.query, stmt.params).catch(function (err) {
123
+ return this.exec(stmt.query, stmt.params, ctx).catch(function (err) {
101
124
  if (err && err.error === 'duplicate') {
102
125
  return 0;
103
126
  }
@@ -110,26 +133,26 @@ var SqlWriter = (function (_super) {
110
133
  return Promise.resolve(0);
111
134
  }
112
135
  };
113
- SqlWriter.prototype.update = function (obj) {
136
+ SqlWriter.prototype.update = function (obj, ctx) {
114
137
  var obj2 = obj;
115
138
  if (this.toDB) {
116
139
  obj2 = this.toDB(obj);
117
140
  }
118
141
  var stmt = build_1.buildToUpdate(obj2, this.table, this.attributes, this.param, this.version);
119
142
  if (stmt) {
120
- return this.exec(stmt.query, stmt.params);
143
+ return this.exec(stmt.query, stmt.params, ctx);
121
144
  }
122
145
  else {
123
146
  return Promise.resolve(0);
124
147
  }
125
148
  };
126
- SqlWriter.prototype.patch = function (obj) {
127
- return this.update(obj);
149
+ SqlWriter.prototype.patch = function (obj, ctx) {
150
+ return this.update(obj, ctx);
128
151
  };
129
- SqlWriter.prototype.delete = function (id) {
130
- var stmt = build_1.buildToDelete(id, this.table, this.keys, this.param);
152
+ SqlWriter.prototype.delete = function (id, ctx) {
153
+ var stmt = build_1.buildToDelete(id, this.table, this.primaryKeys, this.param);
131
154
  if (stmt) {
132
- return this.exec(stmt.query, stmt.params);
155
+ return this.exec(stmt.query, stmt.params, ctx);
133
156
  }
134
157
  else {
135
158
  return Promise.resolve(0);
@@ -138,3 +161,22 @@ var SqlWriter = (function (_super) {
138
161
  return SqlWriter;
139
162
  }(SqlLoader));
140
163
  exports.SqlWriter = SqlWriter;
164
+ var SqlSearchWriter = (function (_super) {
165
+ __extends(SqlSearchWriter, _super);
166
+ function SqlSearchWriter(find, table, query, exec, attrs, buildParam, toDB, fromDB, execBatch) {
167
+ var _this = _super.call(this, table, query, exec, attrs, buildParam, toDB, fromDB, execBatch) || this;
168
+ _this.find = find;
169
+ _this.search = _this.search.bind(_this);
170
+ return _this;
171
+ }
172
+ SqlSearchWriter.prototype.search = function (s, limit, offset, fields) {
173
+ return this.find(s, limit, offset, fields);
174
+ };
175
+ return SqlSearchWriter;
176
+ }(SqlWriter));
177
+ exports.SqlSearchWriter = SqlSearchWriter;
178
+ function createSqlSearchWriter(find, table, manager, attrs, buildParam, toDB, fromDB) {
179
+ var writer = new SqlSearchWriter(find, table, manager.query, manager.exec, attrs, buildParam, toDB, fromDB, manager.execBatch);
180
+ return writer;
181
+ }
182
+ exports.createSqlSearchWriter = createSqlSearchWriter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "query-core",
3
- "version": "0.1.5",
3
+ "version": "0.1.9",
4
4
  "description": "query",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",