@sqb/connect 4.0.7 → 4.0.10
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/package.json +6 -7
- package/dist/client/Adapter.d.ts +0 -57
- package/dist/client/Adapter.js +0 -2
- package/dist/client/Cursor.d.ts +0 -116
- package/dist/client/Cursor.js +0 -250
- package/dist/client/CursorStream.d.ts +0 -29
- package/dist/client/CursorStream.js +0 -98
- package/dist/client/FieldInfoMap.d.ts +0 -10
- package/dist/client/FieldInfoMap.js +0 -33
- package/dist/client/SqbClient.d.ts +0 -70
- package/dist/client/SqbClient.js +0 -165
- package/dist/client/SqbConnection.d.ts +0 -74
- package/dist/client/SqbConnection.js +0 -272
- package/dist/client/extensions.d.ts +0 -4
- package/dist/client/extensions.js +0 -14
- package/dist/client/helpers.d.ts +0 -9
- package/dist/client/helpers.js +0 -133
- package/dist/client/types.d.ts +0 -189
- package/dist/client/types.js +0 -5
- package/dist/index.d.ts +0 -28
- package/dist/index.js +0 -37
- package/dist/orm/base-entity.class.d.ts +0 -16
- package/dist/orm/base-entity.class.js +0 -56
- package/dist/orm/commands/command.helper.d.ts +0 -14
- package/dist/orm/commands/command.helper.js +0 -140
- package/dist/orm/commands/count.command.d.ts +0 -11
- package/dist/orm/commands/count.command.js +0 -30
- package/dist/orm/commands/create.command.d.ts +0 -20
- package/dist/orm/commands/create.command.js +0 -83
- package/dist/orm/commands/destroy.command.d.ts +0 -11
- package/dist/orm/commands/destroy.command.js +0 -30
- package/dist/orm/commands/find.command.d.ts +0 -44
- package/dist/orm/commands/find.command.js +0 -308
- package/dist/orm/commands/row-converter.d.ts +0 -55
- package/dist/orm/commands/row-converter.js +0 -187
- package/dist/orm/commands/update.command.d.ts +0 -22
- package/dist/orm/commands/update.command.js +0 -82
- package/dist/orm/decorators/column.decorator.d.ts +0 -4
- package/dist/orm/decorators/column.decorator.js +0 -14
- package/dist/orm/decorators/embedded.decorator.d.ts +0 -2
- package/dist/orm/decorators/embedded.decorator.js +0 -17
- package/dist/orm/decorators/entity.decorator.d.ts +0 -6
- package/dist/orm/decorators/entity.decorator.js +0 -23
- package/dist/orm/decorators/events.decorator.d.ts +0 -6
- package/dist/orm/decorators/events.decorator.js +0 -76
- package/dist/orm/decorators/foreignkey.decorator.d.ts +0 -2
- package/dist/orm/decorators/foreignkey.decorator.js +0 -13
- package/dist/orm/decorators/index.decorator.d.ts +0 -3
- package/dist/orm/decorators/index.decorator.js +0 -22
- package/dist/orm/decorators/link.decorator.d.ts +0 -23
- package/dist/orm/decorators/link.decorator.js +0 -88
- package/dist/orm/decorators/primarykey.decorator.d.ts +0 -3
- package/dist/orm/decorators/primarykey.decorator.js +0 -23
- package/dist/orm/decorators/transform.decorator.d.ts +0 -3
- package/dist/orm/decorators/transform.decorator.js +0 -24
- package/dist/orm/model/abstract-entityelement.d.ts +0 -8
- package/dist/orm/model/abstract-entityelement.js +0 -10
- package/dist/orm/model/association-node.d.ts +0 -9
- package/dist/orm/model/association-node.js +0 -25
- package/dist/orm/model/association.d.ts +0 -28
- package/dist/orm/model/association.js +0 -129
- package/dist/orm/model/entity-association-element.d.ts +0 -9
- package/dist/orm/model/entity-association-element.js +0 -13
- package/dist/orm/model/entity-column-element.d.ts +0 -68
- package/dist/orm/model/entity-column-element.js +0 -27
- package/dist/orm/model/entity-model.d.ts +0 -59
- package/dist/orm/model/entity-model.js +0 -295
- package/dist/orm/model/entity-object-element.d.ts +0 -12
- package/dist/orm/model/entity-object-element.js +0 -24
- package/dist/orm/model/index-meta.d.ts +0 -9
- package/dist/orm/model/index-meta.js +0 -16
- package/dist/orm/model/link-chain.d.ts +0 -15
- package/dist/orm/model/link-chain.js +0 -50
- package/dist/orm/orm.const.d.ts +0 -2
- package/dist/orm/orm.const.js +0 -5
- package/dist/orm/orm.type.d.ts +0 -112
- package/dist/orm/orm.type.js +0 -2
- package/dist/orm/repository.class.d.ts +0 -125
- package/dist/orm/repository.class.js +0 -217
- package/dist/orm/util/entity-mapping.d.ts +0 -12
- package/dist/orm/util/entity-mapping.js +0 -154
- package/dist/orm/util/extract-keyvalues.d.ts +0 -2
- package/dist/orm/util/extract-keyvalues.js +0 -60
- package/dist/orm/util/orm.helper.d.ts +0 -14
- package/dist/orm/util/orm.helper.js +0 -39
- package/dist/orm/util/serialize-element.d.ts +0 -2
- package/dist/orm/util/serialize-element.js +0 -43
- package/dist/types.d.ts +0 -2
- package/dist/types.js +0 -2
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EntityModel = void 0;
|
|
4
|
-
const builder_1 = require("@sqb/builder");
|
|
5
|
-
const orm_const_1 = require("../orm.const");
|
|
6
|
-
const index_meta_1 = require("./index-meta");
|
|
7
|
-
const association_1 = require("./association");
|
|
8
|
-
const entity_column_element_1 = require("./entity-column-element");
|
|
9
|
-
const entity_object_element_1 = require("./entity-object-element");
|
|
10
|
-
const entity_association_element_1 = require("./entity-association-element");
|
|
11
|
-
const serialize_element_1 = require("../util/serialize-element");
|
|
12
|
-
const orm_helper_1 = require("../util/orm.helper");
|
|
13
|
-
class EntityModel {
|
|
14
|
-
constructor(ctor) {
|
|
15
|
-
this.ctor = ctor;
|
|
16
|
-
this.elements = new Map();
|
|
17
|
-
this.indexes = [];
|
|
18
|
-
this.foreignKeys = [];
|
|
19
|
-
this.eventListeners = [];
|
|
20
|
-
this.name = ctor.name;
|
|
21
|
-
}
|
|
22
|
-
get elementKeys() {
|
|
23
|
-
if (!(this._elementKeys && this.hasOwnProperty('_elementKeys')))
|
|
24
|
-
this._elementKeys = Array.from(this.elements.keys());
|
|
25
|
-
return this._elementKeys;
|
|
26
|
-
}
|
|
27
|
-
getElement(name) {
|
|
28
|
-
if (!name)
|
|
29
|
-
return;
|
|
30
|
-
return this.elements.get(name.toLowerCase());
|
|
31
|
-
}
|
|
32
|
-
getColumnElement(name) {
|
|
33
|
-
if (!name)
|
|
34
|
-
return;
|
|
35
|
-
const prop = this.elements.get(name.toLowerCase());
|
|
36
|
-
return (0, orm_helper_1.isColumnElement)(prop) ? prop : undefined;
|
|
37
|
-
}
|
|
38
|
-
getColumnElementByFieldName(fieldName) {
|
|
39
|
-
if (!fieldName)
|
|
40
|
-
return;
|
|
41
|
-
fieldName = fieldName.toLowerCase();
|
|
42
|
-
for (const prop of this.elements.values()) {
|
|
43
|
-
if ((0, orm_helper_1.isColumnElement)(prop) && prop.fieldName.toLowerCase() === fieldName)
|
|
44
|
-
return prop;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
getObjectElement(name) {
|
|
48
|
-
if (!name)
|
|
49
|
-
return;
|
|
50
|
-
const col = this.elements.get(name.toLowerCase());
|
|
51
|
-
return (0, orm_helper_1.isObjectElement)(col) ? col : undefined;
|
|
52
|
-
}
|
|
53
|
-
getAssociationElement(name) {
|
|
54
|
-
if (!name)
|
|
55
|
-
return;
|
|
56
|
-
const col = this.elements.get(name.toLowerCase());
|
|
57
|
-
return (0, orm_helper_1.isAssociationElement)(col) ? col : undefined;
|
|
58
|
-
}
|
|
59
|
-
defineColumnElement(propertyKey, options) {
|
|
60
|
-
let prop = this.getElement(propertyKey);
|
|
61
|
-
if (!prop || !(0, orm_helper_1.isColumnElement)(prop)) {
|
|
62
|
-
prop = new entity_column_element_1.EntityColumnElement(this, propertyKey, options);
|
|
63
|
-
if (!prop.type) {
|
|
64
|
-
const typ = Reflect.getMetadata("design:type", this.ctor.prototype, propertyKey);
|
|
65
|
-
if (typ === Array) {
|
|
66
|
-
prop.type = String;
|
|
67
|
-
prop.isArray = true;
|
|
68
|
-
}
|
|
69
|
-
else
|
|
70
|
-
prop.type = typ;
|
|
71
|
-
}
|
|
72
|
-
if (!prop.dataType) {
|
|
73
|
-
if (prop.type === Boolean)
|
|
74
|
-
prop.dataType = builder_1.DataType.BOOL;
|
|
75
|
-
else if (prop.type === String)
|
|
76
|
-
prop.dataType = builder_1.DataType.VARCHAR;
|
|
77
|
-
else if (prop.type === Number)
|
|
78
|
-
prop.dataType = builder_1.DataType.NUMBER;
|
|
79
|
-
else if (prop.type === Date)
|
|
80
|
-
prop.dataType = builder_1.DataType.TIMESTAMP;
|
|
81
|
-
else if (prop.type === Array) {
|
|
82
|
-
prop.dataType = builder_1.DataType.VARCHAR;
|
|
83
|
-
prop.isArray = true;
|
|
84
|
-
}
|
|
85
|
-
else if (prop.type === Buffer)
|
|
86
|
-
prop.dataType = builder_1.DataType.BINARY;
|
|
87
|
-
}
|
|
88
|
-
if (options?.isArray)
|
|
89
|
-
prop.isArray = true;
|
|
90
|
-
if (!this.elements.has(propertyKey.toLowerCase()))
|
|
91
|
-
this.elementKeys.push(propertyKey);
|
|
92
|
-
this.elements.set(propertyKey.toLowerCase(), prop);
|
|
93
|
-
}
|
|
94
|
-
else if (options)
|
|
95
|
-
prop.assign(options);
|
|
96
|
-
return prop;
|
|
97
|
-
}
|
|
98
|
-
defineAssociationElement(propertyKey, association) {
|
|
99
|
-
const prop = new entity_association_element_1.EntityAssociationElement(this, propertyKey, association);
|
|
100
|
-
let l = association;
|
|
101
|
-
let i = 1;
|
|
102
|
-
while (l) {
|
|
103
|
-
l.name = this.name + '.' + propertyKey + '#' + (i++);
|
|
104
|
-
l = l.next;
|
|
105
|
-
}
|
|
106
|
-
if (!this.elements.has(propertyKey.toLowerCase()))
|
|
107
|
-
this.elementKeys.push(propertyKey);
|
|
108
|
-
this.elements.set(propertyKey.toLowerCase(), prop);
|
|
109
|
-
return prop;
|
|
110
|
-
}
|
|
111
|
-
defineObjectElement(propertyKey, type) {
|
|
112
|
-
type = type || Reflect.getMetadata("design:type", this.ctor.prototype, propertyKey);
|
|
113
|
-
if (typeof type !== 'function')
|
|
114
|
-
throw new Error('"type" must be defined');
|
|
115
|
-
let prop = this.getElement(propertyKey);
|
|
116
|
-
if (!prop || !(0, orm_helper_1.isObjectElement)(prop)) {
|
|
117
|
-
prop = new entity_object_element_1.EntityObjectElement(this, propertyKey, type);
|
|
118
|
-
if (!this.elements.has(propertyKey.toLowerCase()))
|
|
119
|
-
this.elementKeys.push(propertyKey);
|
|
120
|
-
this.elements.set(propertyKey.toLowerCase(), prop);
|
|
121
|
-
}
|
|
122
|
-
return prop;
|
|
123
|
-
}
|
|
124
|
-
setPrimaryIndex(column, options) {
|
|
125
|
-
this.primaryIndex = new index_meta_1.IndexMeta(this, column, options);
|
|
126
|
-
this.primaryIndex.unique = true;
|
|
127
|
-
}
|
|
128
|
-
addIndex(column, options) {
|
|
129
|
-
this.indexes.push(new index_meta_1.IndexMeta(this, column, options));
|
|
130
|
-
}
|
|
131
|
-
addForeignKey(propertyKey, target, targetKey) {
|
|
132
|
-
const fk = new association_1.Association(this.name + '.' + propertyKey, {
|
|
133
|
-
source: this.ctor,
|
|
134
|
-
sourceKey: propertyKey,
|
|
135
|
-
target,
|
|
136
|
-
targetKey
|
|
137
|
-
});
|
|
138
|
-
this.foreignKeys.push(fk);
|
|
139
|
-
}
|
|
140
|
-
before(event, fn) {
|
|
141
|
-
this.eventListeners.push({ event: 'before-' + event, fn });
|
|
142
|
-
}
|
|
143
|
-
after(event, fn) {
|
|
144
|
-
this.eventListeners.push({ event: 'after-' + event, fn });
|
|
145
|
-
}
|
|
146
|
-
getPrimaryIndexColumns() {
|
|
147
|
-
const out = [];
|
|
148
|
-
if (this.primaryIndex) {
|
|
149
|
-
for (const k of this.primaryIndex.columns) {
|
|
150
|
-
const col = this.getColumnElement(k);
|
|
151
|
-
if (!col)
|
|
152
|
-
throw new Error(`Data column "${k}" in primary index of ${this.name} does not exists`);
|
|
153
|
-
out.push(col);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return out;
|
|
157
|
-
}
|
|
158
|
-
getElementNames(fn) {
|
|
159
|
-
const out = [];
|
|
160
|
-
for (const k of this.elementKeys) {
|
|
161
|
-
const el = this.getElement(k);
|
|
162
|
-
if (el && (!fn || fn(el)))
|
|
163
|
-
out.push(k);
|
|
164
|
-
}
|
|
165
|
-
return out;
|
|
166
|
-
}
|
|
167
|
-
getColumnNames() {
|
|
168
|
-
return this.getElementNames(orm_helper_1.isColumnElement);
|
|
169
|
-
}
|
|
170
|
-
getObjectElementNames() {
|
|
171
|
-
return this.getElementNames(orm_helper_1.isObjectElement);
|
|
172
|
-
}
|
|
173
|
-
getAssociationElementNames() {
|
|
174
|
-
return this.getElementNames(orm_helper_1.isAssociationElement);
|
|
175
|
-
}
|
|
176
|
-
getNonAssociationElementNames() {
|
|
177
|
-
return this.getElementNames(x => !(0, orm_helper_1.isAssociationElement)(x));
|
|
178
|
-
}
|
|
179
|
-
getInsertColumnNames() {
|
|
180
|
-
const out = [];
|
|
181
|
-
for (const k of this.elementKeys) {
|
|
182
|
-
const col = this.getElement(k);
|
|
183
|
-
if ((0, orm_helper_1.isColumnElement)(col) && !col.noInsert)
|
|
184
|
-
out.push(k);
|
|
185
|
-
}
|
|
186
|
-
return out;
|
|
187
|
-
}
|
|
188
|
-
getUpdateColumnNames() {
|
|
189
|
-
const out = [];
|
|
190
|
-
for (const k of this.elementKeys) {
|
|
191
|
-
const col = this.getElement(k);
|
|
192
|
-
if ((0, orm_helper_1.isColumnElement)(col) && !col.noUpdate)
|
|
193
|
-
out.push(k);
|
|
194
|
-
}
|
|
195
|
-
return out;
|
|
196
|
-
}
|
|
197
|
-
async getForeignKeyFor(t) {
|
|
198
|
-
for (const f of this.foreignKeys) {
|
|
199
|
-
if (await f.resolveTarget() === t)
|
|
200
|
-
return f;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
static get(ctor) {
|
|
204
|
-
return ctor[orm_const_1.ENTITY_DEFINITION_KEY];
|
|
205
|
-
}
|
|
206
|
-
static hasOwn(ctor) {
|
|
207
|
-
return ctor.hasOwnProperty(orm_const_1.ENTITY_DEFINITION_KEY);
|
|
208
|
-
}
|
|
209
|
-
static attachTo(ctor) {
|
|
210
|
-
const own = this.hasOwn(ctor) ? this.get(ctor) : undefined;
|
|
211
|
-
if (own)
|
|
212
|
-
return own;
|
|
213
|
-
const current = this.get(ctor);
|
|
214
|
-
const entity = new EntityModel(ctor);
|
|
215
|
-
Object.defineProperty(ctor, orm_const_1.ENTITY_DEFINITION_KEY, {
|
|
216
|
-
value: entity,
|
|
217
|
-
enumerable: false
|
|
218
|
-
});
|
|
219
|
-
// Merge base entity columns into this one
|
|
220
|
-
if (current) {
|
|
221
|
-
entity.tableName = current.tableName;
|
|
222
|
-
for (const k of current.elementKeys) {
|
|
223
|
-
const col = current.elements.get(k.toLowerCase());
|
|
224
|
-
if (col) {
|
|
225
|
-
entity.elementKeys.push(k);
|
|
226
|
-
entity.elements.set(k.toLowerCase(), col);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
for (const fk of current.foreignKeys) {
|
|
230
|
-
const newFk = new association_1.Association(fk.name, { ...fk, source: ctor });
|
|
231
|
-
entity.foreignKeys.push(newFk);
|
|
232
|
-
}
|
|
233
|
-
for (const idx of current.indexes) {
|
|
234
|
-
const newIdx = new index_meta_1.IndexMeta(entity, idx.columns, idx);
|
|
235
|
-
entity.indexes.push(newIdx);
|
|
236
|
-
}
|
|
237
|
-
entity.eventListeners.push(...current.eventListeners);
|
|
238
|
-
if (current.primaryIndex)
|
|
239
|
-
entity.setPrimaryIndex([...current.primaryIndex.columns]);
|
|
240
|
-
}
|
|
241
|
-
ctor.prototype.toJSON = function () {
|
|
242
|
-
const obj = {};
|
|
243
|
-
const elementKeys = entity.elementKeys;
|
|
244
|
-
const l = elementKeys.length;
|
|
245
|
-
let key;
|
|
246
|
-
let v;
|
|
247
|
-
for (let i = 0; i < l; i++) {
|
|
248
|
-
key = elementKeys[i];
|
|
249
|
-
v = this[key];
|
|
250
|
-
if (v === undefined)
|
|
251
|
-
continue;
|
|
252
|
-
const col = entity.getElement(key);
|
|
253
|
-
if (col)
|
|
254
|
-
obj[key] = (0, serialize_element_1.serializeColumn)(col, v);
|
|
255
|
-
}
|
|
256
|
-
return obj;
|
|
257
|
-
};
|
|
258
|
-
return entity;
|
|
259
|
-
}
|
|
260
|
-
static getElementNames(ctor) {
|
|
261
|
-
const meta = this.get(ctor);
|
|
262
|
-
return meta && [...meta.elementKeys];
|
|
263
|
-
}
|
|
264
|
-
static getColumnNames(ctor) {
|
|
265
|
-
const meta = this.get(ctor);
|
|
266
|
-
if (meta)
|
|
267
|
-
return meta.getColumnNames();
|
|
268
|
-
}
|
|
269
|
-
static getAssociationElementNames(ctor) {
|
|
270
|
-
const meta = this.get(ctor);
|
|
271
|
-
if (meta)
|
|
272
|
-
return meta.getAssociationElementNames();
|
|
273
|
-
}
|
|
274
|
-
static getNonAssociationElementNames(ctor) {
|
|
275
|
-
const meta = this.get(ctor);
|
|
276
|
-
if (meta)
|
|
277
|
-
return meta.getNonAssociationElementNames();
|
|
278
|
-
}
|
|
279
|
-
static getObjectElementNames(ctor) {
|
|
280
|
-
const meta = this.get(ctor);
|
|
281
|
-
if (meta)
|
|
282
|
-
return meta.getObjectElementNames();
|
|
283
|
-
}
|
|
284
|
-
static getInsertColumnNames(ctor) {
|
|
285
|
-
const meta = this.get(ctor);
|
|
286
|
-
if (meta)
|
|
287
|
-
return meta.getInsertColumnNames();
|
|
288
|
-
}
|
|
289
|
-
static getUpdateColumnNames(ctor) {
|
|
290
|
-
const meta = this.get(ctor);
|
|
291
|
-
if (meta)
|
|
292
|
-
return meta.getUpdateColumnNames();
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
exports.EntityModel = EntityModel;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ElementKind, TypeThunk, DataPropertyOptions } from '../orm.type';
|
|
2
|
-
import { AbstractEntityelement } from './abstract-entityelement';
|
|
3
|
-
import { EntityModel } from './entity-model';
|
|
4
|
-
export declare class EntityObjectElement extends AbstractEntityelement {
|
|
5
|
-
kind: ElementKind;
|
|
6
|
-
type: TypeThunk;
|
|
7
|
-
fieldNamePrefix?: string;
|
|
8
|
-
fieldNameSuffix?: string;
|
|
9
|
-
constructor(entity: EntityModel, name: string, type: TypeThunk);
|
|
10
|
-
resolveType(): Promise<EntityModel>;
|
|
11
|
-
assign(options: DataPropertyOptions): void;
|
|
12
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EntityObjectElement = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
6
|
-
const abstract_entityelement_1 = require("./abstract-entityelement");
|
|
7
|
-
const orm_helper_1 = require("../util/orm.helper");
|
|
8
|
-
class EntityObjectElement extends abstract_entityelement_1.AbstractEntityelement {
|
|
9
|
-
constructor(entity, name, type) {
|
|
10
|
-
super(entity, name);
|
|
11
|
-
this.kind = 'object';
|
|
12
|
-
this.type = type;
|
|
13
|
-
}
|
|
14
|
-
async resolveType() {
|
|
15
|
-
const typ = await (0, orm_helper_1.resolveEntityMeta)(this.type);
|
|
16
|
-
if (typ)
|
|
17
|
-
return typ;
|
|
18
|
-
throw new Error(`Can't resolve type of ${this.entity.name}.${this.name}`);
|
|
19
|
-
}
|
|
20
|
-
assign(options) {
|
|
21
|
-
Object.assign(this, lodash_1.default.omit(options, ['entity', 'name', 'kind']));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.EntityObjectElement = EntityObjectElement;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { EntityModel } from './entity-model';
|
|
2
|
-
import { IndexOptions } from '../orm.type';
|
|
3
|
-
export declare class IndexMeta {
|
|
4
|
-
entity: EntityModel;
|
|
5
|
-
columns: string[];
|
|
6
|
-
name?: string;
|
|
7
|
-
unique?: boolean;
|
|
8
|
-
constructor(entity: EntityModel, column: string | string[], options?: IndexOptions);
|
|
9
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IndexMeta = void 0;
|
|
4
|
-
class IndexMeta {
|
|
5
|
-
constructor(entity, column, options) {
|
|
6
|
-
this.entity = entity;
|
|
7
|
-
this.columns = Array.isArray(column) ? column : [column];
|
|
8
|
-
if (options) {
|
|
9
|
-
if (options.name)
|
|
10
|
-
this.name = options.name;
|
|
11
|
-
if (options.unique)
|
|
12
|
-
this.unique = options.unique;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.IndexMeta = IndexMeta;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Type } from 'ts-gems';
|
|
2
|
-
import { AssociationKind, TypeResolver, TypeThunk } from '../orm.type';
|
|
3
|
-
import { AssociationNode } from './association-node';
|
|
4
|
-
export declare class LinkChain<T> {
|
|
5
|
-
target: TypeThunk<T>;
|
|
6
|
-
first: AssociationNode;
|
|
7
|
-
current: AssociationNode;
|
|
8
|
-
constructor(target: TypeThunk<T>, kind: AssociationKind, targetKey?: keyof T, sourceKey?: string);
|
|
9
|
-
where(conditions: object | object[]): this;
|
|
10
|
-
linkToOne<K>(target: Type<K> | TypeResolver<K>, targetColumn?: keyof K, parentColumn?: keyof T): LinkChain<K>;
|
|
11
|
-
linkToMany<K>(target: Type<K> | TypeResolver<K>, targetColumn?: keyof K, parentColumn?: keyof T): LinkChain<K>;
|
|
12
|
-
linkFromOne<K>(target: Type<K> | TypeResolver<K>, targetColumn?: keyof K, parentColumn?: keyof T): LinkChain<K>;
|
|
13
|
-
linkFromMany<K>(target: Type<K> | TypeResolver<K>, targetColumn?: keyof K, parentColumn?: keyof T): LinkChain<K>;
|
|
14
|
-
private _newNode;
|
|
15
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LinkChain = void 0;
|
|
4
|
-
const association_node_1 = require("./association-node");
|
|
5
|
-
class LinkChain {
|
|
6
|
-
constructor(target, kind, targetKey, sourceKey) {
|
|
7
|
-
this.target = target;
|
|
8
|
-
this.first = this.current = new association_node_1.AssociationNode('', {
|
|
9
|
-
kind,
|
|
10
|
-
target,
|
|
11
|
-
source: null,
|
|
12
|
-
sourceKey,
|
|
13
|
-
targetKey: targetKey
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
where(conditions) {
|
|
17
|
-
this.current.conditions = this.current.conditions || [];
|
|
18
|
-
if (Array.isArray(conditions))
|
|
19
|
-
this.current.conditions.push(...conditions);
|
|
20
|
-
else
|
|
21
|
-
this.current.conditions.push(conditions);
|
|
22
|
-
return this;
|
|
23
|
-
}
|
|
24
|
-
linkToOne(target, targetColumn, parentColumn) {
|
|
25
|
-
return this._newNode(target, 'to', targetColumn, parentColumn);
|
|
26
|
-
}
|
|
27
|
-
linkToMany(target, targetColumn, parentColumn) {
|
|
28
|
-
return this._newNode(target, 'to-many', targetColumn, parentColumn);
|
|
29
|
-
}
|
|
30
|
-
linkFromOne(target, targetColumn, parentColumn) {
|
|
31
|
-
return this._newNode(target, 'from', targetColumn, parentColumn);
|
|
32
|
-
}
|
|
33
|
-
linkFromMany(target, targetColumn, parentColumn) {
|
|
34
|
-
return this._newNode(target, 'from-many', targetColumn, parentColumn);
|
|
35
|
-
}
|
|
36
|
-
_newNode(target, kind, targetKey, parentKey) {
|
|
37
|
-
const child = new association_node_1.AssociationNode(this.current.name, {
|
|
38
|
-
kind,
|
|
39
|
-
source: this.current.target,
|
|
40
|
-
target,
|
|
41
|
-
sourceKey: parentKey,
|
|
42
|
-
targetKey: targetKey
|
|
43
|
-
});
|
|
44
|
-
child.prior = this.current;
|
|
45
|
-
this.current.next = child;
|
|
46
|
-
this.current = child;
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.LinkChain = LinkChain;
|
package/dist/orm/orm.const.d.ts
DELETED
package/dist/orm/orm.const.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.REPOSITORY_KEY = exports.ENTITY_DEFINITION_KEY = void 0;
|
|
4
|
-
exports.ENTITY_DEFINITION_KEY = Symbol.for('sqb.entity-definition');
|
|
5
|
-
exports.REPOSITORY_KEY = Symbol.for('sqb.entity.repository');
|
package/dist/orm/orm.type.d.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { Type } from 'ts-gems';
|
|
2
|
-
import { DataType } from '..';
|
|
3
|
-
export declare type ElementKind = 'column' | 'object' | 'association';
|
|
4
|
-
export declare type AssociationKind = 'to' | 'to-many' | 'from' | 'from-many';
|
|
5
|
-
/**
|
|
6
|
-
* Indicates auto generation strategy
|
|
7
|
-
*/
|
|
8
|
-
export declare type ColumnAutoGenerationStrategy = 'increment' | 'uuid' | 'rowid' | 'timestamp' | 'custom';
|
|
9
|
-
export declare type ColumnTransformFunction = (value: any, name: string) => any;
|
|
10
|
-
export declare type TypeResolver<T> = () => Type<T> | Promise<Type<T>>;
|
|
11
|
-
export declare type TypeThunk<T = any> = Type<T> | TypeResolver<T>;
|
|
12
|
-
export declare type EnumValue = (FieldValue)[] | Object;
|
|
13
|
-
export declare type FieldValue = string | number | boolean | Date | null;
|
|
14
|
-
export declare type DefaultValueGetter = (obj?: any) => FieldValue;
|
|
15
|
-
export interface EntityConfig {
|
|
16
|
-
/**
|
|
17
|
-
* Name of the table name. Default: entity class name.
|
|
18
|
-
*/
|
|
19
|
-
tableName?: string;
|
|
20
|
-
/**
|
|
21
|
-
* Schema name which entity belongs to
|
|
22
|
-
*/
|
|
23
|
-
schema?: string;
|
|
24
|
-
/**
|
|
25
|
-
* Table comment
|
|
26
|
-
*/
|
|
27
|
-
comment?: string;
|
|
28
|
-
}
|
|
29
|
-
export interface IndexOptions {
|
|
30
|
-
/**
|
|
31
|
-
* Name of the index
|
|
32
|
-
*/
|
|
33
|
-
name?: string;
|
|
34
|
-
/**
|
|
35
|
-
* Specifies if index is unique
|
|
36
|
-
*/
|
|
37
|
-
unique?: boolean;
|
|
38
|
-
}
|
|
39
|
-
export interface AssociationSettings {
|
|
40
|
-
source: TypeThunk;
|
|
41
|
-
target: TypeThunk;
|
|
42
|
-
sourceKey?: string;
|
|
43
|
-
targetKey?: string;
|
|
44
|
-
kind?: AssociationKind;
|
|
45
|
-
}
|
|
46
|
-
export interface DataPropertyOptions {
|
|
47
|
-
type?: Function;
|
|
48
|
-
/**
|
|
49
|
-
* Column data type
|
|
50
|
-
*/
|
|
51
|
-
dataType?: DataType;
|
|
52
|
-
/**
|
|
53
|
-
*
|
|
54
|
-
*/
|
|
55
|
-
isArray?: boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Field name in the database table. Default: property name
|
|
58
|
-
*/
|
|
59
|
-
fieldName?: string;
|
|
60
|
-
/**
|
|
61
|
-
* Field comment
|
|
62
|
-
*/
|
|
63
|
-
comment?: string;
|
|
64
|
-
/**
|
|
65
|
-
* Character or byte length of column
|
|
66
|
-
*/
|
|
67
|
-
length?: number;
|
|
68
|
-
/**
|
|
69
|
-
* Column's default value
|
|
70
|
-
*/
|
|
71
|
-
default?: FieldValue | DefaultValueGetter;
|
|
72
|
-
/**
|
|
73
|
-
* The precision for a decimal field
|
|
74
|
-
*/
|
|
75
|
-
precision?: number;
|
|
76
|
-
/**
|
|
77
|
-
* The scale for a decimal field
|
|
78
|
-
*/
|
|
79
|
-
scale?: number;
|
|
80
|
-
/**
|
|
81
|
-
* Fields's collation.
|
|
82
|
-
*/
|
|
83
|
-
collation?: string;
|
|
84
|
-
/**
|
|
85
|
-
* Indicates auto generation strategy
|
|
86
|
-
*/
|
|
87
|
-
autoGenerated?: ColumnAutoGenerationStrategy;
|
|
88
|
-
/**
|
|
89
|
-
* Indicates enum values
|
|
90
|
-
*/
|
|
91
|
-
enum?: EnumValue;
|
|
92
|
-
/**
|
|
93
|
-
* Indicates if column value can be null
|
|
94
|
-
*/
|
|
95
|
-
notNull?: boolean;
|
|
96
|
-
/**
|
|
97
|
-
* Indicates whether or not to hide this column by default when making queries.
|
|
98
|
-
*/
|
|
99
|
-
hidden?: boolean;
|
|
100
|
-
/**
|
|
101
|
-
* Indicates if column value is used in update queries
|
|
102
|
-
*/
|
|
103
|
-
noUpdate?: boolean;
|
|
104
|
-
/**
|
|
105
|
-
* Indicates if column value is used in insert queries
|
|
106
|
-
*/
|
|
107
|
-
noInsert?: boolean;
|
|
108
|
-
}
|
|
109
|
-
export interface EmbeddedTypeOptions {
|
|
110
|
-
fieldNamePrefix?: string;
|
|
111
|
-
fieldNameSuffix?: string;
|
|
112
|
-
}
|
package/dist/orm/orm.type.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { DeepPartial, Type } from 'ts-gems';
|
|
2
|
-
import { AsyncEventEmitter } from 'strict-typed-events';
|
|
3
|
-
import { SqbClient } from '../client/SqbClient';
|
|
4
|
-
import { SqbConnection } from '../client/SqbConnection';
|
|
5
|
-
import { EntityModel } from './model/entity-model';
|
|
6
|
-
import { QueryRequest, TransactionFunction } from '../client/types';
|
|
7
|
-
import { InstanceValues } from '../types';
|
|
8
|
-
import { FieldInfoMap } from '../client/FieldInfoMap';
|
|
9
|
-
export declare namespace Repository {
|
|
10
|
-
type TransformRowFunction = (fields: FieldInfoMap, row: object, obj: object) => void;
|
|
11
|
-
interface CommandOptions {
|
|
12
|
-
connection?: SqbConnection;
|
|
13
|
-
}
|
|
14
|
-
interface CreateOptions extends CommandOptions {
|
|
15
|
-
elements?: string[];
|
|
16
|
-
include?: string[];
|
|
17
|
-
exclude?: string[];
|
|
18
|
-
}
|
|
19
|
-
interface CountOptions extends CommandOptions {
|
|
20
|
-
filter?: any;
|
|
21
|
-
params?: any;
|
|
22
|
-
}
|
|
23
|
-
interface ExistsOptions extends CommandOptions {
|
|
24
|
-
filter?: any;
|
|
25
|
-
params?: any;
|
|
26
|
-
}
|
|
27
|
-
interface DestroyOptions extends CommandOptions {
|
|
28
|
-
filter?: any;
|
|
29
|
-
params?: any;
|
|
30
|
-
}
|
|
31
|
-
interface FindOneOptions extends CommandOptions {
|
|
32
|
-
elements?: string[];
|
|
33
|
-
include?: string[];
|
|
34
|
-
exclude?: string[];
|
|
35
|
-
filter?: any;
|
|
36
|
-
params?: any;
|
|
37
|
-
sort?: string[];
|
|
38
|
-
offset?: number;
|
|
39
|
-
distinct?: boolean;
|
|
40
|
-
onTransformRow?: TransformRowFunction;
|
|
41
|
-
}
|
|
42
|
-
interface FindAllOptions extends FindOneOptions {
|
|
43
|
-
limit?: number;
|
|
44
|
-
maxEagerFetch?: number;
|
|
45
|
-
maxSubQueries?: number;
|
|
46
|
-
}
|
|
47
|
-
interface GetOptions extends CommandOptions {
|
|
48
|
-
elements?: string[];
|
|
49
|
-
include?: string[];
|
|
50
|
-
exclude?: string[];
|
|
51
|
-
filter?: any;
|
|
52
|
-
params?: any;
|
|
53
|
-
}
|
|
54
|
-
interface UpdateOptions extends CommandOptions {
|
|
55
|
-
elements?: string[];
|
|
56
|
-
include?: string[];
|
|
57
|
-
exclude?: string[];
|
|
58
|
-
filter?: any;
|
|
59
|
-
params?: any;
|
|
60
|
-
}
|
|
61
|
-
interface UpdateAllOptions extends CommandOptions {
|
|
62
|
-
filter?: any;
|
|
63
|
-
params?: any;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
interface RepositoryEvents {
|
|
67
|
-
execute: (request: QueryRequest) => void;
|
|
68
|
-
error: (error: Error) => void;
|
|
69
|
-
acquire: (connection: SqbConnection) => Promise<void>;
|
|
70
|
-
}
|
|
71
|
-
export declare class Repository<T> extends AsyncEventEmitter<RepositoryEvents> {
|
|
72
|
-
private readonly _executor;
|
|
73
|
-
private readonly _entity;
|
|
74
|
-
private readonly _schema?;
|
|
75
|
-
constructor(entityDef: EntityModel, executor: SqbClient | SqbConnection, schema?: string);
|
|
76
|
-
get entity(): EntityModel;
|
|
77
|
-
get type(): Type<T>;
|
|
78
|
-
create(values: InstanceValues<T>, options?: Repository.CreateOptions): Promise<DeepPartial<T>>;
|
|
79
|
-
createOnly(values: InstanceValues<T>, options?: Repository.CreateOptions): Promise<void>;
|
|
80
|
-
exists(keyValue: any | Record<string, any>, options?: Repository.ExistsOptions): Promise<boolean>;
|
|
81
|
-
count(options?: Repository.CountOptions): Promise<number>;
|
|
82
|
-
findAll(options?: Repository.FindAllOptions): Promise<DeepPartial<T>[]>;
|
|
83
|
-
findOne(options?: Repository.FindOneOptions): Promise<DeepPartial<T> | undefined>;
|
|
84
|
-
findByPk(keyValue: any | Record<string, any>, options?: Repository.GetOptions): Promise<DeepPartial<T> | undefined>;
|
|
85
|
-
destroy(keyValue: any | Record<string, any>, options?: Repository.DestroyOptions): Promise<boolean>;
|
|
86
|
-
destroyAll(options?: Repository.DestroyOptions): Promise<number>;
|
|
87
|
-
update(keyValue: any | Record<string, any>, values: InstanceValues<T>, options?: Repository.UpdateOptions): Promise<DeepPartial<T> | undefined>;
|
|
88
|
-
updateOnly(keyValue: any | Record<string, any>, values: InstanceValues<T>, options?: Repository.UpdateOptions): Promise<DeepPartial<T>>;
|
|
89
|
-
updateAll(values: InstanceValues<T>, options?: Repository.UpdateAllOptions): Promise<number>;
|
|
90
|
-
protected _execute(fn: TransactionFunction, opts?: Repository.CommandOptions): Promise<any>;
|
|
91
|
-
protected _create(values: InstanceValues<T>, options: Repository.CreateOptions & {
|
|
92
|
-
connection: SqbConnection;
|
|
93
|
-
}): Promise<DeepPartial<T>>;
|
|
94
|
-
protected _createOnly(values: InstanceValues<T>, options: Repository.CreateOptions & {
|
|
95
|
-
connection: SqbConnection;
|
|
96
|
-
}): Promise<void>;
|
|
97
|
-
protected _exists(keyValue: any | Record<string, any>, options: Repository.ExistsOptions & {
|
|
98
|
-
connection: SqbConnection;
|
|
99
|
-
}): Promise<boolean>;
|
|
100
|
-
protected _count(options: Repository.CountOptions & {
|
|
101
|
-
connection: SqbConnection;
|
|
102
|
-
}): Promise<number>;
|
|
103
|
-
protected _findAll(options: Repository.FindAllOptions & {
|
|
104
|
-
connection: SqbConnection;
|
|
105
|
-
}): Promise<DeepPartial<T>[]>;
|
|
106
|
-
protected _findOne(options: Repository.FindOneOptions & {
|
|
107
|
-
connection: SqbConnection;
|
|
108
|
-
}): Promise<DeepPartial<T> | undefined>;
|
|
109
|
-
protected _findByPk(keyValue: any | Record<string, any>, options: Repository.GetOptions & {
|
|
110
|
-
connection: SqbConnection;
|
|
111
|
-
}): Promise<DeepPartial<T> | undefined>;
|
|
112
|
-
protected _destroy(keyValue: any | Record<string, any>, options: Repository.DestroyOptions & {
|
|
113
|
-
connection: SqbConnection;
|
|
114
|
-
}): Promise<boolean>;
|
|
115
|
-
protected _destroyAll(options: Repository.DestroyOptions & {
|
|
116
|
-
connection: SqbConnection;
|
|
117
|
-
}): Promise<number>;
|
|
118
|
-
protected _update(keyValue: any | Record<string, any>, values: InstanceValues<T>, options: Repository.UpdateOptions & {
|
|
119
|
-
connection: SqbConnection;
|
|
120
|
-
}): Promise<Record<string, any> | undefined>;
|
|
121
|
-
protected _updateAll(values: InstanceValues<T>, options: Repository.UpdateAllOptions & {
|
|
122
|
-
connection: SqbConnection;
|
|
123
|
-
}): Promise<number>;
|
|
124
|
-
}
|
|
125
|
-
export {};
|