query-core 0.1.26 → 0.1.28
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/batch.js +33 -9
- package/package.json +1 -1
- package/src/batch.ts +26 -10
package/lib/batch.js
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var build_1 = require("./build");
|
|
4
4
|
var SqlInserter = (function () {
|
|
5
|
-
function SqlInserter(exec, table, attributes, param, map) {
|
|
5
|
+
function SqlInserter(exec, table, attributes, param, oneIfSuccess, map) {
|
|
6
6
|
this.exec = exec;
|
|
7
7
|
this.table = table;
|
|
8
8
|
this.attributes = attributes;
|
|
9
9
|
this.param = param;
|
|
10
|
+
this.oneIfSuccess = oneIfSuccess;
|
|
10
11
|
this.map = map;
|
|
11
12
|
this.write = this.write.bind(this);
|
|
12
13
|
var x = build_1.version(attributes);
|
|
@@ -24,7 +25,12 @@ var SqlInserter = (function () {
|
|
|
24
25
|
}
|
|
25
26
|
var stmt = build_1.buildToInsert(obj2, this.table, this.attributes, this.param, this.version);
|
|
26
27
|
if (stmt) {
|
|
27
|
-
|
|
28
|
+
if (this.oneIfSuccess) {
|
|
29
|
+
return this.exec(stmt.query, stmt.params).then(function (ct) { return ct > 0 ? 1 : 0; });
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return this.exec(stmt.query, stmt.params);
|
|
33
|
+
}
|
|
28
34
|
}
|
|
29
35
|
else {
|
|
30
36
|
return Promise.resolve(0);
|
|
@@ -34,11 +40,12 @@ var SqlInserter = (function () {
|
|
|
34
40
|
}());
|
|
35
41
|
exports.SqlInserter = SqlInserter;
|
|
36
42
|
var SqlUpdater = (function () {
|
|
37
|
-
function SqlUpdater(exec, table, attributes, param, map) {
|
|
43
|
+
function SqlUpdater(exec, table, attributes, param, oneIfSuccess, map) {
|
|
38
44
|
this.exec = exec;
|
|
39
45
|
this.table = table;
|
|
40
46
|
this.attributes = attributes;
|
|
41
47
|
this.param = param;
|
|
48
|
+
this.oneIfSuccess = oneIfSuccess;
|
|
42
49
|
this.map = map;
|
|
43
50
|
this.write = this.write.bind(this);
|
|
44
51
|
var x = build_1.version(attributes);
|
|
@@ -56,7 +63,12 @@ var SqlUpdater = (function () {
|
|
|
56
63
|
}
|
|
57
64
|
var stmt = build_1.buildToUpdate(obj2, this.table, this.attributes, this.param, this.version);
|
|
58
65
|
if (stmt) {
|
|
59
|
-
|
|
66
|
+
if (this.oneIfSuccess) {
|
|
67
|
+
return this.exec(stmt.query, stmt.params).then(function (ct) { return ct > 0 ? 1 : 0; });
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
return this.exec(stmt.query, stmt.params);
|
|
71
|
+
}
|
|
60
72
|
}
|
|
61
73
|
else {
|
|
62
74
|
return Promise.resolve(0);
|
|
@@ -66,11 +78,12 @@ var SqlUpdater = (function () {
|
|
|
66
78
|
}());
|
|
67
79
|
exports.SqlUpdater = SqlUpdater;
|
|
68
80
|
var SqlBatchInserter = (function () {
|
|
69
|
-
function SqlBatchInserter(exec, table, attributes, param, map) {
|
|
81
|
+
function SqlBatchInserter(exec, table, attributes, param, oneIfSuccess, map) {
|
|
70
82
|
this.exec = exec;
|
|
71
83
|
this.table = table;
|
|
72
84
|
this.attributes = attributes;
|
|
73
85
|
this.param = param;
|
|
86
|
+
this.oneIfSuccess = oneIfSuccess;
|
|
74
87
|
this.map = map;
|
|
75
88
|
this.write = this.write.bind(this);
|
|
76
89
|
var x = build_1.version(attributes);
|
|
@@ -93,7 +106,12 @@ var SqlBatchInserter = (function () {
|
|
|
93
106
|
}
|
|
94
107
|
var stmt = build_1.buildToInsertBatch(list, this.table, this.attributes, this.param, this.version);
|
|
95
108
|
if (stmt) {
|
|
96
|
-
|
|
109
|
+
if (this.oneIfSuccess) {
|
|
110
|
+
return this.exec(stmt.query, stmt.params).then(function (ct) { return objs.length; });
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
return this.exec(stmt.query, stmt.params);
|
|
114
|
+
}
|
|
97
115
|
}
|
|
98
116
|
else {
|
|
99
117
|
return Promise.resolve(0);
|
|
@@ -103,11 +121,12 @@ var SqlBatchInserter = (function () {
|
|
|
103
121
|
}());
|
|
104
122
|
exports.SqlBatchInserter = SqlBatchInserter;
|
|
105
123
|
var SqlBatchUpdater = (function () {
|
|
106
|
-
function SqlBatchUpdater(execBatch, table, attributes, param, notSkipInvalid, map) {
|
|
124
|
+
function SqlBatchUpdater(execBatch, table, attributes, param, oneIfSuccess, notSkipInvalid, map) {
|
|
107
125
|
this.execBatch = execBatch;
|
|
108
126
|
this.table = table;
|
|
109
127
|
this.attributes = attributes;
|
|
110
128
|
this.param = param;
|
|
129
|
+
this.oneIfSuccess = oneIfSuccess;
|
|
111
130
|
this.notSkipInvalid = notSkipInvalid;
|
|
112
131
|
this.map = map;
|
|
113
132
|
this.write = this.write.bind(this);
|
|
@@ -131,7 +150,12 @@ var SqlBatchUpdater = (function () {
|
|
|
131
150
|
}
|
|
132
151
|
var stmts = build_1.buildToUpdateBatch(list, this.table, this.attributes, this.param, this.notSkipInvalid);
|
|
133
152
|
if (stmts && stmts.length > 0) {
|
|
134
|
-
|
|
153
|
+
if (this.oneIfSuccess) {
|
|
154
|
+
return this.execBatch(stmts).then(function (ct) { return stmts.length; });
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
return this.execBatch(stmts);
|
|
158
|
+
}
|
|
135
159
|
}
|
|
136
160
|
else {
|
|
137
161
|
return Promise.resolve(0);
|
|
@@ -190,7 +214,7 @@ var StreamInserter = (function () {
|
|
|
190
214
|
return this.exec(stmt.query, stmt.params).then(function (r) {
|
|
191
215
|
_this.list = [];
|
|
192
216
|
return total_1;
|
|
193
|
-
});
|
|
217
|
+
}); F
|
|
194
218
|
}
|
|
195
219
|
else {
|
|
196
220
|
return Promise.resolve(0);
|
package/package.json
CHANGED
package/src/batch.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Attributes, Statement } from './metadata';
|
|
|
3
3
|
|
|
4
4
|
export class SqlInserter<T> {
|
|
5
5
|
version?: string;
|
|
6
|
-
constructor(public exec: (sql: string, args?: any[]) => Promise<number>, public table: string, public attributes: Attributes, public param: (i: number) => string, public map?: (v: T) => T) {
|
|
6
|
+
constructor(public exec: (sql: string, args?: any[]) => Promise<number>, public table: string, public attributes: Attributes, public param: (i: number) => string, public oneIfSuccess?: boolean, public map?: (v: T) => T) {
|
|
7
7
|
this.write = this.write.bind(this);
|
|
8
8
|
const x = version(attributes);
|
|
9
9
|
if (x) {
|
|
@@ -20,7 +20,11 @@ export class SqlInserter<T> {
|
|
|
20
20
|
}
|
|
21
21
|
const stmt = buildToInsert(obj2, this.table, this.attributes, this.param, this.version);
|
|
22
22
|
if (stmt) {
|
|
23
|
-
|
|
23
|
+
if (this.oneIfSuccess) {
|
|
24
|
+
return this.exec(stmt.query, stmt.params).then(ct => ct > 0 ? 1 : 0);
|
|
25
|
+
} else {
|
|
26
|
+
return this.exec(stmt.query, stmt.params);
|
|
27
|
+
}
|
|
24
28
|
} else {
|
|
25
29
|
return Promise.resolve(0);
|
|
26
30
|
}
|
|
@@ -29,7 +33,7 @@ export class SqlInserter<T> {
|
|
|
29
33
|
// tslint:disable-next-line:max-classes-per-file
|
|
30
34
|
export class SqlUpdater<T> {
|
|
31
35
|
version?: string;
|
|
32
|
-
constructor(public exec: (sql: string, args?: any[]) => Promise<number>, public table: string, public attributes: Attributes, public param: (i: number) => string, public map?: (v: T) => T) {
|
|
36
|
+
constructor(public exec: (sql: string, args?: any[]) => Promise<number>, public table: string, public attributes: Attributes, public param: (i: number) => string, public oneIfSuccess?: boolean, public map?: (v: T) => T) {
|
|
33
37
|
this.write = this.write.bind(this);
|
|
34
38
|
const x = version(attributes);
|
|
35
39
|
if (x) {
|
|
@@ -46,7 +50,11 @@ export class SqlUpdater<T> {
|
|
|
46
50
|
}
|
|
47
51
|
const stmt = buildToUpdate(obj2, this.table, this.attributes, this.param, this.version);
|
|
48
52
|
if (stmt) {
|
|
49
|
-
|
|
53
|
+
if (this.oneIfSuccess) {
|
|
54
|
+
return this.exec(stmt.query, stmt.params).then(ct => ct > 0 ? 1 : 0);
|
|
55
|
+
} else {
|
|
56
|
+
return this.exec(stmt.query, stmt.params);
|
|
57
|
+
}
|
|
50
58
|
} else {
|
|
51
59
|
return Promise.resolve(0);
|
|
52
60
|
}
|
|
@@ -55,7 +63,7 @@ export class SqlUpdater<T> {
|
|
|
55
63
|
// tslint:disable-next-line:max-classes-per-file
|
|
56
64
|
export class SqlBatchInserter<T> {
|
|
57
65
|
version?: string;
|
|
58
|
-
constructor(public exec: (sql: string, args?: any[]) => Promise<number>, public table: string, public attributes: Attributes, public param: ((i: number) => string) | boolean, public map?: (v: T) => T) {
|
|
66
|
+
constructor(public exec: (sql: string, args?: any[]) => Promise<number>, public table: string, public attributes: Attributes, public param: ((i: number) => string) | boolean, public oneIfSuccess?: boolean, public map?: (v: T) => T) {
|
|
59
67
|
this.write = this.write.bind(this);
|
|
60
68
|
const x = version(attributes);
|
|
61
69
|
if (x) {
|
|
@@ -76,7 +84,11 @@ export class SqlBatchInserter<T> {
|
|
|
76
84
|
}
|
|
77
85
|
const stmt = buildToInsertBatch(list, this.table, this.attributes, this.param, this.version);
|
|
78
86
|
if (stmt) {
|
|
79
|
-
|
|
87
|
+
if (this.oneIfSuccess) {
|
|
88
|
+
return this.exec(stmt.query, stmt.params).then(ct => objs.length);
|
|
89
|
+
} else {
|
|
90
|
+
return this.exec(stmt.query, stmt.params);
|
|
91
|
+
}
|
|
80
92
|
} else {
|
|
81
93
|
return Promise.resolve(0);
|
|
82
94
|
}
|
|
@@ -85,7 +97,7 @@ export class SqlBatchInserter<T> {
|
|
|
85
97
|
// tslint:disable-next-line:max-classes-per-file
|
|
86
98
|
export class SqlBatchUpdater<T> {
|
|
87
99
|
version?: string;
|
|
88
|
-
constructor(public execBatch: (statements: Statement[]) => Promise<number>, public table: string, public attributes: Attributes, public param: (i: number) => string, protected notSkipInvalid?: boolean, public map?: (v: T) => T) {
|
|
100
|
+
constructor(public execBatch: (statements: Statement[]) => Promise<number>, public table: string, public attributes: Attributes, public param: (i: number) => string, public oneIfSuccess?: boolean, protected notSkipInvalid?: boolean, public map?: (v: T) => T) {
|
|
89
101
|
this.write = this.write.bind(this);
|
|
90
102
|
const x = version(attributes);
|
|
91
103
|
if (x) {
|
|
@@ -106,7 +118,11 @@ export class SqlBatchUpdater<T> {
|
|
|
106
118
|
}
|
|
107
119
|
const stmts = buildToUpdateBatch(list, this.table, this.attributes, this.param, this.notSkipInvalid);
|
|
108
120
|
if (stmts && stmts.length > 0) {
|
|
109
|
-
|
|
121
|
+
if (this.oneIfSuccess) {
|
|
122
|
+
return this.execBatch(stmts).then(ct => stmts.length);
|
|
123
|
+
} else {
|
|
124
|
+
return this.execBatch(stmts);
|
|
125
|
+
}
|
|
110
126
|
} else {
|
|
111
127
|
return Promise.resolve(0);
|
|
112
128
|
}
|
|
@@ -115,7 +131,7 @@ export class SqlBatchUpdater<T> {
|
|
|
115
131
|
// tslint:disable-next-line:max-classes-per-file
|
|
116
132
|
export class StreamInserter<T> {
|
|
117
133
|
list: T[] = [];
|
|
118
|
-
size
|
|
134
|
+
size = 0;
|
|
119
135
|
version?: string;
|
|
120
136
|
map?: (v: T) => T;
|
|
121
137
|
constructor(public exec: ((sql: string, args?: any[]) => Promise<number>), public table: string, public attributes: Attributes, public param: (i: number) => string, size?: number, toDB?: (v: T) => T) {
|
|
@@ -167,7 +183,7 @@ export class StreamInserter<T> {
|
|
|
167
183
|
// tslint:disable-next-line:max-classes-per-file
|
|
168
184
|
export class StreamUpdater<T> {
|
|
169
185
|
list: T[] = [];
|
|
170
|
-
size
|
|
186
|
+
size = 0;
|
|
171
187
|
version?: string;
|
|
172
188
|
map?: (v: T) => T;
|
|
173
189
|
constructor(public execBatch: ((statements: Statement[]) => Promise<number>), public table: string, public attributes: Attributes, public param: (i: number) => string, size?: number, toDB?: (v: T) => T) {
|