@spinajs/orm 1.2.42 → 1.2.49
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/orm.d.ts +1 -0
- package/lib/orm.js +24 -22
- package/lib/orm.js.map +1 -1
- package/package.json +5 -5
- package/lib/helpers.d.ts +0 -1
- package/lib/helpers.js +0 -14
- package/lib/helpers.js.map +0 -1
- package/lib/log-common/src/index.d.ts +0 -180
- package/lib/log-common/src/index.js +0 -49
- package/lib/log-common/src/index.js.map +0 -1
- package/lib/orm/src/builders.d.ts +0 -429
- package/lib/orm/src/builders.js +0 -1082
- package/lib/orm/src/builders.js.map +0 -1
- package/lib/orm/src/cli.d.ts +0 -1
- package/lib/orm/src/cli.js +0 -2
- package/lib/orm/src/cli.js.map +0 -1
- package/lib/orm/src/converters.d.ts +0 -9
- package/lib/orm/src/converters.js +0 -22
- package/lib/orm/src/converters.js.map +0 -1
- package/lib/orm/src/decorators.d.ts +0 -122
- package/lib/orm/src/decorators.js +0 -380
- package/lib/orm/src/decorators.js.map +0 -1
- package/lib/orm/src/driver.d.ts +0 -77
- package/lib/orm/src/driver.js +0 -84
- package/lib/orm/src/driver.js.map +0 -1
- package/lib/orm/src/enums.d.ts +0 -111
- package/lib/orm/src/enums.js +0 -122
- package/lib/orm/src/enums.js.map +0 -1
- package/lib/orm/src/exceptions.d.ts +0 -6
- package/lib/orm/src/exceptions.js +0 -11
- package/lib/orm/src/exceptions.js.map +0 -1
- package/lib/orm/src/hydrators.d.ts +0 -16
- package/lib/orm/src/hydrators.js +0 -70
- package/lib/orm/src/hydrators.js.map +0 -1
- package/lib/orm/src/index.d.ts +0 -12
- package/lib/orm/src/index.js +0 -25
- package/lib/orm/src/index.js.map +0 -1
- package/lib/orm/src/interfaces.d.ts +0 -615
- package/lib/orm/src/interfaces.js +0 -186
- package/lib/orm/src/interfaces.js.map +0 -1
- package/lib/orm/src/model.d.ts +0 -135
- package/lib/orm/src/model.js +0 -449
- package/lib/orm/src/model.js.map +0 -1
- package/lib/orm/src/orm.d.ts +0 -59
- package/lib/orm/src/orm.js +0 -278
- package/lib/orm/src/orm.js.map +0 -1
- package/lib/orm/src/relations.d.ts +0 -96
- package/lib/orm/src/relations.js +0 -503
- package/lib/orm/src/relations.js.map +0 -1
- package/lib/orm/src/statements.d.ts +0 -132
- package/lib/orm/src/statements.js +0 -257
- package/lib/orm/src/statements.js.map +0 -1
- package/lib/orm/src/types.d.ts +0 -2
- package/lib/orm/src/types.js +0 -3
- package/lib/orm/src/types.js.map +0 -1
- package/lib/orm/src/wrappers.d.ts +0 -5
- package/lib/orm/src/wrappers.js +0 -13
- package/lib/orm/src/wrappers.js.map +0 -1
package/lib/orm/src/orm.js
DELETED
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Orm = void 0;
|
|
13
|
-
/* eslint-disable prettier/prettier */
|
|
14
|
-
const configuration_1 = require("@spinajs/configuration");
|
|
15
|
-
const di_1 = require("@spinajs/di");
|
|
16
|
-
const log_1 = require("@spinajs/log");
|
|
17
|
-
const reflection_1 = require("@spinajs/reflection");
|
|
18
|
-
const _ = require("lodash");
|
|
19
|
-
const interfaces_1 = require("./interfaces");
|
|
20
|
-
const model_1 = require("./model");
|
|
21
|
-
const decorators_1 = require("./decorators");
|
|
22
|
-
const exceptions_1 = require("@spinajs/exceptions");
|
|
23
|
-
const luxon_1 = require("luxon");
|
|
24
|
-
const exceptions_2 = require("./exceptions");
|
|
25
|
-
/**
|
|
26
|
-
* Used to exclude sensitive data to others. eg. removed password field from cfg
|
|
27
|
-
*/
|
|
28
|
-
const CFG_PROPS = ['Database', 'User', 'Host', 'Port', 'Filename', 'Driver', 'Name'];
|
|
29
|
-
const MIGRATION_TABLE_NAME = 'spinajs_migration';
|
|
30
|
-
const MIGRATION_FILE_REGEXP = /(.*)_([0-9]{4}_[0-9]{2}_[0-9]{2}_[0-9]{2}_[0-9]{2}_[0-9]{2})\.(.*)/;
|
|
31
|
-
const MIGRATION_TYPE_REGEXP = /(.*)_([0-9]{4}_[0-9]{2}_[0-9]{2}_[0-9]{2}_[0-9]{2}_[0-9]{2})/;
|
|
32
|
-
function migrationFileTypeMatcher(name) {
|
|
33
|
-
const match = name.match(MIGRATION_TYPE_REGEXP);
|
|
34
|
-
if (match === null || match.length !== 3) {
|
|
35
|
-
throw new exceptions_2.OrmException(`Invalid migration file name ${name}, expected: ${name}_YYYY_MM_DD_HH_mm_ss`);
|
|
36
|
-
}
|
|
37
|
-
return match[1];
|
|
38
|
-
}
|
|
39
|
-
class Orm extends di_1.AsyncModule {
|
|
40
|
-
constructor() {
|
|
41
|
-
super(...arguments);
|
|
42
|
-
this.Connections = new Map();
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
*
|
|
46
|
-
* Migrates schema up ( fill function is not executed )
|
|
47
|
-
*
|
|
48
|
-
* @param name - migration file name
|
|
49
|
-
*/
|
|
50
|
-
async migrateUp(name) {
|
|
51
|
-
const self = this;
|
|
52
|
-
await this.executeAvaibleMigrations(name, async (migration, driver) => {
|
|
53
|
-
var _a, _b;
|
|
54
|
-
const trFunction = async (driver) => {
|
|
55
|
-
var _a, _b;
|
|
56
|
-
await migration.up(driver);
|
|
57
|
-
await driver
|
|
58
|
-
.insert()
|
|
59
|
-
.into((_b = (_a = driver.Options.Migration) === null || _a === void 0 ? void 0 : _a.Table) !== null && _b !== void 0 ? _b : MIGRATION_TABLE_NAME)
|
|
60
|
-
.values({
|
|
61
|
-
Migration: migration.constructor.name,
|
|
62
|
-
CreatedAt: new Date(),
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
|
-
if (((_b = (_a = driver.Options.Migration) === null || _a === void 0 ? void 0 : _a.Transaction) === null || _b === void 0 ? void 0 : _b.Mode) === interfaces_1.MigrationTransactionMode.PerMigration) {
|
|
66
|
-
await driver.transaction(trFunction);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
await trFunction(driver);
|
|
70
|
-
}
|
|
71
|
-
self.Log.info(`Migration ${migration.constructor.name} success !`);
|
|
72
|
-
}, false);
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
*
|
|
76
|
-
* Migrates schema up ( fill function is not executed )
|
|
77
|
-
*
|
|
78
|
-
* @param name - migration file name
|
|
79
|
-
*/
|
|
80
|
-
async migrateDown(name) {
|
|
81
|
-
const self = this;
|
|
82
|
-
await this.executeAvaibleMigrations(name, async (migration, driver) => {
|
|
83
|
-
var _a, _b;
|
|
84
|
-
const trFunction = async (driver) => {
|
|
85
|
-
var _a, _b;
|
|
86
|
-
await migration.down(driver);
|
|
87
|
-
await driver
|
|
88
|
-
.del()
|
|
89
|
-
.from((_b = (_a = driver.Options.Migration) === null || _a === void 0 ? void 0 : _a.Table) !== null && _b !== void 0 ? _b : MIGRATION_TABLE_NAME)
|
|
90
|
-
.where({
|
|
91
|
-
Migration: migration.constructor.name,
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
if (((_b = (_a = driver.Options.Migration) === null || _a === void 0 ? void 0 : _a.Transaction) === null || _b === void 0 ? void 0 : _b.Mode) === interfaces_1.MigrationTransactionMode.PerMigration) {
|
|
95
|
-
await driver.transaction(trFunction);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
await trFunction(driver);
|
|
99
|
-
}
|
|
100
|
-
self.Log.info(`Migration down ${migration.constructor.name} success !`);
|
|
101
|
-
}, true);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* This function is exposed mainly for unit testing purposes. It reloads table information for models
|
|
105
|
-
* ORM always try to load table at resolve time
|
|
106
|
-
*/
|
|
107
|
-
async reloadTableInfo() {
|
|
108
|
-
for (const m of this.Models) {
|
|
109
|
-
const descriptor = (0, model_1.extractModelDescriptor)(m.type);
|
|
110
|
-
if (descriptor) {
|
|
111
|
-
const connection = this.Connections.get(descriptor.Connection);
|
|
112
|
-
if (connection) {
|
|
113
|
-
const columns = await connection.tableInfo(descriptor.TableName, connection.Options.Database);
|
|
114
|
-
if (columns) {
|
|
115
|
-
m.type[decorators_1.MODEL_DESCTRIPTION_SYMBOL].Columns = _.uniqBy(_.map(columns, (c) => {
|
|
116
|
-
return _.assign(c, _.find(descriptor.Columns, { Name: c.Name }));
|
|
117
|
-
}), 'Name');
|
|
118
|
-
}
|
|
119
|
-
for (const [key, val] of descriptor.Converters) {
|
|
120
|
-
const column = m.type[decorators_1.MODEL_DESCTRIPTION_SYMBOL].Columns.find((c) => c.Name === key);
|
|
121
|
-
if (column) {
|
|
122
|
-
column.Converter = connection.Container.hasRegistered(val) ? connection.Container.resolve(val) : null;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
async resolveAsync() {
|
|
130
|
-
const migrateOnStartup = this.Configuration.get('db.Migration.Startup', false);
|
|
131
|
-
await this.createConnections();
|
|
132
|
-
if (migrateOnStartup) {
|
|
133
|
-
await this.prepareMigrations();
|
|
134
|
-
await this.migrateUp();
|
|
135
|
-
}
|
|
136
|
-
await this.reloadTableInfo();
|
|
137
|
-
this.applyModelMixins();
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
*
|
|
141
|
-
* Register model to ORM programatically so ORM can see it and use it. Sometimes dynamical model discovery is not possible eg.
|
|
142
|
-
* in webpack evnironment. In such case we must tell ORM manually what to load.
|
|
143
|
-
*
|
|
144
|
-
* NOTE: use it in ORM constructor before ORM is resolved & model list used.
|
|
145
|
-
*
|
|
146
|
-
* @param model - model to register
|
|
147
|
-
*/
|
|
148
|
-
registerModel(model) {
|
|
149
|
-
this.Models.push({
|
|
150
|
-
file: `${model.name}.registered`,
|
|
151
|
-
name: model.name,
|
|
152
|
-
type: model,
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
*
|
|
157
|
-
* Register migration to ORM programatically so ORM can see it and use it. Sometimes dynamical migration discovery is not possible eg.
|
|
158
|
-
* in webpack evnironment. In such case we must tell ORM manually what to load.
|
|
159
|
-
*
|
|
160
|
-
* NOTE: use it in ORM constructor before ORM is resolved & migrate function used.
|
|
161
|
-
*
|
|
162
|
-
* @param model - model to register
|
|
163
|
-
*/
|
|
164
|
-
registerMigration(migration) {
|
|
165
|
-
const date = luxon_1.DateTime.now().toFormat('yyyy_MM_dd_HH_mm_ss');
|
|
166
|
-
this.Migrations.push({
|
|
167
|
-
file: `${migration.name}_${date}.registered`,
|
|
168
|
-
name: `${migration.name}_${date}`,
|
|
169
|
-
type: migration,
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
async createConnections() {
|
|
173
|
-
const connections = await Promise.all(this.Configuration.get('db.Connections', [])
|
|
174
|
-
.map((c) => {
|
|
175
|
-
return this.Container.resolve(c.Driver, [c]);
|
|
176
|
-
})
|
|
177
|
-
.filter((c) => c !== null)
|
|
178
|
-
.map((c) => c.connect()));
|
|
179
|
-
connections.forEach((c) => {
|
|
180
|
-
this.Connections.set(c.Options.Name, c);
|
|
181
|
-
this.Log.info(`Found ORM driver ${c.Options.Name} with parameters ${JSON.stringify(_.pick(c.Options, CFG_PROPS))}`);
|
|
182
|
-
});
|
|
183
|
-
const defaultConnection = this.Configuration.get('db.DefaultConnection');
|
|
184
|
-
if (defaultConnection) {
|
|
185
|
-
if (!this.Connections.has(defaultConnection)) {
|
|
186
|
-
throw new exceptions_1.InvalidOperation(`default connection ${defaultConnection} not exists`);
|
|
187
|
-
}
|
|
188
|
-
this.Connections.set('default', this.Connections.get(defaultConnection));
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
applyModelMixins() {
|
|
192
|
-
this.Models.forEach((m) => {
|
|
193
|
-
// tslint:disable-next-line: forin
|
|
194
|
-
for (const mixin in model_1.MODEL_STATIC_MIXINS) {
|
|
195
|
-
m.type[mixin] = model_1.MODEL_STATIC_MIXINS[mixin].bind(m.type);
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
async executeAvaibleMigrations(name, callback, down) {
|
|
200
|
-
var _a, _b;
|
|
201
|
-
const toMigrate = name ? this.Migrations.filter((m) => m.name === name) : this.Migrations;
|
|
202
|
-
let migrations = toMigrate
|
|
203
|
-
.map((x) => {
|
|
204
|
-
const match = x.file.match(MIGRATION_FILE_REGEXP);
|
|
205
|
-
if (match === null || match.length !== 4) {
|
|
206
|
-
throw new exceptions_2.OrmException(`Migration file name have invalid format ( expected: some_name_yyyy_MM_dd_HH_mm_ss got ${x.file})`);
|
|
207
|
-
}
|
|
208
|
-
const created = luxon_1.DateTime.fromFormat(match[2], 'yyyy_MM_dd_HH_mm_ss');
|
|
209
|
-
if (!created.isValid) {
|
|
210
|
-
throw new exceptions_2.OrmException(`Migration file ${x.file} have invalid name format ( invalid migration date )`);
|
|
211
|
-
}
|
|
212
|
-
return Object.assign({ created }, x);
|
|
213
|
-
})
|
|
214
|
-
.filter((x) => x !== null)
|
|
215
|
-
.sort((a, b) => {
|
|
216
|
-
if (a.created < b.created) {
|
|
217
|
-
return -1;
|
|
218
|
-
}
|
|
219
|
-
return 1;
|
|
220
|
-
});
|
|
221
|
-
if (down) {
|
|
222
|
-
migrations = migrations.reverse();
|
|
223
|
-
}
|
|
224
|
-
for (const m of migrations) {
|
|
225
|
-
const md = m.type[decorators_1.MIGRATION_DESCRIPTION_SYMBOL];
|
|
226
|
-
const cn = this.Connections.get(md.Connection);
|
|
227
|
-
const migrationTableName = (_b = (_a = cn.Options.Migration) === null || _a === void 0 ? void 0 : _a.Table) !== null && _b !== void 0 ? _b : MIGRATION_TABLE_NAME;
|
|
228
|
-
const exists = await cn.select().from(migrationTableName).where({ Migration: m.name }).first();
|
|
229
|
-
if (!exists) {
|
|
230
|
-
const migration = await this.Container.resolve(m.type, [cn]);
|
|
231
|
-
this.Log.info(`Setting up migration ${m.name} from file ${m.file} created at ${m.created} mode: ${down ? 'migrate down' : 'migrate up'}`);
|
|
232
|
-
await callback(migration, cn);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
async prepareMigrations() {
|
|
237
|
-
var _a, _b;
|
|
238
|
-
for (const [_, connection] of this.Connections) {
|
|
239
|
-
const migrationTableName = (_b = (_a = connection.Options.Migration) === null || _a === void 0 ? void 0 : _a.Table) !== null && _b !== void 0 ? _b : MIGRATION_TABLE_NAME;
|
|
240
|
-
let migrationTable = null;
|
|
241
|
-
// if there is no info on migraiton table or query throws we assume table not exists
|
|
242
|
-
try {
|
|
243
|
-
migrationTable = await connection.tableInfo(migrationTableName);
|
|
244
|
-
// tslint:disable-next-line: no-empty
|
|
245
|
-
}
|
|
246
|
-
catch (_c) { }
|
|
247
|
-
if (!migrationTable) {
|
|
248
|
-
this.Log.info(`No migration table in database, recreating migration information ...`);
|
|
249
|
-
await connection.schema().createTable(migrationTableName, (table) => {
|
|
250
|
-
table.string('Migration').unique().notNull();
|
|
251
|
-
table.dateTime('CreatedAt').notNull();
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
__decorate([
|
|
258
|
-
(0, reflection_1.ListFromFiles)('/**/!(*.d).{ts,js}', 'system.dirs.models'),
|
|
259
|
-
__metadata("design:type", Array)
|
|
260
|
-
], Orm.prototype, "Models", void 0);
|
|
261
|
-
__decorate([
|
|
262
|
-
(0, reflection_1.ListFromFiles)('/**/!(*.d).{ts,js}', 'system.dirs.migrations', migrationFileTypeMatcher),
|
|
263
|
-
__metadata("design:type", Array)
|
|
264
|
-
], Orm.prototype, "Migrations", void 0);
|
|
265
|
-
__decorate([
|
|
266
|
-
(0, di_1.Autoinject)(),
|
|
267
|
-
__metadata("design:type", di_1.Container)
|
|
268
|
-
], Orm.prototype, "Container", void 0);
|
|
269
|
-
__decorate([
|
|
270
|
-
(0, log_1.Logger)('ORM'),
|
|
271
|
-
__metadata("design:type", log_1.Log)
|
|
272
|
-
], Orm.prototype, "Log", void 0);
|
|
273
|
-
__decorate([
|
|
274
|
-
(0, di_1.Autoinject)(),
|
|
275
|
-
__metadata("design:type", configuration_1.Configuration)
|
|
276
|
-
], Orm.prototype, "Configuration", void 0);
|
|
277
|
-
exports.Orm = Orm;
|
|
278
|
-
//# sourceMappingURL=orm.js.map
|
package/lib/orm/src/orm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"orm.js","sourceRoot":"","sources":["../../../src/orm.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sCAAsC;AACtC,0DAAuD;AACvD,oCAAwE;AACxE,sCAA2C;AAC3C,oDAA+D;AAC/D,4BAA4B;AAC5B,6CAA+H;AAC/H,mCAAiF;AACjF,6CAAuF;AAEvF,oDAAuD;AACvD,iCAAiC;AACjC,6CAA4C;AAE5C;;GAEG;AACH,MAAM,SAAS,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AACrF,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AACjD,MAAM,qBAAqB,GAAG,oEAAoE,CAAC;AACnG,MA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gBACnB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,sEAAsE,CAAC,CAAC;gBAEtF,MAAM,UAAU,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC,kBAAkB,EAAE,CAAC,KAAK,EAAE,EAAE;oBAClE,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC;oBAC7C,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,CAAC;gBACxC,CAAC,CAAC,CAAC;aACJ;SACF;IACH,CAAC;CACF;AApRC;IADC,IAAA,0BAAa,EAAC,oBAAoB,EAAE,oBAAoB,CAAC;8BAC3C,KAAK;mCAAuB;AAG3C;IADC,IAAA,0BAAa,EAAC,oBAAoB,EAAE,wBAAwB,EAAE,wBAAwB,CAAC;8BACrE,KAAK;uCAA0B;AAKlD;IADC,IAAA,eAAU,GAAE;8BACK,cAAS;sCAAC;AAG5B;IADC,IAAA,YAAM,EAAC,KAAK,CAAC;8BACC,SAAG;gCAAC;AAGnB;IADC,IAAA,eAAU,GAAE;8BACY,6BAAa;0CAAC;AAhBzC,kBAsRC"}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { IRelationDescriptor, IModelDescrtiptor, IBuilderMiddleware, InsertBehaviour, ForwardRefFunction } from './interfaces';
|
|
2
|
-
import { Constructor } from '@spinajs/di';
|
|
3
|
-
import { SelectQueryBuilder } from './builders';
|
|
4
|
-
import { ModelBase } from './model';
|
|
5
|
-
import { Orm } from './orm';
|
|
6
|
-
export interface IOrmRelation {
|
|
7
|
-
execute(callback?: (this: SelectQueryBuilder, relation: OrmRelation) => void): void;
|
|
8
|
-
}
|
|
9
|
-
export declare abstract class OrmRelation implements IOrmRelation {
|
|
10
|
-
protected _orm: Orm;
|
|
11
|
-
protected _query: SelectQueryBuilder<any>;
|
|
12
|
-
_description: IRelationDescriptor;
|
|
13
|
-
parentRelation?: OrmRelation;
|
|
14
|
-
protected _targetModel: Constructor<ModelBase> | ForwardRefFunction;
|
|
15
|
-
protected _targetModelDescriptor: IModelDescrtiptor;
|
|
16
|
-
protected _relationQuery: SelectQueryBuilder;
|
|
17
|
-
get Alias(): string;
|
|
18
|
-
constructor(_orm: Orm, _query: SelectQueryBuilder<any>, _description: IRelationDescriptor, parentRelation?: OrmRelation);
|
|
19
|
-
abstract execute(callback?: (this: SelectQueryBuilder, relation: OrmRelation) => void): void;
|
|
20
|
-
}
|
|
21
|
-
export declare class DiscriminationMapMiddleware implements IBuilderMiddleware {
|
|
22
|
-
protected _description: IModelDescrtiptor;
|
|
23
|
-
constructor(_description: IModelDescrtiptor);
|
|
24
|
-
afterData(data: any[]): any[];
|
|
25
|
-
modelCreation(data: any): ModelBase;
|
|
26
|
-
afterHydration(_data: ModelBase[]): Promise<void>;
|
|
27
|
-
}
|
|
28
|
-
export declare class BelongsToRelation extends OrmRelation {
|
|
29
|
-
protected _targetModel: Constructor<ModelBase>;
|
|
30
|
-
protected _targetModelDescriptor: IModelDescrtiptor;
|
|
31
|
-
protected _relationQuery: SelectQueryBuilder;
|
|
32
|
-
constructor(_orm: Orm, _query: SelectQueryBuilder<any>, _description: IRelationDescriptor, _parentRelation?: OrmRelation);
|
|
33
|
-
execute(callback: (this: SelectQueryBuilder, relation: OrmRelation) => void): void;
|
|
34
|
-
}
|
|
35
|
-
export declare class BelongsToRecursiveRelation extends OrmRelation {
|
|
36
|
-
protected _targetModel: Constructor<ModelBase>;
|
|
37
|
-
protected _targetModelDescriptor: IModelDescrtiptor;
|
|
38
|
-
protected _relationQuery: SelectQueryBuilder;
|
|
39
|
-
constructor(_orm: Orm, _query: SelectQueryBuilder<any>, _description: IRelationDescriptor, _parentRelation?: OrmRelation);
|
|
40
|
-
execute(callback: (this: SelectQueryBuilder, relation: OrmRelation) => void): void;
|
|
41
|
-
}
|
|
42
|
-
export declare class OneToManyRelation extends OrmRelation {
|
|
43
|
-
constructor(_orm: Orm, _query: SelectQueryBuilder<any>, _description: IRelationDescriptor, _parentRelation?: OrmRelation);
|
|
44
|
-
execute(callback?: (this: SelectQueryBuilder<any>, relation: OrmRelation) => void): void;
|
|
45
|
-
}
|
|
46
|
-
export declare class ManyToManyRelation extends OrmRelation {
|
|
47
|
-
protected _joinModel: Constructor<ModelBase>;
|
|
48
|
-
protected _joinModelDescriptor: IModelDescrtiptor;
|
|
49
|
-
protected _joinQuery: SelectQueryBuilder;
|
|
50
|
-
get TableJoinQuery(): SelectQueryBuilder<any>;
|
|
51
|
-
get RelationQuery(): SelectQueryBuilder<any>;
|
|
52
|
-
constructor(_orm: Orm, _query: SelectQueryBuilder<any>, _description: IRelationDescriptor, _parentRelation?: OrmRelation);
|
|
53
|
-
execute(callback?: (this: SelectQueryBuilder<any>, relation: OrmRelation) => void): void;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Iterable list of populated relation entities
|
|
57
|
-
*
|
|
58
|
-
* It allows to add / remove objects to relation
|
|
59
|
-
*/
|
|
60
|
-
export declare abstract class Relation<R extends ModelBase> extends Array<R> {
|
|
61
|
-
protected owner: ModelBase;
|
|
62
|
-
protected model: Constructor<R> | ForwardRefFunction;
|
|
63
|
-
protected Relation: IRelationDescriptor;
|
|
64
|
-
protected TargetModelDescriptor: IModelDescrtiptor;
|
|
65
|
-
protected Orm: Orm;
|
|
66
|
-
constructor(owner: ModelBase, model: Constructor<R> | ForwardRefFunction, Relation: IRelationDescriptor, objects?: R[]);
|
|
67
|
-
/**
|
|
68
|
-
* Removes from relation & deletes from db
|
|
69
|
-
*
|
|
70
|
-
* @param obj - data to remove
|
|
71
|
-
*/
|
|
72
|
-
abstract remove(obj: R | R[]): Promise<void>;
|
|
73
|
-
/**
|
|
74
|
-
*
|
|
75
|
-
* Add to relation & saves to db
|
|
76
|
-
*
|
|
77
|
-
* @param obj - data to add
|
|
78
|
-
*/
|
|
79
|
-
abstract add(obj: R | R[], mode?: InsertBehaviour): Promise<void>;
|
|
80
|
-
/**
|
|
81
|
-
* Delete all objects from relation
|
|
82
|
-
*/
|
|
83
|
-
clear(): Promise<void>;
|
|
84
|
-
/**
|
|
85
|
-
* Populates this relation
|
|
86
|
-
*/
|
|
87
|
-
populate(callback?: (this: SelectQueryBuilder<this>, relation: OrmRelation) => void): Promise<void>;
|
|
88
|
-
}
|
|
89
|
-
export declare class ManyToManyRelationList<T extends ModelBase> extends Relation<T> {
|
|
90
|
-
remove(obj: T | T[]): Promise<void>;
|
|
91
|
-
add(obj: T | T[], mode?: InsertBehaviour): Promise<void>;
|
|
92
|
-
}
|
|
93
|
-
export declare class OneToManyRelationList<T extends ModelBase> extends Relation<T> {
|
|
94
|
-
remove(obj: T | T[]): Promise<void>;
|
|
95
|
-
add(obj: T | T[], mode?: InsertBehaviour): Promise<void>;
|
|
96
|
-
}
|