@spinajs/orm-sql 2.0.46 → 2.0.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/README.md +11 -11
- package/lib/builders.d.ts +1 -2
- package/lib/builders.d.ts.map +1 -0
- package/lib/builders.js +7 -10
- package/lib/builders.js.map +1 -1
- package/lib/compilers.d.ts +1 -0
- package/lib/compilers.d.ts.map +1 -0
- package/lib/compilers.js +138 -146
- package/lib/compilers.js.map +1 -1
- package/lib/converters.d.ts +1 -0
- package/lib/converters.d.ts.map +1 -0
- package/lib/converters.js +9 -14
- package/lib/converters.js.map +1 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +47 -65
- package/lib/index.js.map +1 -1
- package/lib/statements.d.ts +1 -0
- package/lib/statements.d.ts.map +1 -0
- package/lib/statements.js +45 -51
- package/lib/statements.js.map +1 -1
- package/package.json +53 -50
- package/lib/orm/src/builders.d.ts +0 -636
- package/lib/orm/src/builders.js +0 -1509
- package/lib/orm/src/builders.js.map +0 -1
- package/lib/orm/src/converters.d.ts +0 -14
- package/lib/orm/src/converters.js +0 -57
- package/lib/orm/src/converters.js.map +0 -1
- package/lib/orm/src/decorators.d.ts +0 -152
- package/lib/orm/src/decorators.js +0 -454
- package/lib/orm/src/decorators.js.map +0 -1
- package/lib/orm/src/dehydrators.d.ts +0 -7
- package/lib/orm/src/dehydrators.js +0 -41
- package/lib/orm/src/dehydrators.js.map +0 -1
- package/lib/orm/src/driver.d.ts +0 -80
- package/lib/orm/src/driver.js +0 -104
- package/lib/orm/src/driver.js.map +0 -1
- package/lib/orm/src/enums.d.ts +0 -115
- package/lib/orm/src/enums.js +0 -125
- 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 -19
- package/lib/orm/src/hydrators.js +0 -110
- package/lib/orm/src/hydrators.js.map +0 -1
- package/lib/orm/src/interfaces.d.ts +0 -794
- package/lib/orm/src/interfaces.js +0 -293
- package/lib/orm/src/interfaces.js.map +0 -1
- package/lib/orm/src/model.d.ts +0 -310
- package/lib/orm/src/model.js +0 -779
- package/lib/orm/src/model.js.map +0 -1
- package/lib/orm/src/orm.d.ts +0 -61
- package/lib/orm/src/orm.js +0 -341
- package/lib/orm/src/orm.js.map +0 -1
- package/lib/orm/src/relations.d.ts +0 -150
- package/lib/orm/src/relations.js +0 -681
- package/lib/orm/src/relations.js.map +0 -1
- package/lib/orm/src/statements.d.ts +0 -140
- package/lib/orm/src/statements.js +0 -314
- package/lib/orm/src/statements.js.map +0 -1
- package/lib/orm/src/types.d.ts +0 -11
- package/lib/orm/src/types.js +0 -3
- package/lib/orm/src/types.js.map +0 -1
- package/lib/orm-sql/src/builders.d.ts +0 -11
- package/lib/orm-sql/src/builders.js +0 -42
- package/lib/orm-sql/src/builders.js.map +0 -1
- package/lib/orm-sql/src/compilers.d.ts +0 -226
- package/lib/orm-sql/src/compilers.js +0 -1016
- package/lib/orm-sql/src/compilers.js.map +0 -1
- package/lib/orm-sql/src/converters.d.ts +0 -10
- package/lib/orm-sql/src/converters.js +0 -39
- package/lib/orm-sql/src/converters.js.map +0 -1
- package/lib/orm-sql/src/index.d.ts +0 -6
- package/lib/orm-sql/src/index.js +0 -70
- package/lib/orm-sql/src/index.js.map +0 -1
- package/lib/orm-sql/src/statements.d.ts +0 -46
- package/lib/orm-sql/src/statements.js +0 -268
- package/lib/orm-sql/src/statements.js.map +0 -1
|
@@ -1,454 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Set = exports.UniversalConverter = exports.Json = exports.DateTime = exports.HasManyToMany = exports.Historical = exports.HasMany = exports.ForwardBelongsTo = exports.BelongsTo = exports.forwardRef = exports.Recursive = exports.DiscriminationMap = exports.JunctionTable = exports.Uuid = exports.Ignore = exports.Primary = exports.Archived = exports.SoftDelete = exports.UpdatedAt = exports.CreatedAt = exports.Model = exports.Connection = exports.Migration = exports.extractDecoratorDescriptor = exports.MIGRATION_DESCRIPTION_SYMBOL = exports.MODEL_DESCTRIPTION_SYMBOL = void 0;
|
|
4
|
-
const interfaces_1 = require("./interfaces");
|
|
5
|
-
/* eslint-disable prettier/prettier */
|
|
6
|
-
const converters_1 = require("./converters");
|
|
7
|
-
const di_1 = require("@spinajs/di");
|
|
8
|
-
const interfaces_2 = require("./interfaces");
|
|
9
|
-
require("reflect-metadata");
|
|
10
|
-
const model_1 = require("./model");
|
|
11
|
-
const exceptions_1 = require("@spinajs/exceptions");
|
|
12
|
-
exports.MODEL_DESCTRIPTION_SYMBOL = Symbol.for('MODEL_DESCRIPTOR');
|
|
13
|
-
exports.MIGRATION_DESCRIPTION_SYMBOL = Symbol.for('MIGRATION_DESCRIPTOR');
|
|
14
|
-
/**
|
|
15
|
-
* Helper func to create model metadata
|
|
16
|
-
*/
|
|
17
|
-
function extractDecoratorDescriptor(callback, base = false) {
|
|
18
|
-
return (target, propertyKey, indexOrDescriptor) => {
|
|
19
|
-
let metadata = null;
|
|
20
|
-
if (!base) {
|
|
21
|
-
metadata = target.constructor[exports.MODEL_DESCTRIPTION_SYMBOL];
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
metadata = target[exports.MODEL_DESCTRIPTION_SYMBOL];
|
|
25
|
-
}
|
|
26
|
-
if (!metadata) {
|
|
27
|
-
metadata = {
|
|
28
|
-
Driver: null,
|
|
29
|
-
Converters: new Map(),
|
|
30
|
-
Columns: [],
|
|
31
|
-
Connection: null,
|
|
32
|
-
PrimaryKey: '',
|
|
33
|
-
SoftDelete: {
|
|
34
|
-
DeletedAt: '',
|
|
35
|
-
},
|
|
36
|
-
Archived: {
|
|
37
|
-
ArchivedAt: '',
|
|
38
|
-
},
|
|
39
|
-
TableName: '',
|
|
40
|
-
Timestamps: {
|
|
41
|
-
CreatedAt: '',
|
|
42
|
-
UpdatedAt: '',
|
|
43
|
-
},
|
|
44
|
-
Relations: new Map(),
|
|
45
|
-
Name: target.constructor.name,
|
|
46
|
-
JunctionModelProperties: [],
|
|
47
|
-
DiscriminationMap: {
|
|
48
|
-
Field: '',
|
|
49
|
-
Models: null,
|
|
50
|
-
},
|
|
51
|
-
Schema: {},
|
|
52
|
-
};
|
|
53
|
-
if (!base) {
|
|
54
|
-
target.constructor[exports.MODEL_DESCTRIPTION_SYMBOL] = metadata;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
target[exports.MODEL_DESCTRIPTION_SYMBOL] = metadata;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (callback) {
|
|
61
|
-
callback(metadata, target, propertyKey, indexOrDescriptor);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
exports.extractDecoratorDescriptor = extractDecoratorDescriptor;
|
|
66
|
-
/**
|
|
67
|
-
* Sets migration option
|
|
68
|
-
*
|
|
69
|
-
* @param connection - connection name, must exists in configuration file
|
|
70
|
-
*/
|
|
71
|
-
function Migration(connection) {
|
|
72
|
-
return (target) => {
|
|
73
|
-
let metadata = target[exports.MIGRATION_DESCRIPTION_SYMBOL];
|
|
74
|
-
if (!metadata) {
|
|
75
|
-
metadata = {
|
|
76
|
-
Connection: '',
|
|
77
|
-
};
|
|
78
|
-
target[exports.MIGRATION_DESCRIPTION_SYMBOL] = metadata;
|
|
79
|
-
}
|
|
80
|
-
metadata.Connection = connection;
|
|
81
|
-
di_1.DI.register(target).as('__migrations__');
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
exports.Migration = Migration;
|
|
85
|
-
/**
|
|
86
|
-
* Connection model decorator, assigns connection to model
|
|
87
|
-
*
|
|
88
|
-
* @param name - connection name, must be avaible in db config
|
|
89
|
-
*/
|
|
90
|
-
function Connection(name) {
|
|
91
|
-
return extractDecoratorDescriptor((model) => {
|
|
92
|
-
model.Connection = name;
|
|
93
|
-
}, true);
|
|
94
|
-
}
|
|
95
|
-
exports.Connection = Connection;
|
|
96
|
-
/**
|
|
97
|
-
* TableName model decorator, assigns table from database to model
|
|
98
|
-
*
|
|
99
|
-
* @param name - table name in database that is referred by this model
|
|
100
|
-
*/
|
|
101
|
-
function Model(tableName) {
|
|
102
|
-
return extractDecoratorDescriptor((model, target) => {
|
|
103
|
-
di_1.DI.register(target).as('__models__');
|
|
104
|
-
model.TableName = tableName;
|
|
105
|
-
}, true);
|
|
106
|
-
}
|
|
107
|
-
exports.Model = Model;
|
|
108
|
-
/**
|
|
109
|
-
* Set create timestamps feature to model. Proper columns must be avaible in database table.
|
|
110
|
-
* It allow to track creation times & changes to model
|
|
111
|
-
*/
|
|
112
|
-
function CreatedAt() {
|
|
113
|
-
return extractDecoratorDescriptor((model, target, propertyKey) => {
|
|
114
|
-
const type = Reflect.getMetadata('design:type', target, propertyKey);
|
|
115
|
-
if (type.name !== 'DateTime') {
|
|
116
|
-
throw Error('Proprety CreatedAt must be DateTime type');
|
|
117
|
-
}
|
|
118
|
-
model.Timestamps.CreatedAt = propertyKey;
|
|
119
|
-
// add converter for this field
|
|
120
|
-
model.Converters.set(propertyKey, {
|
|
121
|
-
Class: interfaces_2.DatetimeValueConverter,
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
exports.CreatedAt = CreatedAt;
|
|
126
|
-
/**
|
|
127
|
-
* Set update timestamps feature to model. Proper columns must be avaible in database table.
|
|
128
|
-
* It allow to track creation times & changes to model
|
|
129
|
-
*/
|
|
130
|
-
function UpdatedAt() {
|
|
131
|
-
return extractDecoratorDescriptor((model, target, propertyKey) => {
|
|
132
|
-
const type = Reflect.getMetadata('design:type', target, propertyKey);
|
|
133
|
-
if (type.name !== 'DateTime') {
|
|
134
|
-
throw Error('Proprety UpdatedAt must be DateTime type');
|
|
135
|
-
}
|
|
136
|
-
model.Timestamps.UpdatedAt = propertyKey;
|
|
137
|
-
// add converter for this field
|
|
138
|
-
model.Converters.set(propertyKey, {
|
|
139
|
-
Class: interfaces_2.DatetimeValueConverter,
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
exports.UpdatedAt = UpdatedAt;
|
|
144
|
-
/**
|
|
145
|
-
* Sets soft delete feature to model. Soft delete dont delete model, but sets deletion date and hides from
|
|
146
|
-
* select result by default.
|
|
147
|
-
*/
|
|
148
|
-
function SoftDelete() {
|
|
149
|
-
return extractDecoratorDescriptor((model, target, propertyKey) => {
|
|
150
|
-
const type = Reflect.getMetadata('design:type', target, propertyKey);
|
|
151
|
-
if (type.name !== 'DateTime') {
|
|
152
|
-
throw Error('Proprety DeletedAt must be DateTime type');
|
|
153
|
-
}
|
|
154
|
-
model.SoftDelete.DeletedAt = propertyKey;
|
|
155
|
-
// add converter for this field
|
|
156
|
-
model.Converters.set(propertyKey, {
|
|
157
|
-
Class: interfaces_2.DatetimeValueConverter,
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
exports.SoftDelete = SoftDelete;
|
|
162
|
-
/**
|
|
163
|
-
* Enable archive mode for model. If enabled all changes creates new instance in DB and old have set archived field
|
|
164
|
-
* and gets attached to new model. It enabled to track changes to model in DB and also preserve data in relations.
|
|
165
|
-
*
|
|
166
|
-
*/
|
|
167
|
-
function Archived() {
|
|
168
|
-
return extractDecoratorDescriptor((model, target, propertyKey) => {
|
|
169
|
-
const type = Reflect.getMetadata('design:type', target, propertyKey);
|
|
170
|
-
if (type.name !== 'DateTime') {
|
|
171
|
-
throw Error('Proprety DeletedAt must be Date type');
|
|
172
|
-
}
|
|
173
|
-
model.Archived.ArchivedAt = propertyKey;
|
|
174
|
-
// add converter for this field
|
|
175
|
-
model.Converters.set(propertyKey, {
|
|
176
|
-
Class: interfaces_2.DatetimeValueConverter,
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
exports.Archived = Archived;
|
|
181
|
-
/**
|
|
182
|
-
* Makrs field as primary key
|
|
183
|
-
*/
|
|
184
|
-
function Primary() {
|
|
185
|
-
return extractDecoratorDescriptor((model, _target, propertyKey) => {
|
|
186
|
-
model.PrimaryKey = propertyKey;
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
exports.Primary = Primary;
|
|
190
|
-
/**
|
|
191
|
-
* Marks columns as UUID. Column will be generated ad creation
|
|
192
|
-
*/
|
|
193
|
-
function Ignore() {
|
|
194
|
-
return extractDecoratorDescriptor((model, _target, propertyKey) => {
|
|
195
|
-
const columnDesc = model.Columns.find((c) => c.Name === propertyKey);
|
|
196
|
-
if (!columnDesc) {
|
|
197
|
-
// we dont want to fill all props, they will be loaded from db and mergeg with this
|
|
198
|
-
model.Columns.push({ Name: propertyKey, Ignore: true });
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
columnDesc.Ignore = true;
|
|
202
|
-
}
|
|
203
|
-
}, true);
|
|
204
|
-
}
|
|
205
|
-
exports.Ignore = Ignore;
|
|
206
|
-
/**
|
|
207
|
-
* Marks columns as UUID. Column will be generated ad creation
|
|
208
|
-
*/
|
|
209
|
-
function Uuid() {
|
|
210
|
-
return extractDecoratorDescriptor((model, _target, propertyKey) => {
|
|
211
|
-
const columnDesc = model.Columns.find((c) => c.Name === propertyKey);
|
|
212
|
-
if (!columnDesc) {
|
|
213
|
-
// we dont want to fill all props, they will be loaded from db and mergeg with this
|
|
214
|
-
model.Columns.push({ Name: propertyKey, Uuid: true });
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
columnDesc.Uuid = true;
|
|
218
|
-
}
|
|
219
|
-
model.Converters.set(propertyKey, {
|
|
220
|
-
Class: converters_1.UuidConverter,
|
|
221
|
-
});
|
|
222
|
-
}, true);
|
|
223
|
-
}
|
|
224
|
-
exports.Uuid = Uuid;
|
|
225
|
-
function JunctionTable() {
|
|
226
|
-
return extractDecoratorDescriptor((model, target, propertyKey) => {
|
|
227
|
-
model.JunctionModelProperties.push({
|
|
228
|
-
Name: propertyKey,
|
|
229
|
-
Model: Reflect.getMetadata('design:type', target, propertyKey),
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
exports.JunctionTable = JunctionTable;
|
|
234
|
-
/**
|
|
235
|
-
*
|
|
236
|
-
* Marks model to have discrimination map.
|
|
237
|
-
*
|
|
238
|
-
* @param fieldName - db field name to look for
|
|
239
|
-
* @param discriminationMap - field - model mapping
|
|
240
|
-
*/
|
|
241
|
-
function DiscriminationMap(fieldName, discriminationMap) {
|
|
242
|
-
return extractDecoratorDescriptor((model, _target, _propertyKey) => {
|
|
243
|
-
model.DiscriminationMap.Field = fieldName;
|
|
244
|
-
model.DiscriminationMap.Models = new Map();
|
|
245
|
-
discriminationMap.forEach((d) => {
|
|
246
|
-
model.DiscriminationMap.Models.set(d.Key, d.Value);
|
|
247
|
-
});
|
|
248
|
-
}, true);
|
|
249
|
-
}
|
|
250
|
-
exports.DiscriminationMap = DiscriminationMap;
|
|
251
|
-
/**
|
|
252
|
-
* Marks relation as recursive. When relation is populated it loads all to the top
|
|
253
|
-
*
|
|
254
|
-
*/
|
|
255
|
-
function Recursive() {
|
|
256
|
-
return extractDecoratorDescriptor((model, _target, propertyKey) => {
|
|
257
|
-
if (!model.Relations.has(propertyKey)) {
|
|
258
|
-
throw new exceptions_1.InvalidOperation(`cannot set recursive on not existing relation ( relation ${propertyKey} on model ${model.Name} )`);
|
|
259
|
-
}
|
|
260
|
-
const relation = model.Relations.get(propertyKey);
|
|
261
|
-
if (relation.Type !== interfaces_2.RelationType.One) {
|
|
262
|
-
throw new exceptions_1.InvalidOperation(`cannot set recursive on non one-to-one relation ( relation ${propertyKey} on model ${model.Name} )`);
|
|
263
|
-
}
|
|
264
|
-
relation.Recursive = true;
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
exports.Recursive = Recursive;
|
|
268
|
-
const forwardRef = (fn) => ({
|
|
269
|
-
forwardRef: fn,
|
|
270
|
-
});
|
|
271
|
-
exports.forwardRef = forwardRef;
|
|
272
|
-
/**
|
|
273
|
-
* Creates one to one relation with target model.
|
|
274
|
-
*
|
|
275
|
-
* @param foreignKey - foreign key name in db, defaults to lowercase property name with _id suffix eg. owner_id
|
|
276
|
-
* @param primaryKey - primary key in related model, defaults to primary key taken from db
|
|
277
|
-
*/
|
|
278
|
-
function BelongsTo(targetModel, foreignKey, primaryKey) {
|
|
279
|
-
return extractDecoratorDescriptor((model, target, propertyKey) => {
|
|
280
|
-
model.Relations.set(propertyKey, {
|
|
281
|
-
Name: propertyKey,
|
|
282
|
-
Type: interfaces_2.RelationType.One,
|
|
283
|
-
SourceModel: target.constructor,
|
|
284
|
-
TargetModelType: targetModel,
|
|
285
|
-
TargetModel: null,
|
|
286
|
-
ForeignKey: foreignKey !== null && foreignKey !== void 0 ? foreignKey : `${propertyKey.toLowerCase()}_id`,
|
|
287
|
-
PrimaryKey: primaryKey !== null && primaryKey !== void 0 ? primaryKey : model.PrimaryKey,
|
|
288
|
-
Recursive: false,
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
exports.BelongsTo = BelongsTo;
|
|
293
|
-
/**
|
|
294
|
-
* Creates one to one relation with target model.
|
|
295
|
-
*
|
|
296
|
-
* @param foreignKey - foreign key name in db, defaults to lowercase property name with _id suffix eg. owner_id
|
|
297
|
-
* @param primaryKey - primary key in related model, defaults to primary key taken from db
|
|
298
|
-
*/
|
|
299
|
-
function ForwardBelongsTo(forwardRef, foreignKey, primaryKey) {
|
|
300
|
-
return extractDecoratorDescriptor((model, target, propertyKey) => {
|
|
301
|
-
model.Relations.set(propertyKey, {
|
|
302
|
-
Name: propertyKey,
|
|
303
|
-
Type: interfaces_2.RelationType.One,
|
|
304
|
-
SourceModel: target.constructor,
|
|
305
|
-
TargetModelType: forwardRef.forwardRef,
|
|
306
|
-
TargetModel: null,
|
|
307
|
-
ForeignKey: foreignKey !== null && foreignKey !== void 0 ? foreignKey : `${propertyKey.toLowerCase()}_id`,
|
|
308
|
-
PrimaryKey: primaryKey !== null && primaryKey !== void 0 ? primaryKey : model.PrimaryKey,
|
|
309
|
-
Recursive: false,
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
exports.ForwardBelongsTo = ForwardBelongsTo;
|
|
314
|
-
/**
|
|
315
|
-
* Creates one to many relation with target model.
|
|
316
|
-
*
|
|
317
|
-
* @param targetModel - due to limitations of metadata reflection api in typescript target model mus be set explicitly
|
|
318
|
-
* @param foreignKey - foreign key name in db, defaults to lowercase property name with _id suffix eg. owner_id
|
|
319
|
-
* @param primaryKey - primary key in source table defaults to lowercase property name with _id suffix eg. owner_id
|
|
320
|
-
*
|
|
321
|
-
*/
|
|
322
|
-
function HasMany(targetModel, options) {
|
|
323
|
-
return extractDecoratorDescriptor((model, target, propertyKey) => {
|
|
324
|
-
var _a, _b;
|
|
325
|
-
model.Relations.set(propertyKey, {
|
|
326
|
-
Name: propertyKey,
|
|
327
|
-
Type: interfaces_2.RelationType.Many,
|
|
328
|
-
SourceModel: target.constructor,
|
|
329
|
-
TargetModelType: targetModel,
|
|
330
|
-
TargetModel: null,
|
|
331
|
-
ForeignKey: options ? (_a = options.foreignKey) !== null && _a !== void 0 ? _a : `${model.Name.toLowerCase()}_id` : `${model.Name.toLowerCase()}_id`,
|
|
332
|
-
PrimaryKey: options ? (_b = options.primaryKey) !== null && _b !== void 0 ? _b : model.PrimaryKey : model.PrimaryKey,
|
|
333
|
-
Recursive: false,
|
|
334
|
-
Factory: options ? options.factory : null,
|
|
335
|
-
RelationClass: options ? options.type : null,
|
|
336
|
-
});
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
exports.HasMany = HasMany;
|
|
340
|
-
function Historical(targetModel) {
|
|
341
|
-
return extractDecoratorDescriptor((model, target, propertyKey) => {
|
|
342
|
-
model.Relations.set(propertyKey, {
|
|
343
|
-
Name: propertyKey,
|
|
344
|
-
Type: interfaces_2.RelationType.Many,
|
|
345
|
-
SourceModel: target.constructor,
|
|
346
|
-
TargetModelType: targetModel,
|
|
347
|
-
TargetModel: null,
|
|
348
|
-
ForeignKey: model.PrimaryKey,
|
|
349
|
-
PrimaryKey: model.PrimaryKey,
|
|
350
|
-
Recursive: false,
|
|
351
|
-
});
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
exports.Historical = Historical;
|
|
355
|
-
/**
|
|
356
|
-
* Creates many to many relation with separate join table
|
|
357
|
-
*
|
|
358
|
-
* @param junctionModel - model for junction table
|
|
359
|
-
* @param targetModel - model for related data
|
|
360
|
-
* @param targetModelPKey - target model primary key name
|
|
361
|
-
* @param sourceModelPKey - source model primary key name
|
|
362
|
-
* @param junctionModelTargetPk - junction table target primary key name ( foreign key for target model )
|
|
363
|
-
* @param junctionModelSourcePk - junction table source primary key name ( foreign key for source model )
|
|
364
|
-
*/
|
|
365
|
-
function HasManyToMany(junctionModel, targetModel, targetModelPKey, sourceModelPKey, junctionModelTargetPk, junctionModelSourcePk) {
|
|
366
|
-
return extractDecoratorDescriptor((model, target, propertyKey) => {
|
|
367
|
-
const targetModelDescriptor = (0, model_1.extractModelDescriptor)(targetModel);
|
|
368
|
-
model.Relations.set(propertyKey, {
|
|
369
|
-
Name: propertyKey,
|
|
370
|
-
Recursive: false,
|
|
371
|
-
Type: interfaces_2.RelationType.ManyToMany,
|
|
372
|
-
SourceModel: target.constructor,
|
|
373
|
-
TargetModelType: targetModel,
|
|
374
|
-
TargetModel: null,
|
|
375
|
-
ForeignKey: targetModelPKey !== null && targetModelPKey !== void 0 ? targetModelPKey : targetModelDescriptor.PrimaryKey,
|
|
376
|
-
PrimaryKey: sourceModelPKey !== null && sourceModelPKey !== void 0 ? sourceModelPKey : model.PrimaryKey,
|
|
377
|
-
JunctionModel: junctionModel,
|
|
378
|
-
JunctionModelTargetModelFKey_Name: junctionModelTargetPk !== null && junctionModelTargetPk !== void 0 ? junctionModelTargetPk : `${targetModelDescriptor.Name.toLowerCase()}_id`,
|
|
379
|
-
JunctionModelSourceModelFKey_Name: junctionModelSourcePk !== null && junctionModelSourcePk !== void 0 ? junctionModelSourcePk : `${model.Name.toLowerCase()}_id`,
|
|
380
|
-
});
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
exports.HasManyToMany = HasManyToMany;
|
|
384
|
-
/**
|
|
385
|
-
* Mark field as datetime type. It will ensure that conversion to & from DB is valid, eg. sqlite DB
|
|
386
|
-
* saves datetime as TEXT and ISO8601 strings
|
|
387
|
-
*/
|
|
388
|
-
function DateTime() {
|
|
389
|
-
return extractDecoratorDescriptor((model, target, propertyKey) => {
|
|
390
|
-
const type = Reflect.getMetadata('design:type', target, propertyKey);
|
|
391
|
-
if (type.name !== 'DateTime') {
|
|
392
|
-
throw Error(`Proprety ${propertyKey} must be DateTime type`);
|
|
393
|
-
}
|
|
394
|
-
if (model.Converters.has(propertyKey)) {
|
|
395
|
-
throw new exceptions_1.InvalidArgument(`property ${propertyKey} already have data converter attached`);
|
|
396
|
-
}
|
|
397
|
-
model.Converters.set(propertyKey, {
|
|
398
|
-
Class: interfaces_2.DatetimeValueConverter,
|
|
399
|
-
});
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
exports.DateTime = DateTime;
|
|
403
|
-
/**
|
|
404
|
-
* Converts data in db to json object. Column type in DB should be STRING.
|
|
405
|
-
* DO not use this decorator for use of native DB JSON implementation.
|
|
406
|
-
* ORM will detect automatically if field is native JSON DB type.
|
|
407
|
-
*/
|
|
408
|
-
function Json() {
|
|
409
|
-
return extractDecoratorDescriptor((model, _, propertyKey) => {
|
|
410
|
-
// add converter for this field
|
|
411
|
-
model.Converters.set(propertyKey, {
|
|
412
|
-
Class: interfaces_1.JsonValueConverter,
|
|
413
|
-
});
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
exports.Json = Json;
|
|
417
|
-
/**
|
|
418
|
-
*
|
|
419
|
-
* Universal converter that guess whitch type to return. Usefull in tables that holds as text different values
|
|
420
|
-
* eg. metadata table
|
|
421
|
-
*
|
|
422
|
-
* @param typeColumn - type column that defines final type of value
|
|
423
|
-
*/
|
|
424
|
-
function UniversalConverter(typeColumn) {
|
|
425
|
-
return extractDecoratorDescriptor((model, _, propertyKey) => {
|
|
426
|
-
// add converter for this field
|
|
427
|
-
model.Converters.set(propertyKey, {
|
|
428
|
-
Class: interfaces_1.JsonValueConverter,
|
|
429
|
-
Options: {
|
|
430
|
-
TypeColumn: typeColumn,
|
|
431
|
-
},
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
exports.UniversalConverter = UniversalConverter;
|
|
436
|
-
/**
|
|
437
|
-
* Mark field as SET type. It will ensure that conversion to & from DB is valid, eg. to emulate field type SET in sqlite
|
|
438
|
-
*/
|
|
439
|
-
function Set() {
|
|
440
|
-
return extractDecoratorDescriptor((model, target, propertyKey) => {
|
|
441
|
-
const type = Reflect.getMetadata('design:type', target, propertyKey);
|
|
442
|
-
if (type.name !== 'Array') {
|
|
443
|
-
throw Error(`Proprety ${propertyKey} must be an array type`);
|
|
444
|
-
}
|
|
445
|
-
if (model.Converters.has(propertyKey)) {
|
|
446
|
-
throw new exceptions_1.InvalidArgument(`property ${propertyKey} already have data converter attached`);
|
|
447
|
-
}
|
|
448
|
-
model.Converters.set(propertyKey, {
|
|
449
|
-
Class: interfaces_2.SetValueConverter,
|
|
450
|
-
});
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
exports.Set = Set;
|
|
454
|
-
//# sourceMappingURL=decorators.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../orm/src/decorators.ts"],"names":[],"mappings":";;;AAAA,6CAA6E;AAC7E,sCAAsC;AACtC,6CAA6C;AAC7C,oCAA0D;AAC1D,6CAA0K;AAC1K,4BAA0B;AAC1B,mCAA4D;AAC5D,oDAAwE;AAG3D,QAAA,yBAAyB,GAAG,MAAM,CAAC,G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,MAAM,KAAK,CAAC,aAAa,WAAW,wBAAwB,CAAC,CAAC;SAC/D;QAED,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;YACrC,MAAM,IAAI,4BAAe,CAAC,YAAY,WAAW,uCAAuC,CAAC,CAAC;SAC3F;QAED,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,WAAW,EAAE;YAChC,KAAK,EAAE,8BAAiB;SACzB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAfD,kBAeC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ModelBase } from './model';
|
|
2
|
-
export declare abstract class ModelDehydrator {
|
|
3
|
-
abstract dehydrate(model: ModelBase, omit?: string[]): any;
|
|
4
|
-
}
|
|
5
|
-
export declare class StandardModelDehydrator extends ModelDehydrator {
|
|
6
|
-
dehydrate(model: ModelBase, omit?: string[]): {};
|
|
7
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StandardModelDehydrator = exports.ModelDehydrator = void 0;
|
|
4
|
-
const exceptions_1 = require("./exceptions");
|
|
5
|
-
const interfaces_1 = require("./interfaces");
|
|
6
|
-
class ModelDehydrator {
|
|
7
|
-
}
|
|
8
|
-
exports.ModelDehydrator = ModelDehydrator;
|
|
9
|
-
class StandardModelDehydrator extends ModelDehydrator {
|
|
10
|
-
dehydrate(model, omit) {
|
|
11
|
-
var _a;
|
|
12
|
-
const obj = {};
|
|
13
|
-
const relArr = [...model.ModelDescriptor.Relations.values()];
|
|
14
|
-
(_a = model.ModelDescriptor.Columns) === null || _a === void 0 ? void 0 : _a.forEach((c) => {
|
|
15
|
-
// if in omit list OR it is foreign key for relation - skip
|
|
16
|
-
if ((omit && omit.indexOf(c.Name) !== -1) || relArr.find((r) => r.ForeignKey === c.Name)) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const val = model[c.Name];
|
|
20
|
-
if (!c.PrimaryKey && !c.Nullable && (val === null || val === undefined || val === '')) {
|
|
21
|
-
throw new exceptions_1.OrmException(`Field ${c.Name} cannot be null`);
|
|
22
|
-
}
|
|
23
|
-
obj[c.Name] = c.Converter ? c.Converter.toDB(val, model, null) : val;
|
|
24
|
-
});
|
|
25
|
-
for (const val of relArr) {
|
|
26
|
-
if (val.Type === interfaces_1.RelationType.One) {
|
|
27
|
-
if (model[val.Name].Value) {
|
|
28
|
-
obj[val.Name] = model[val.Name].Value.dehydrate();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (val.Type === interfaces_1.RelationType.Many) {
|
|
32
|
-
if (model[val.Name]) {
|
|
33
|
-
obj[val.Name] = [...model[val.Name].map((x) => x.dehydrate())];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return obj;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.StandardModelDehydrator = StandardModelDehydrator;
|
|
41
|
-
//# sourceMappingURL=dehydrators.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dehydrators.js","sourceRoot":"","sources":["../../../../orm/src/dehydrators.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAC5C,6CAA4C;AAI5C,MAAsB,eAAe;CAEpC;AAFD,0CAEC;AAED,MAAa,uBAAwB,SAAQ,eAAe;IACnD,SAAS,CAAC,KAAgB,EAAE,IAAe;;QAChD,MAAM,GAAG,GAAG,EAAE,CAAC;QACf,MAAM,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,eAAe,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;QAC7D,MAAA,KAAK,CAAC,eAAe,CAAC,OAAO,0CAAE,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YAC3C,2DAA2D;YAC3D,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAA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AAE,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;iBAChH;aACF;SACF;QAED,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AAjCD,0DAiCC"}
|
package/lib/orm/src/driver.d.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { Log } from '@spinajs/log';
|
|
2
|
-
import { IColumnDescriptor, IDriverOptions, QueryContext } from './interfaces';
|
|
3
|
-
import { SyncService, IContainer, Container } from '@spinajs/di';
|
|
4
|
-
import { UpdateQueryBuilder, SelectQueryBuilder, IndexQueryBuilder, DeleteQueryBuilder, InsertQueryBuilder, SchemaQueryBuilder, QueryBuilder, TruncateTableQueryBuilder } from './builders';
|
|
5
|
-
export declare type TransactionCallback = (driver: OrmDriver) => Promise<any>;
|
|
6
|
-
export declare abstract class OrmDriver extends SyncService {
|
|
7
|
-
/**
|
|
8
|
-
* Connection options
|
|
9
|
-
*/
|
|
10
|
-
Options: IDriverOptions;
|
|
11
|
-
Container: IContainer;
|
|
12
|
-
protected RootContainer: Container;
|
|
13
|
-
protected Log: Log;
|
|
14
|
-
constructor(options: IDriverOptions);
|
|
15
|
-
/**
|
|
16
|
-
* Executes query on database
|
|
17
|
-
*
|
|
18
|
-
* @param stmt - query string or query objects that is executed in database
|
|
19
|
-
* @param params - binding parameters
|
|
20
|
-
* @param context - query context to optimize queries sent to DB
|
|
21
|
-
*/
|
|
22
|
-
abstract execute(stmt: string | object, params: any[], context: QueryContext): Promise<any[] | any>;
|
|
23
|
-
/**
|
|
24
|
-
* Checks if database is avaible
|
|
25
|
-
* @returns false if cannot reach database
|
|
26
|
-
*/
|
|
27
|
-
abstract ping(): Promise<boolean>;
|
|
28
|
-
/**
|
|
29
|
-
* Connects to database
|
|
30
|
-
* @throws OrmException if can't connec to to database
|
|
31
|
-
*/
|
|
32
|
-
abstract connect(): Promise<OrmDriver>;
|
|
33
|
-
/**
|
|
34
|
-
* Disconnects from database
|
|
35
|
-
*/
|
|
36
|
-
abstract disconnect(): Promise<OrmDriver>;
|
|
37
|
-
abstract tableInfo(name: string, schema?: string): Promise<IColumnDescriptor[]>;
|
|
38
|
-
resolve(): void;
|
|
39
|
-
/**
|
|
40
|
-
* Creates select query builder associated with this connection.
|
|
41
|
-
* This can be used to execute raw queries to db without orm model layer
|
|
42
|
-
*/
|
|
43
|
-
select<T>(): SelectQueryBuilder<T>;
|
|
44
|
-
/**
|
|
45
|
-
* Creates delete query builder associated with this connection.
|
|
46
|
-
* This can be used to execute raw queries to db without orm model layer
|
|
47
|
-
*/
|
|
48
|
-
del<T>(): DeleteQueryBuilder<T>;
|
|
49
|
-
/**
|
|
50
|
-
* Creates insert query builder associated with this connection.
|
|
51
|
-
* This can be used to execute raw queries to db without orm model layer
|
|
52
|
-
*/
|
|
53
|
-
insert(): InsertQueryBuilder;
|
|
54
|
-
/**
|
|
55
|
-
* Truncates given table
|
|
56
|
-
*/
|
|
57
|
-
truncate(table: string): TruncateTableQueryBuilder;
|
|
58
|
-
/**
|
|
59
|
-
* Creates update query builder associated with this connection.
|
|
60
|
-
* This can be used to execute raw queries to db without orm model layer
|
|
61
|
-
*/
|
|
62
|
-
update<T>(): UpdateQueryBuilder<T>;
|
|
63
|
-
/**
|
|
64
|
-
* Creates schema query builder associated with this connection.
|
|
65
|
-
* This can be use to modify database structure
|
|
66
|
-
*/
|
|
67
|
-
schema(): SchemaQueryBuilder;
|
|
68
|
-
/**
|
|
69
|
-
* Creates index query builder associated with this connection.
|
|
70
|
-
* This can be use to create table indexes
|
|
71
|
-
*/
|
|
72
|
-
index(): IndexQueryBuilder;
|
|
73
|
-
/**
|
|
74
|
-
* Executes all queries in transaction
|
|
75
|
-
*
|
|
76
|
-
* @param queryOrCallback - one or more queries to execute in transaction scope. If parameter is function
|
|
77
|
-
* its executed in transaction scope, thus all db operation in callback function are in transaction
|
|
78
|
-
*/
|
|
79
|
-
abstract transaction(queryOrCallback?: QueryBuilder[] | TransactionCallback): Promise<void>;
|
|
80
|
-
}
|