@riao/dbal 3.8.0 → 3.9.0
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/CHANGELOG.md +3 -3
- package/LICENSE.md +20 -20
- package/README.md +148 -148
- package/builder/builder.d.ts +7 -7
- package/builder/builder.js +19 -19
- package/builder/index.d.ts +2 -2
- package/builder/index.js +7 -7
- package/builder/sql-builder.d.ts +54 -53
- package/builder/sql-builder.js +161 -157
- package/builder/sql-builder.js.map +1 -1
- package/builder/statement-builder.d.ts +12 -12
- package/builder/statement-builder.js +32 -32
- package/column/column-options.d.ts +156 -156
- package/column/column-options.js +2 -2
- package/column/column-type.d.ts +18 -18
- package/column/column-type.js +27 -27
- package/column/column-values.d.ts +34 -34
- package/column/column-values.js +2 -2
- package/column/create-column-template.d.ts +11 -0
- package/column/create-column-template.js +57 -0
- package/column/create-column-template.js.map +1 -0
- package/column/index.d.ts +4 -3
- package/column/index.js +20 -19
- package/column/index.js.map +1 -1
- package/column-pack/date-time/create-timestamp-column.d.ts +2 -2
- package/column-pack/date-time/create-timestamp-column.js +10 -10
- package/column-pack/date-time/index.d.ts +2 -2
- package/column-pack/date-time/index.js +7 -7
- package/column-pack/date-time/update-timestamp-column.d.ts +2 -2
- package/column-pack/date-time/update-timestamp-column.js +14 -14
- package/column-pack/index.d.ts +6 -6
- package/column-pack/index.js +22 -22
- package/column-pack/keys/big-int-key-column.d.ts +2 -2
- package/column-pack/keys/big-int-key-column.js +10 -10
- package/column-pack/keys/index.d.ts +3 -3
- package/column-pack/keys/index.js +9 -9
- package/column-pack/keys/int-key-column.d.ts +2 -2
- package/column-pack/keys/int-key-column.js +10 -10
- package/column-pack/keys/uuid-key-column.d.ts +2 -2
- package/column-pack/keys/uuid-key-column.js +11 -11
- package/column-pack/person/date-of-birth-column.d.ts +2 -2
- package/column-pack/person/date-of-birth-column.js +8 -8
- package/column-pack/person/first-name-column.d.ts +2 -2
- package/column-pack/person/first-name-column.js +9 -9
- package/column-pack/person/index.d.ts +3 -3
- package/column-pack/person/index.js +9 -9
- package/column-pack/person/last-name-column.d.ts +2 -2
- package/column-pack/person/last-name-column.js +9 -9
- package/column-pack/resource/content-column.d.ts +2 -2
- package/column-pack/resource/content-column.js +9 -9
- package/column-pack/resource/description-column.d.ts +2 -2
- package/column-pack/resource/description-column.js +9 -9
- package/column-pack/resource/index.d.ts +6 -6
- package/column-pack/resource/index.js +15 -15
- package/column-pack/resource/is-active-column.d.ts +2 -2
- package/column-pack/resource/is-active-column.js +9 -9
- package/column-pack/resource/name-column.d.ts +2 -2
- package/column-pack/resource/name-column.js +10 -10
- package/column-pack/resource/path-column.d.ts +2 -2
- package/column-pack/resource/path-column.js +11 -11
- package/column-pack/resource/title-column.d.ts +2 -2
- package/column-pack/resource/title-column.js +10 -10
- package/column-pack/system/filename-column.d.ts +2 -2
- package/column-pack/system/filename-column.js +9 -9
- package/column-pack/system/filepath-column.d.ts +2 -2
- package/column-pack/system/filepath-column.js +9 -9
- package/column-pack/system/index.d.ts +4 -4
- package/column-pack/system/index.js +11 -11
- package/column-pack/system/ip-address-column.d.ts +2 -2
- package/column-pack/system/ip-address-column.js +9 -9
- package/column-pack/system/url-column.d.ts +3 -3
- package/column-pack/system/url-column.js +13 -13
- package/column-pack/user/email-column.d.ts +2 -2
- package/column-pack/user/email-column.js +11 -11
- package/column-pack/user/index.d.ts +4 -4
- package/column-pack/user/index.js +11 -11
- package/column-pack/user/password-column.d.ts +2 -2
- package/column-pack/user/password-column.js +10 -10
- package/column-pack/user/temp-email-column.d.ts +2 -2
- package/column-pack/user/temp-email-column.js +5 -5
- package/column-pack/user/username-column.d.ts +2 -2
- package/column-pack/user/username-column.js +11 -11
- package/comparison/comparison-aliases.d.ts +10 -10
- package/comparison/comparison-aliases.js +40 -40
- package/comparison/comparison-token.d.ts +17 -17
- package/comparison/comparison-token.js +15 -15
- package/comparison/comparison.d.ts +13 -13
- package/comparison/comparison.js +71 -71
- package/comparison/index.d.ts +4 -4
- package/comparison/index.js +24 -24
- package/comparison/is-comparison-token.d.ts +2 -2
- package/comparison/is-comparison-token.js +8 -8
- package/config/configure-db.d.ts +14 -14
- package/config/configure-db.js +18 -18
- package/config/database-env.d.ts +16 -16
- package/config/database-env.js +14 -14
- package/config/index.d.ts +2 -2
- package/config/index.js +7 -7
- package/database/connection-options.d.ts +7 -7
- package/database/connection-options.js +2 -2
- package/database/database.d.ts +204 -204
- package/database/database.js +330 -330
- package/database/driver-query.d.ts +10 -10
- package/database/driver-query.js +2 -2
- package/database/driver.d.ts +12 -12
- package/database/driver.js +47 -47
- package/database/get-database-path.d.ts +6 -6
- package/database/get-database-path.js +12 -12
- package/database/index.d.ts +7 -7
- package/database/index.js +26 -26
- package/database/load-database.d.ts +9 -9
- package/database/load-database.js +36 -36
- package/database/transaction.d.ts +8 -8
- package/database/transaction.js +2 -2
- package/ddl/alter-table.d.ts +26 -26
- package/ddl/alter-table.js +2 -2
- package/ddl/create-database.d.ts +3 -3
- package/ddl/create-database.js +2 -2
- package/ddl/create-index.d.ts +5 -5
- package/ddl/create-index.js +2 -2
- package/ddl/create-table.d.ts +8 -8
- package/ddl/create-table.js +2 -2
- package/ddl/create-user.d.ts +4 -4
- package/ddl/create-user.js +2 -2
- package/ddl/ddl-builder.d.ts +96 -96
- package/ddl/ddl-builder.js +565 -565
- package/ddl/ddl-repository.d.ts +135 -135
- package/ddl/ddl-repository.js +228 -228
- package/ddl/drop-database.d.ts +4 -4
- package/ddl/drop-database.js +2 -2
- package/ddl/drop-table.d.ts +4 -4
- package/ddl/drop-table.js +2 -2
- package/ddl/drop-user.d.ts +4 -4
- package/ddl/drop-user.js +2 -2
- package/ddl/foreign-key-constraint.d.ts +19 -19
- package/ddl/foreign-key-constraint.js +2 -2
- package/ddl/grant.d.ts +12 -12
- package/ddl/grant.js +2 -2
- package/ddl/index.d.ts +13 -13
- package/ddl/index.js +23 -23
- package/ddl/truncate.d.ts +3 -3
- package/ddl/truncate.js +2 -2
- package/dml/case-expression.d.ts +16 -16
- package/dml/case-expression.js +11 -11
- package/dml/delete.d.ts +8 -8
- package/dml/delete.js +2 -2
- package/dml/from.d.ts +4 -4
- package/dml/from.js +2 -2
- package/dml/group-by.d.ts +4 -4
- package/dml/group-by.js +2 -2
- package/dml/index.d.ts +11 -11
- package/dml/index.js +30 -30
- package/dml/insert.d.ts +14 -14
- package/dml/insert.js +2 -2
- package/dml/join.d.ts +7 -7
- package/dml/join.js +2 -2
- package/dml/order-by.d.ts +2 -2
- package/dml/order-by.js +2 -2
- package/dml/query-builder.d.ts +125 -106
- package/dml/query-builder.js +991 -793
- package/dml/query-builder.js.map +1 -1
- package/dml/query-repository.d.ts +84 -84
- package/dml/query-repository.js +239 -225
- package/dml/query-repository.js.map +1 -1
- package/dml/select.d.ts +44 -29
- package/dml/select.js +2 -2
- package/dml/set-options.d.ts +5 -5
- package/dml/set-options.js +2 -2
- package/dml/subquery.d.ts +5 -5
- package/dml/subquery.js +10 -10
- package/dml/update.d.ts +11 -11
- package/dml/update.js +2 -2
- package/expression/expression-token.d.ts +11 -11
- package/expression/expression-token.js +12 -12
- package/expression/expression.d.ts +6 -6
- package/expression/expression.js +2 -2
- package/expression/identifier.d.ts +7 -7
- package/expression/identifier.js +15 -15
- package/expression/index.d.ts +7 -7
- package/expression/index.js +25 -25
- package/expression/is-expression-token.d.ts +2 -2
- package/expression/is-expression-token.js +7 -7
- package/expression/key-val-expression.d.ts +7 -7
- package/expression/key-val-expression.js +2 -2
- package/expression/literal.d.ts +3 -3
- package/expression/literal.js +2 -2
- package/expression/logical.d.ts +28 -18
- package/expression/logical.js +54 -30
- package/expression/logical.js.map +1 -1
- package/expression/math.d.ts +17 -17
- package/expression/math.js +36 -36
- package/expression/raw.d.ts +8 -8
- package/expression/raw.js +16 -16
- package/expression/simple-expression.d.ts +8 -8
- package/expression/simple-expression.js +2 -2
- package/functions/function-aliases.d.ts +6 -4
- package/functions/function-aliases.js +16 -12
- package/functions/function-aliases.js.map +1 -1
- package/functions/function-token.d.ts +33 -29
- package/functions/function-token.js +19 -15
- package/functions/function-token.js.map +1 -1
- package/functions/functions.d.ts +23 -19
- package/functions/functions.js +126 -94
- package/functions/functions.js.map +1 -1
- package/functions/index.d.ts +4 -4
- package/functions/index.js +22 -22
- package/functions/is-database-function.d.ts +8 -8
- package/functions/is-database-function.js +14 -14
- package/functions/signatures/count.d.ts +14 -11
- package/functions/signatures/count.js +2 -2
- package/index.d.ts +16 -16
- package/index.js +32 -32
- package/migration/index.d.ts +3 -3
- package/migration/index.js +9 -9
- package/migration/migration-package.d.ts +14 -14
- package/migration/migration-package.js +10 -10
- package/migration/migration-record.d.ts +10 -10
- package/migration/migration-record.js +2 -2
- package/migration/migration-runner.d.ts +33 -33
- package/migration/migration-runner.js +180 -180
- package/migration/migration.d.ts +12 -12
- package/migration/migration.js +27 -27
- package/migration/migrations/001-create-migration-table.d.ts +8 -8
- package/migration/migrations/001-create-migration-table.js +54 -54
- package/migration/migrations/002-add-migration-package-column.d.ts +9 -9
- package/migration/migrations/002-add-migration-package-column.js +44 -44
- package/package.json +1 -1
- package/record/index.d.ts +1 -1
- package/record/index.js +17 -17
- package/record/record.d.ts +2 -2
- package/record/record.js +2 -2
- package/repository/index.d.ts +2 -2
- package/repository/index.js +5 -5
- package/repository/repository-options.d.ts +6 -6
- package/repository/repository-options.js +2 -2
- package/repository/repository.d.ts +29 -29
- package/repository/repository.js +68 -68
- package/schema/index.d.ts +3 -3
- package/schema/index.js +5 -5
- package/schema/schema-query-repository.d.ts +54 -54
- package/schema/schema-query-repository.js +159 -159
- package/schema/schema-table.d.ts +9 -9
- package/schema/schema-table.js +2 -2
- package/schema/schema.d.ts +4 -4
- package/schema/schema.js +2 -2
- package/seed/auto-seed.d.ts +9 -9
- package/seed/auto-seed.js +61 -61
- package/seed/create-seed-table.d.ts +8 -8
- package/seed/create-seed-table.js +64 -64
- package/seed/index.d.ts +4 -4
- package/seed/index.js +9 -9
- package/seed/seed-record.d.ts +11 -11
- package/seed/seed-record.js +2 -2
- package/seed/seed-runner.d.ts +20 -20
- package/seed/seed-runner.js +91 -91
- package/seed/seed.d.ts +12 -12
- package/seed/seed.js +27 -27
- package/tokens/index.d.ts +1 -1
- package/tokens/index.js +5 -5
- package/triggers/index.d.ts +2 -2
- package/triggers/index.js +18 -18
- package/triggers/prebuilt/index.d.ts +1 -1
- package/triggers/prebuilt/index.js +5 -5
- package/triggers/prebuilt/update-timestamp-trigger.d.ts +16 -16
- package/triggers/prebuilt/update-timestamp-trigger.js +24 -24
- package/triggers/trigger-options.d.ts +22 -22
- package/triggers/trigger-options.js +2 -2
- package/triggers/trigger.d.ts +19 -19
- package/triggers/trigger.js +23 -23
package/dml/query-repository.js
CHANGED
|
@@ -1,226 +1,240 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.QueryRepository = void 0;
|
|
13
|
-
const repository_1 = require("../repository");
|
|
14
|
-
const functions_1 = require("../functions");
|
|
15
|
-
/**
|
|
16
|
-
* Use the Query Repository to query a database
|
|
17
|
-
*/
|
|
18
|
-
class QueryRepository extends repository_1.Repository {
|
|
19
|
-
constructor(options) {
|
|
20
|
-
var _a, _b, _c;
|
|
21
|
-
super(options);
|
|
22
|
-
this.table = (_a = options.table) !== null && _a !== void 0 ? _a : this.table;
|
|
23
|
-
this.identifiedBy = (_b = options.identifiedBy) !== null && _b !== void 0 ? _b : this.identifiedBy;
|
|
24
|
-
this.queryBuilderType =
|
|
25
|
-
(_c = options.queryBuilderType) !== null && _c !== void 0 ? _c : this.queryBuilderType;
|
|
26
|
-
}
|
|
27
|
-
init(options) {
|
|
28
|
-
super.init(options);
|
|
29
|
-
this.schema = options.schema;
|
|
30
|
-
this.getIdentifier();
|
|
31
|
-
this.isReady = true;
|
|
32
|
-
}
|
|
33
|
-
getTableName() {
|
|
34
|
-
var _a;
|
|
35
|
-
return (_a = this.table) !== null && _a !== void 0 ? _a : null;
|
|
36
|
-
}
|
|
37
|
-
getIdentifier() {
|
|
38
|
-
var _a;
|
|
39
|
-
if (!this.identifiedBy &&
|
|
40
|
-
this.table &&
|
|
41
|
-
this.schema &&
|
|
42
|
-
this.table in this.schema.tables) {
|
|
43
|
-
this.identifiedBy = this.schema.tables[this.table].primaryKey;
|
|
44
|
-
}
|
|
45
|
-
return (_a = this.identifiedBy) !== null && _a !== void 0 ? _a : null;
|
|
46
|
-
}
|
|
47
|
-
getQueryBuilder() {
|
|
48
|
-
return new this.queryBuilderType();
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Finds entities matching given criteria
|
|
52
|
-
*
|
|
53
|
-
* @param selectQuery Select query
|
|
54
|
-
* @returns Found entities
|
|
55
|
-
*/
|
|
56
|
-
find(selectQuery) {
|
|
57
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
selectQuery.table = selectQuery.table || this.table;
|
|
59
|
-
const query = this.getQueryBuilder()
|
|
60
|
-
.select(selectQuery)
|
|
61
|
-
.toDatabaseQuery();
|
|
62
|
-
const { results } = yield this.query(query);
|
|
63
|
-
return (results !== null && results !== void 0 ? results : []);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Finds one entity matching given criteria
|
|
68
|
-
*
|
|
69
|
-
* @param selectQuery Select query
|
|
70
|
-
* @returns Found entity or `null`
|
|
71
|
-
*/
|
|
72
|
-
findOne(selectQuery) {
|
|
73
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
selectQuery.table = selectQuery.table || this.table;
|
|
75
|
-
const query = this.getQueryBuilder()
|
|
76
|
-
.select(Object.assign(Object.assign({}, selectQuery), { limit: 1 }))
|
|
77
|
-
.toDatabaseQuery();
|
|
78
|
-
const { results } = yield this.query(query);
|
|
79
|
-
if (!(results === null || results === void 0 ? void 0 : results.length)) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
return results[0];
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
findById(id) {
|
|
86
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
// Ready-check before throwing a PK error
|
|
88
|
-
this.readyCheck();
|
|
89
|
-
if (!this.getIdentifier()) {
|
|
90
|
-
throw new Error('findById() Could not determine PK for table "' +
|
|
91
|
-
this.table +
|
|
92
|
-
'"');
|
|
93
|
-
}
|
|
94
|
-
return yield this.findOne({
|
|
95
|
-
where: { [this.identifiedBy]: id },
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Finds one entity matching given criteria, or throws error
|
|
101
|
-
*
|
|
102
|
-
* @param selectQuery Select query
|
|
103
|
-
* @param error Error to throw
|
|
104
|
-
* @returns Found entity
|
|
105
|
-
*/
|
|
106
|
-
findOneOrFail(selectQuery, error) {
|
|
107
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
-
selectQuery.table = selectQuery.table || this.table;
|
|
109
|
-
const result = yield this.findOne(selectQuery);
|
|
110
|
-
if (result === null) {
|
|
111
|
-
throw error !== null && error !== void 0 ? error : new Error('Result not found!');
|
|
112
|
-
}
|
|
113
|
-
return result;
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
count(selectQuery = {}, params) {
|
|
117
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const
|
|
171
|
-
if (
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.QueryRepository = void 0;
|
|
13
|
+
const repository_1 = require("../repository");
|
|
14
|
+
const functions_1 = require("../functions");
|
|
15
|
+
/**
|
|
16
|
+
* Use the Query Repository to query a database
|
|
17
|
+
*/
|
|
18
|
+
class QueryRepository extends repository_1.Repository {
|
|
19
|
+
constructor(options) {
|
|
20
|
+
var _a, _b, _c;
|
|
21
|
+
super(options);
|
|
22
|
+
this.table = (_a = options.table) !== null && _a !== void 0 ? _a : this.table;
|
|
23
|
+
this.identifiedBy = (_b = options.identifiedBy) !== null && _b !== void 0 ? _b : this.identifiedBy;
|
|
24
|
+
this.queryBuilderType =
|
|
25
|
+
(_c = options.queryBuilderType) !== null && _c !== void 0 ? _c : this.queryBuilderType;
|
|
26
|
+
}
|
|
27
|
+
init(options) {
|
|
28
|
+
super.init(options);
|
|
29
|
+
this.schema = options.schema;
|
|
30
|
+
this.getIdentifier();
|
|
31
|
+
this.isReady = true;
|
|
32
|
+
}
|
|
33
|
+
getTableName() {
|
|
34
|
+
var _a;
|
|
35
|
+
return (_a = this.table) !== null && _a !== void 0 ? _a : null;
|
|
36
|
+
}
|
|
37
|
+
getIdentifier() {
|
|
38
|
+
var _a;
|
|
39
|
+
if (!this.identifiedBy &&
|
|
40
|
+
this.table &&
|
|
41
|
+
this.schema &&
|
|
42
|
+
this.table in this.schema.tables) {
|
|
43
|
+
this.identifiedBy = this.schema.tables[this.table].primaryKey;
|
|
44
|
+
}
|
|
45
|
+
return (_a = this.identifiedBy) !== null && _a !== void 0 ? _a : null;
|
|
46
|
+
}
|
|
47
|
+
getQueryBuilder() {
|
|
48
|
+
return new this.queryBuilderType();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Finds entities matching given criteria
|
|
52
|
+
*
|
|
53
|
+
* @param selectQuery Select query
|
|
54
|
+
* @returns Found entities
|
|
55
|
+
*/
|
|
56
|
+
find(selectQuery) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
selectQuery.table = selectQuery.table || this.table;
|
|
59
|
+
const query = this.getQueryBuilder()
|
|
60
|
+
.select(selectQuery)
|
|
61
|
+
.toDatabaseQuery();
|
|
62
|
+
const { results } = yield this.query(query);
|
|
63
|
+
return (results !== null && results !== void 0 ? results : []);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Finds one entity matching given criteria
|
|
68
|
+
*
|
|
69
|
+
* @param selectQuery Select query
|
|
70
|
+
* @returns Found entity or `null`
|
|
71
|
+
*/
|
|
72
|
+
findOne(selectQuery) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
selectQuery.table = selectQuery.table || this.table;
|
|
75
|
+
const query = this.getQueryBuilder()
|
|
76
|
+
.select(Object.assign(Object.assign({}, selectQuery), { limit: 1 }))
|
|
77
|
+
.toDatabaseQuery();
|
|
78
|
+
const { results } = yield this.query(query);
|
|
79
|
+
if (!(results === null || results === void 0 ? void 0 : results.length)) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
return results[0];
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
findById(id) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
// Ready-check before throwing a PK error
|
|
88
|
+
this.readyCheck();
|
|
89
|
+
if (!this.getIdentifier()) {
|
|
90
|
+
throw new Error('findById() Could not determine PK for table "' +
|
|
91
|
+
this.table +
|
|
92
|
+
'"');
|
|
93
|
+
}
|
|
94
|
+
return yield this.findOne({
|
|
95
|
+
where: { [this.identifiedBy]: id },
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Finds one entity matching given criteria, or throws error
|
|
101
|
+
*
|
|
102
|
+
* @param selectQuery Select query
|
|
103
|
+
* @param error Error to throw
|
|
104
|
+
* @returns Found entity
|
|
105
|
+
*/
|
|
106
|
+
findOneOrFail(selectQuery, error) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
selectQuery.table = selectQuery.table || this.table;
|
|
109
|
+
const result = yield this.findOne(selectQuery);
|
|
110
|
+
if (result === null) {
|
|
111
|
+
throw error !== null && error !== void 0 ? error : new Error('Result not found!');
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
count(selectQuery = {}, params) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
// When groupBy is present, count the distinct combinations
|
|
119
|
+
// of groupBy columns using COUNT(DISTINCT col1, col2, ...)
|
|
120
|
+
if (selectQuery.groupBy && selectQuery.groupBy.length > 0) {
|
|
121
|
+
const { count } = yield this.findOneOrFail(Object.assign(Object.assign({}, selectQuery), { groupBy: undefined, columns: [
|
|
122
|
+
{
|
|
123
|
+
query: functions_1.DatabaseFunctions.count({
|
|
124
|
+
distinct: true,
|
|
125
|
+
columns: selectQuery.groupBy,
|
|
126
|
+
}),
|
|
127
|
+
as: 'count',
|
|
128
|
+
},
|
|
129
|
+
] }));
|
|
130
|
+
return +count;
|
|
131
|
+
}
|
|
132
|
+
const { count } = yield this.findOneOrFail(Object.assign(Object.assign({}, selectQuery), { columns: [
|
|
133
|
+
{
|
|
134
|
+
query: functions_1.DatabaseFunctions.count(params),
|
|
135
|
+
as: 'count',
|
|
136
|
+
},
|
|
137
|
+
] }));
|
|
138
|
+
return +count;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Insert one or multiple items into the database
|
|
143
|
+
*
|
|
144
|
+
* @param insertOptions Insert options
|
|
145
|
+
* @returns Inserted item(s)
|
|
146
|
+
*/
|
|
147
|
+
insert(insertOptions) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
const table = insertOptions.table || this.table;
|
|
150
|
+
if (!table) {
|
|
151
|
+
throw new Error('Cannot insert on query repository without a table.');
|
|
152
|
+
}
|
|
153
|
+
const query = this.getQueryBuilder()
|
|
154
|
+
.insert(Object.assign({ table, primaryKey: undefined }, insertOptions))
|
|
155
|
+
.toDatabaseQuery();
|
|
156
|
+
yield this.query(query);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Insert one item into the database
|
|
161
|
+
*
|
|
162
|
+
* @param insertOptions Insert options
|
|
163
|
+
* @returns Inserted item
|
|
164
|
+
*/
|
|
165
|
+
insertOne(insertOptions) {
|
|
166
|
+
var _a, _b;
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
// Ready-check before throwing a PK error
|
|
169
|
+
this.readyCheck();
|
|
170
|
+
const table = insertOptions.table || this.table;
|
|
171
|
+
if (!table) {
|
|
172
|
+
throw new Error('Query repository cannot insertOne without a table.');
|
|
173
|
+
}
|
|
174
|
+
insertOptions.primaryKey =
|
|
175
|
+
insertOptions.primaryKey ||
|
|
176
|
+
((_b = (_a = this.schema) === null || _a === void 0 ? void 0 : _a.tables[table]) === null || _b === void 0 ? void 0 : _b.primaryKey) ||
|
|
177
|
+
this.identifiedBy;
|
|
178
|
+
if (!insertOptions.primaryKey && !insertOptions.ignoreReturnId) {
|
|
179
|
+
throw new Error('insertOne() cannot determine PK to return. Pass a primaryKey argument or ignoreReturnId: true to suppress this safety. https://github.com/riao-project/riao-dbal/issues/4');
|
|
180
|
+
}
|
|
181
|
+
const query = this.getQueryBuilder()
|
|
182
|
+
.insert(Object.assign(Object.assign({ table }, insertOptions), { records: insertOptions.record }))
|
|
183
|
+
.toDatabaseQuery();
|
|
184
|
+
const { results } = yield this.query(query);
|
|
185
|
+
if (insertOptions.primaryKey && Array.isArray(results)) {
|
|
186
|
+
return results[0];
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
return {};
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Update items in the database
|
|
195
|
+
*
|
|
196
|
+
* @param updateOptions Update options
|
|
197
|
+
*/
|
|
198
|
+
update(updateOptions) {
|
|
199
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
200
|
+
const table = updateOptions.table || this.table;
|
|
201
|
+
if (!table) {
|
|
202
|
+
throw new Error('Query repository cannot update() without a table.');
|
|
203
|
+
}
|
|
204
|
+
const query = this.getQueryBuilder()
|
|
205
|
+
.update(Object.assign({ table }, updateOptions))
|
|
206
|
+
.toDatabaseQuery();
|
|
207
|
+
yield this.query(query);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Set a variable
|
|
212
|
+
*
|
|
213
|
+
* @param setOptions
|
|
214
|
+
*/
|
|
215
|
+
set(setOptions) {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
const query = this.getQueryBuilder().set(setOptions).toDatabaseQuery();
|
|
218
|
+
yield this.query(query);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Delete items from the database
|
|
223
|
+
*
|
|
224
|
+
* @param deleteOptions Delete options
|
|
225
|
+
*/
|
|
226
|
+
delete(deleteOptions) {
|
|
227
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
228
|
+
const table = deleteOptions.table || this.table;
|
|
229
|
+
if (!table) {
|
|
230
|
+
throw new Error('Query repository cannot update() without a table.');
|
|
231
|
+
}
|
|
232
|
+
const query = this.getQueryBuilder()
|
|
233
|
+
.delete(Object.assign({ table }, deleteOptions))
|
|
234
|
+
.toDatabaseQuery();
|
|
235
|
+
yield this.query(query);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
exports.QueryRepository = QueryRepository;
|
|
226
240
|
//# sourceMappingURL=query-repository.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-repository.js","sourceRoot":"","sources":["../../../src/dml/query-repository.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAA8E;AAW9E,4CAAiD;AAcjD;;GAEG;AACH,MAAa,eAEX,SAAQ,uBAAU;IAMnB,YAAmB,OAA+B;;QACjD,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,KAAK,GAAG,MAAA,OAAO,CAAC,KAAK,mCAAI,IAAI,CAAC,KAAK,CAAC;QACzC,IAAI,CAAC,YAAY,GAAG,MAAA,OAAO,CAAC,YAAY,mCAAI,IAAI,CAAC,YAAY,CAAC;QAC9D,IAAI,CAAC,gBAAgB;YACpB,MAAA,OAAO,CAAC,gBAAgB,mCAAI,IAAI,CAAC,gBAAgB,CAAC;IACpD,CAAC;IAEe,IAAI,CAAC,OAA4B;QAChD,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAEpB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACrB,CAAC;IAEM,YAAY;;QAClB,OAAO,MAAA,IAAI,CAAC,KAAK,mCAAI,IAAI,CAAC;IAC3B,CAAC;IAEM,aAAa;;QACnB,IACC,CAAC,I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;;KACD;IAED;;;;OAIG;IACU,MAAM,CAAC,aAA+B;;YAClD,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC;YAEhD,IAAI,CAAC,KAAK,EAAE;gBACX,MAAM,IAAI,KAAK,CACd,mDAAmD,CACnD,CAAC;aACF;YAED,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,EAAE;iBAClC,MAAM,iBAAG,KAAK,IAAK,aAAa,EAAG;iBACnC,eAAe,EAAE,CAAC;YAEpB,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;KAAA;IAED;;;;OAIG;IACU,GAAG,CAAC,UAAsB;;YACtC,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,eAAe,EAAE,CAAC;YAEvE,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;KAAA;IAED;;;;OAIG;IACU,MAAM,CAAC,aAA+B;;YAClD,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC;YAEhD,IAAI,CAAC,KAAK,EAAE;gBACX,MAAM,IAAI,KAAK,CACd,mDAAmD,CACnD,CAAC;aACF;YAED,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,EAAE;iBAClC,MAAM,iBAAG,KAAK,IAAK,aAAa,EAAG;iBACnC,eAAe,EAAE,CAAC;YAEpB,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;KAAA;CACD;
|
|
1
|
+
{"version":3,"file":"query-repository.js","sourceRoot":"","sources":["../../../src/dml/query-repository.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAA8E;AAW9E,4CAAiD;AAcjD;;GAEG;AACH,MAAa,eAEX,SAAQ,uBAAU;IAMnB,YAAmB,OAA+B;;QACjD,KAAK,CAAC,OAAO,CAAC,CAAC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,mDAAmD,CACnD,CAAC;aACF;YAED,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,EAAE;iBAClC,MAAM,iBAAG,KAAK,IAAK,aAAa,EAAG;iBACnC,eAAe,EAAE,CAAC;YAEpB,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;KAAA;IAED;;;;OAIG;IACU,GAAG,CAAC,UAAsB;;YACtC,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,eAAe,EAAE,CAAC;YAEvE,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;KAAA;IAED;;;;OAIG;IACU,MAAM,CAAC,aAA+B;;YAClD,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC;YAEhD,IAAI,CAAC,KAAK,EAAE;gBACX,MAAM,IAAI,KAAK,CACd,mDAAmD,CACnD,CAAC;aACF;YAED,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,EAAE;iBAClC,MAAM,iBAAG,KAAK,IAAK,aAAa,EAAG;iBACnC,eAAe,EAAE,CAAC;YAEpB,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;KAAA;CACD;AApSD,0CAoSC"}
|
package/dml/select.d.ts
CHANGED
|
@@ -1,29 +1,44 @@
|
|
|
1
|
-
import { Expression, SimpleExpression } from '../expression';
|
|
2
|
-
import { DatabaseRecord } from '../record';
|
|
3
|
-
import { Join } from './join';
|
|
4
|
-
import { GroupBy } from './group-by';
|
|
5
|
-
import { OrderBy } from './order-by';
|
|
6
|
-
import { From } from './from';
|
|
7
|
-
export type SelectColumnString<T extends DatabaseRecord = DatabaseRecord> = keyof Partial<T> & string;
|
|
8
|
-
export interface SelectColumnAs<T extends DatabaseRecord = DatabaseRecord> {
|
|
9
|
-
column: SelectColumnString;
|
|
10
|
-
as?: string;
|
|
11
|
-
}
|
|
12
|
-
export interface SelectColumnFromExpression {
|
|
13
|
-
query: SimpleExpression | SimpleExpression[];
|
|
14
|
-
as: string;
|
|
15
|
-
}
|
|
16
|
-
export type SelectColumn<T extends DatabaseRecord = DatabaseRecord> = SelectColumnString<T> | SelectColumnAs<T> | SelectColumnFromExpression;
|
|
17
|
-
export interface
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
import { Expression, SimpleExpression } from '../expression';
|
|
2
|
+
import { DatabaseRecord } from '../record';
|
|
3
|
+
import { Join } from './join';
|
|
4
|
+
import { GroupBy } from './group-by';
|
|
5
|
+
import { OrderBy } from './order-by';
|
|
6
|
+
import { From } from './from';
|
|
7
|
+
export type SelectColumnString<T extends DatabaseRecord = DatabaseRecord> = keyof Partial<T> & string;
|
|
8
|
+
export interface SelectColumnAs<T extends DatabaseRecord = DatabaseRecord> {
|
|
9
|
+
column: SelectColumnString;
|
|
10
|
+
as?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface SelectColumnFromExpression {
|
|
13
|
+
query: SimpleExpression | SimpleExpression[];
|
|
14
|
+
as: string;
|
|
15
|
+
}
|
|
16
|
+
export type SelectColumn<T extends DatabaseRecord = DatabaseRecord> = SelectColumnString<T> | SelectColumnAs<T> | SelectColumnFromExpression;
|
|
17
|
+
export interface UnionQuery<T extends DatabaseRecord = DatabaseRecord> {
|
|
18
|
+
query: SelectQuery<T>;
|
|
19
|
+
all?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface IntersectQuery<T extends DatabaseRecord = DatabaseRecord> {
|
|
22
|
+
query: SelectQuery<T>;
|
|
23
|
+
all?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface ExceptQuery<T extends DatabaseRecord = DatabaseRecord> {
|
|
26
|
+
query: SelectQuery<T>;
|
|
27
|
+
all?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface SelectQuery<T extends DatabaseRecord = DatabaseRecord> {
|
|
30
|
+
columns?: SelectColumn<T>[];
|
|
31
|
+
distinct?: boolean;
|
|
32
|
+
table?: From;
|
|
33
|
+
tableAlias?: string;
|
|
34
|
+
join?: Join[];
|
|
35
|
+
where?: Expression<T>;
|
|
36
|
+
limit?: number;
|
|
37
|
+
offset?: number;
|
|
38
|
+
groupBy?: GroupBy<T>;
|
|
39
|
+
having?: Expression<T>;
|
|
40
|
+
orderBy?: OrderBy<T>;
|
|
41
|
+
union?: UnionQuery<T> | UnionQuery<T>[];
|
|
42
|
+
intersect?: IntersectQuery<T> | IntersectQuery<T>[];
|
|
43
|
+
except?: ExceptQuery<T> | ExceptQuery<T>[];
|
|
44
|
+
}
|
package/dml/select.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=select.js.map
|
package/dml/set-options.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Expression } from '../expression';
|
|
2
|
-
export interface SetOptions {
|
|
3
|
-
column: string;
|
|
4
|
-
value: Expression;
|
|
5
|
-
}
|
|
1
|
+
import { Expression } from '../expression';
|
|
2
|
+
export interface SetOptions {
|
|
3
|
+
column: string;
|
|
4
|
+
value: Expression;
|
|
5
|
+
}
|
package/dml/set-options.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=set-options.js.map
|
package/dml/subquery.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SelectQuery } from './select';
|
|
2
|
-
export declare class Subquery {
|
|
3
|
-
query: SelectQuery;
|
|
4
|
-
constructor(query: SelectQuery);
|
|
5
|
-
}
|
|
1
|
+
import { SelectQuery } from './select';
|
|
2
|
+
export declare class Subquery {
|
|
3
|
+
query: SelectQuery;
|
|
4
|
+
constructor(query: SelectQuery);
|
|
5
|
+
}
|
package/dml/subquery.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Subquery = void 0;
|
|
4
|
-
class Subquery {
|
|
5
|
-
constructor(query) {
|
|
6
|
-
this.query = query;
|
|
7
|
-
return this;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.Subquery = Subquery;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Subquery = void 0;
|
|
4
|
+
class Subquery {
|
|
5
|
+
constructor(query) {
|
|
6
|
+
this.query = query;
|
|
7
|
+
return this;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.Subquery = Subquery;
|
|
11
11
|
//# sourceMappingURL=subquery.js.map
|