@sqb/connect 4.11.2 → 4.12.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/README.md +9 -24
- package/cjs/client/cursor-stream.js +6 -3
- package/cjs/client/cursor.js +8 -6
- package/cjs/client/field-info-map.js +3 -3
- package/cjs/client/sqb-client.js +2 -3
- package/cjs/client/sqb-connection.js +14 -13
- package/cjs/orm/commands/command.helper.js +7 -8
- package/cjs/orm/commands/create.command.js +4 -5
- package/cjs/orm/commands/find.command.js +19 -30
- package/cjs/orm/commands/row-converter.js +6 -6
- package/cjs/orm/commands/update.command.js +3 -4
- package/cjs/orm/decorators/column.decorator.js +1 -1
- package/cjs/orm/decorators/embedded.decorator.js +1 -1
- package/cjs/orm/decorators/entity.decorator.js +2 -2
- package/cjs/orm/decorators/link.decorator.js +1 -1
- package/cjs/orm/decorators/transform.decorator.js +2 -4
- package/cjs/orm/model/association-field-metadata.js +1 -1
- package/cjs/orm/model/association.js +2 -4
- package/cjs/orm/model/column-field-metadata.js +1 -1
- package/cjs/orm/model/embedded-field-metadata.js +1 -1
- package/cjs/orm/model/entity-metadata.js +7 -7
- package/cjs/orm/model/link-chain.js +2 -2
- package/cjs/orm/repository.class.js +8 -9
- package/cjs/orm/util/apply-mixins.js +6 -4
- package/cjs/orm/util/extract-keyvalues.js +1 -1
- package/cjs/orm/util/serialize-field.js +10 -10
- package/esm/client/cursor-stream.js +6 -3
- package/esm/client/cursor.js +8 -6
- package/esm/client/field-info-map.js +3 -3
- package/esm/client/helpers.js +1 -1
- package/esm/client/sqb-client.js +2 -3
- package/esm/client/sqb-connection.js +15 -14
- package/esm/orm/commands/command.helper.js +8 -9
- package/esm/orm/commands/create.command.js +4 -5
- package/esm/orm/commands/find.command.js +19 -30
- package/esm/orm/commands/row-converter.js +6 -6
- package/esm/orm/commands/update.command.js +3 -4
- package/esm/orm/decorators/column.decorator.js +1 -1
- package/esm/orm/decorators/embedded.decorator.js +1 -1
- package/esm/orm/decorators/entity.decorator.js +2 -2
- package/esm/orm/decorators/link.decorator.js +1 -1
- package/esm/orm/decorators/transform.decorator.js +2 -4
- package/esm/orm/model/association-field-metadata.js +1 -1
- package/esm/orm/model/association.js +2 -4
- package/esm/orm/model/column-field-metadata.js +1 -1
- package/esm/orm/model/embedded-field-metadata.js +1 -1
- package/esm/orm/model/entity-metadata.js +7 -7
- package/esm/orm/model/link-chain.js +2 -2
- package/esm/orm/repository.class.js +8 -9
- package/esm/orm/util/apply-mixins.js +6 -4
- package/esm/orm/util/extract-keyvalues.js +1 -1
- package/esm/orm/util/serialize-field.js +10 -10
- package/package.json +8 -7
- package/types/orm/decorators/entity.decorator.d.ts +2 -2
- package/types/orm/orm.type.d.ts +1 -1
- package/types/orm/repository.class.d.ts +2 -1
|
@@ -56,7 +56,7 @@ export class FindCommand {
|
|
|
56
56
|
pick: args.pick,
|
|
57
57
|
include: args.include,
|
|
58
58
|
omit: args.omit,
|
|
59
|
-
sort: args.sort
|
|
59
|
+
sort: args.sort,
|
|
60
60
|
});
|
|
61
61
|
if (args.filter)
|
|
62
62
|
await command.filter(args.filter);
|
|
@@ -68,12 +68,9 @@ export class FindCommand {
|
|
|
68
68
|
const tableAlias = opts.tableAlias || this.resultAlias;
|
|
69
69
|
const entity = opts.entity || this._getEntityFromAlias(tableAlias);
|
|
70
70
|
const converter = opts.converter || this.converter;
|
|
71
|
-
const _pick = opts.pick ?
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
opts.omit.map(x => x.toLowerCase()) : undefined;
|
|
75
|
-
const _include = opts.include ?
|
|
76
|
-
opts.include.map(x => x.toLowerCase()) : undefined;
|
|
71
|
+
const _pick = opts.pick ? opts.pick.map(x => x.toLowerCase()) : undefined;
|
|
72
|
+
const _omit = opts.omit ? opts.omit.map(x => x.toLowerCase()) : undefined;
|
|
73
|
+
const _include = opts.include ? opts.include.map(x => x.toLowerCase()) : undefined;
|
|
77
74
|
let requestedFields;
|
|
78
75
|
if (_pick)
|
|
79
76
|
requestedFields = [..._pick];
|
|
@@ -87,8 +84,7 @@ export class FindCommand {
|
|
|
87
84
|
}
|
|
88
85
|
if (_include)
|
|
89
86
|
requestedFields.push(..._include);
|
|
90
|
-
const sortFields = opts.sort && opts.sort.length ?
|
|
91
|
-
opts.sort.map(x => x.toLowerCase()) : undefined;
|
|
87
|
+
const sortFields = opts.sort && opts.sort.length ? opts.sort.map(x => x.toLowerCase()) : undefined;
|
|
92
88
|
const prefix = opts.prefix || '';
|
|
93
89
|
const suffix = opts.suffix || '';
|
|
94
90
|
for (const key of Object.keys(entity.fields)) {
|
|
@@ -110,7 +106,7 @@ export class FindCommand {
|
|
|
110
106
|
name: col.name,
|
|
111
107
|
fieldAlias,
|
|
112
108
|
dataType: col.dataType,
|
|
113
|
-
parse: col.parse
|
|
109
|
+
parse: col.parse,
|
|
114
110
|
});
|
|
115
111
|
continue;
|
|
116
112
|
}
|
|
@@ -118,7 +114,7 @@ export class FindCommand {
|
|
|
118
114
|
const typ = await EmbeddedFieldMetadata.resolveType(col);
|
|
119
115
|
const subConverter = converter.addObjectProperty({
|
|
120
116
|
name: col.name,
|
|
121
|
-
type: typ.ctor
|
|
117
|
+
type: typ.ctor,
|
|
122
118
|
}).converter;
|
|
123
119
|
await this.addFields({
|
|
124
120
|
tableAlias,
|
|
@@ -126,8 +122,7 @@ export class FindCommand {
|
|
|
126
122
|
entity: typ,
|
|
127
123
|
prefix: col.fieldNamePrefix,
|
|
128
124
|
suffix: col.fieldNameSuffix,
|
|
129
|
-
pick: _pick?.includes(colNameLower) ? undefined :
|
|
130
|
-
extractSubFields(colNameLower, _pick),
|
|
125
|
+
pick: _pick?.includes(colNameLower) ? undefined : extractSubFields(colNameLower, _pick),
|
|
131
126
|
include: extractSubFields(colNameLower, _include),
|
|
132
127
|
omit: extractSubFields(colNameLower, _omit),
|
|
133
128
|
sort: extractSubFields(colNameLower, sortFields),
|
|
@@ -140,15 +135,14 @@ export class FindCommand {
|
|
|
140
135
|
const joinInfo = await joinAssociationGetLast(this._joins, col.association, tableAlias);
|
|
141
136
|
const subConverter = converter.addObjectProperty({
|
|
142
137
|
name: col.name,
|
|
143
|
-
type: joinInfo.targetEntity.ctor
|
|
138
|
+
type: joinInfo.targetEntity.ctor,
|
|
144
139
|
}).converter;
|
|
145
140
|
// Add join fields to select columns list
|
|
146
141
|
await this.addFields({
|
|
147
142
|
tableAlias: joinInfo.joinAlias,
|
|
148
143
|
converter: subConverter,
|
|
149
144
|
entity: joinInfo.targetEntity,
|
|
150
|
-
pick: _pick?.includes(colNameLower) ? undefined :
|
|
151
|
-
extractSubFields(colNameLower, _pick),
|
|
145
|
+
pick: _pick?.includes(colNameLower) ? undefined : extractSubFields(colNameLower, _pick),
|
|
152
146
|
include: extractSubFields(colNameLower, _include),
|
|
153
147
|
omit: extractSubFields(colNameLower, _omit),
|
|
154
148
|
sort: extractSubFields(colNameLower, sortFields),
|
|
@@ -164,14 +158,13 @@ export class FindCommand {
|
|
|
164
158
|
const parentField = this._selectColumn(tableAlias, sourceCol);
|
|
165
159
|
const findCommand = await FindCommand.create(col.association, {
|
|
166
160
|
maxSubQueries: this.maxSubQueries - 1,
|
|
167
|
-
maxEagerFetch: this.maxEagerFetch
|
|
161
|
+
maxEagerFetch: this.maxEagerFetch,
|
|
168
162
|
});
|
|
169
163
|
findCommand.converter.parent = this.converter;
|
|
170
164
|
await findCommand.filter(In(targetCol.name, Param(parentField)));
|
|
171
165
|
const sort = sortFields && extractSubFields(colNameLower, sortFields);
|
|
172
166
|
await findCommand.addFields({
|
|
173
|
-
pick: _pick?.includes(colNameLower) ? undefined :
|
|
174
|
-
extractSubFields(colNameLower, _pick),
|
|
167
|
+
pick: _pick?.includes(colNameLower) ? undefined : extractSubFields(colNameLower, _pick),
|
|
175
168
|
include: extractSubFields(colNameLower, _include),
|
|
176
169
|
omit: extractSubFields(colNameLower, _omit),
|
|
177
170
|
sort,
|
|
@@ -186,20 +179,18 @@ export class FindCommand {
|
|
|
186
179
|
findCommand,
|
|
187
180
|
parentField,
|
|
188
181
|
keyField,
|
|
189
|
-
sort: extractSubFields(colNameLower, sortFields)
|
|
182
|
+
sort: extractSubFields(colNameLower, sortFields),
|
|
190
183
|
});
|
|
191
184
|
}
|
|
192
185
|
}
|
|
193
186
|
}
|
|
194
187
|
}
|
|
195
188
|
_selectColumn(tableAlias, el, prefix, suffix) {
|
|
196
|
-
const fieldName = (prefix || '').toLowerCase() +
|
|
197
|
-
|
|
198
|
-
(suffix || '').toLowerCase();
|
|
199
|
-
const fieldAlias = tableAlias + '_' + fieldName;
|
|
189
|
+
const fieldName = (prefix || '').toLowerCase() + el.fieldName.toUpperCase() + (suffix || '').toLowerCase();
|
|
190
|
+
const fieldAlias = (tableAlias + '_' + fieldName).substring(0, 30);
|
|
200
191
|
this._selectColumns[fieldAlias] = {
|
|
201
192
|
field: el,
|
|
202
|
-
statement: tableAlias + '.' + fieldName + ' as ' + fieldAlias
|
|
193
|
+
statement: tableAlias + '.' + fieldName + ' as ' + fieldAlias,
|
|
203
194
|
};
|
|
204
195
|
return fieldAlias;
|
|
205
196
|
}
|
|
@@ -256,12 +247,10 @@ export class FindCommand {
|
|
|
256
247
|
}
|
|
257
248
|
async execute(args) {
|
|
258
249
|
// Generate select query
|
|
259
|
-
const columnSqls = Object.keys(this._selectColumns)
|
|
260
|
-
.map(x => this._selectColumns[x].statement);
|
|
250
|
+
const columnSqls = Object.keys(this._selectColumns).map(x => this._selectColumns[x].statement);
|
|
261
251
|
if (!columnSqls.length)
|
|
262
252
|
columnSqls.push('1');
|
|
263
|
-
const query = Select(...columnSqls)
|
|
264
|
-
.from(this.mainEntity.tableName + ' as ' + this.mainAlias);
|
|
253
|
+
const query = Select(...columnSqls).from(this.mainEntity.tableName + ' as ' + this.mainAlias);
|
|
265
254
|
if (args.distinct)
|
|
266
255
|
query.distinct();
|
|
267
256
|
query.where(...this._filter._items);
|
|
@@ -280,7 +269,7 @@ export class FindCommand {
|
|
|
280
269
|
params: args?.params,
|
|
281
270
|
fetchRows: args?.limit,
|
|
282
271
|
objectRows: false,
|
|
283
|
-
cursor: false
|
|
272
|
+
cursor: false,
|
|
284
273
|
});
|
|
285
274
|
// Create objects
|
|
286
275
|
if (resp.rows && resp.fields) {
|
|
@@ -19,7 +19,7 @@ export class RowConverter {
|
|
|
19
19
|
const item = {
|
|
20
20
|
fieldAlias: args.fieldAlias,
|
|
21
21
|
dataType: args.dataType,
|
|
22
|
-
parse: args.parse
|
|
22
|
+
parse: args.parse,
|
|
23
23
|
};
|
|
24
24
|
this._properties[args.name] = item;
|
|
25
25
|
return item;
|
|
@@ -30,7 +30,7 @@ export class RowConverter {
|
|
|
30
30
|
const converter = new RowConverter(args.type, this);
|
|
31
31
|
const item = {
|
|
32
32
|
converter,
|
|
33
|
-
type: args.type
|
|
33
|
+
type: args.type,
|
|
34
34
|
};
|
|
35
35
|
this._properties[args.name] = item;
|
|
36
36
|
return item;
|
|
@@ -45,7 +45,7 @@ export class RowConverter {
|
|
|
45
45
|
keyField: args.keyField,
|
|
46
46
|
findCommand: args.findCommand,
|
|
47
47
|
sort: args.sort,
|
|
48
|
-
paramValues: []
|
|
48
|
+
paramValues: [],
|
|
49
49
|
};
|
|
50
50
|
this._properties[args.name] = item;
|
|
51
51
|
return item;
|
|
@@ -126,7 +126,7 @@ export class RowConverter {
|
|
|
126
126
|
if (!(prop.paramValues && prop.paramValues.length))
|
|
127
127
|
continue;
|
|
128
128
|
const resultType = this.resultType;
|
|
129
|
-
const promise = async function (p) {
|
|
129
|
+
const promise = (async function (p) {
|
|
130
130
|
const findCommand = p.findCommand;
|
|
131
131
|
let fld;
|
|
132
132
|
const map = new Map();
|
|
@@ -148,7 +148,7 @@ export class RowConverter {
|
|
|
148
148
|
arr.push(obj);
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
|
-
}
|
|
151
|
+
},
|
|
152
152
|
});
|
|
153
153
|
if (r.length > findCommand.maxEagerFetch)
|
|
154
154
|
throw new Error(`Number of returning rows for "${propKey}" exceeds maxEagerFetch limit`);
|
|
@@ -168,7 +168,7 @@ export class RowConverter {
|
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
|
-
}(prop);
|
|
171
|
+
})(prop);
|
|
172
172
|
promises.push(promise);
|
|
173
173
|
}
|
|
174
174
|
else if (isObjectProperty(prop)) {
|
|
@@ -27,12 +27,11 @@ export class UpdateCommand {
|
|
|
27
27
|
return 0;
|
|
28
28
|
if (args.filter)
|
|
29
29
|
await this._prepareFilter(ctx, args.filter);
|
|
30
|
-
const query = Update(tableName + ' as T', ctx.queryValues)
|
|
31
|
-
.where(...ctx.queryFilter);
|
|
30
|
+
const query = Update(tableName + ' as T', ctx.queryValues).where(...ctx.queryFilter);
|
|
32
31
|
const qr = await args.connection.execute(query, {
|
|
33
32
|
params: args.params ? [...args.params, ctx.queryParams] : ctx.queryParams,
|
|
34
33
|
objectRows: false,
|
|
35
|
-
cursor: false
|
|
34
|
+
cursor: false,
|
|
36
35
|
});
|
|
37
36
|
return qr.rowsAffected || 0;
|
|
38
37
|
}
|
|
@@ -66,7 +65,7 @@ export class UpdateCommand {
|
|
|
66
65
|
ctx.queryValues[fieldName] = Param({
|
|
67
66
|
name: k,
|
|
68
67
|
dataType: col.dataType,
|
|
69
|
-
isArray: col.isArray
|
|
68
|
+
isArray: col.isArray,
|
|
70
69
|
});
|
|
71
70
|
ctx.queryParams[k] = v;
|
|
72
71
|
ctx.colCount++;
|
|
@@ -6,7 +6,7 @@ export function Column(arg0) {
|
|
|
6
6
|
const options = (typeof arg0 === 'string' ? { dataType: arg0 } : arg0) || {};
|
|
7
7
|
const entity = EntityMetadata.define(target.constructor);
|
|
8
8
|
if (!options.type) {
|
|
9
|
-
const typ = Reflect.getMetadata(
|
|
9
|
+
const typ = Reflect.getMetadata('design:type', entity.ctor.prototype, propertyKey);
|
|
10
10
|
if (typ === Array) {
|
|
11
11
|
options.type = String;
|
|
12
12
|
options.isArray = true;
|
|
@@ -3,7 +3,7 @@ export function Embedded(type, options) {
|
|
|
3
3
|
return (target, propertyKey) => {
|
|
4
4
|
if (typeof propertyKey !== 'string')
|
|
5
5
|
throw new Error('Symbol properties are not accepted');
|
|
6
|
-
type = type || Reflect.getMetadata(
|
|
6
|
+
type = type || Reflect.getMetadata('design:type', target, propertyKey);
|
|
7
7
|
if (typeof type !== 'function')
|
|
8
8
|
throw new Error('"type" must be defined');
|
|
9
9
|
const entity = EntityMetadata.define(target.constructor);
|
|
@@ -111,7 +111,7 @@ export function Entity(options) {
|
|
|
111
111
|
}
|
|
112
112
|
};
|
|
113
113
|
const pickKeys = keys.map(x => x.toLowerCase());
|
|
114
|
-
const filter =
|
|
114
|
+
const filter = k => pickKeys.includes(k.toLowerCase());
|
|
115
115
|
applyMixins(PickEntityClass, classRef, filter);
|
|
116
116
|
const srcMeta = EntityMetadata.get(classRef);
|
|
117
117
|
if (srcMeta) {
|
|
@@ -128,7 +128,7 @@ export function Entity(options) {
|
|
|
128
128
|
}
|
|
129
129
|
};
|
|
130
130
|
const omitKeys = keys.map(x => x.toLowerCase());
|
|
131
|
-
const filter =
|
|
131
|
+
const filter = k => !omitKeys.includes(k.toLowerCase());
|
|
132
132
|
applyMixins(OmitEntityClass, classRef, filter);
|
|
133
133
|
const srcMeta = EntityMetadata.get(classRef);
|
|
134
134
|
if (srcMeta) {
|
|
@@ -6,7 +6,7 @@ export function Link(options) {
|
|
|
6
6
|
const fn = (target, propertyKey) => {
|
|
7
7
|
if (typeof propertyKey !== 'string')
|
|
8
8
|
throw new TypeError('Symbol properties are not allowed');
|
|
9
|
-
const reflectType = Reflect.getMetadata(
|
|
9
|
+
const reflectType = Reflect.getMetadata('design:type', target, propertyKey);
|
|
10
10
|
if (!root) {
|
|
11
11
|
if (reflectType === Array)
|
|
12
12
|
throw new TypeError(`Can't get type information while it is an array. Please define entity type`);
|
|
@@ -4,8 +4,7 @@ export function Parse(fn) {
|
|
|
4
4
|
if (typeof propertyKey !== 'string')
|
|
5
5
|
throw new Error('You can define a Column for only string properties');
|
|
6
6
|
const entity = EntityMetadata.define(target.constructor);
|
|
7
|
-
EntityMetadata.defineColumnField(entity, propertyKey)
|
|
8
|
-
.parse = fn;
|
|
7
|
+
EntityMetadata.defineColumnField(entity, propertyKey).parse = fn;
|
|
9
8
|
};
|
|
10
9
|
}
|
|
11
10
|
export function Serialize(fn) {
|
|
@@ -13,7 +12,6 @@ export function Serialize(fn) {
|
|
|
13
12
|
if (typeof propertyKey !== 'string')
|
|
14
13
|
throw new Error('You can define a Column for only string properties');
|
|
15
14
|
const entity = EntityMetadata.define(target.constructor);
|
|
16
|
-
EntityMetadata.defineColumnField(entity, propertyKey)
|
|
17
|
-
.serialize = fn;
|
|
15
|
+
EntityMetadata.defineColumnField(entity, propertyKey).serialize = fn;
|
|
18
16
|
};
|
|
19
17
|
}
|
|
@@ -78,8 +78,7 @@ export class Association {
|
|
|
78
78
|
if (this.many) {
|
|
79
79
|
if (!sourceKey) {
|
|
80
80
|
const primaryIndexColumns = EntityMetadata.getPrimaryIndexColumns(source);
|
|
81
|
-
sourceKey = primaryIndexColumns && primaryIndexColumns.length === 1 ?
|
|
82
|
-
primaryIndexColumns[0].name : 'id';
|
|
81
|
+
sourceKey = primaryIndexColumns && primaryIndexColumns.length === 1 ? primaryIndexColumns[0].name : 'id';
|
|
83
82
|
}
|
|
84
83
|
if (!targetKey && sourceKey) {
|
|
85
84
|
// snake-case
|
|
@@ -92,8 +91,7 @@ export class Association {
|
|
|
92
91
|
else {
|
|
93
92
|
if (!targetKey) {
|
|
94
93
|
const primaryIndexColumns = EntityMetadata.getPrimaryIndexColumns(target);
|
|
95
|
-
targetKey = primaryIndexColumns && primaryIndexColumns.length === 1 ?
|
|
96
|
-
primaryIndexColumns[0].name : 'id';
|
|
94
|
+
targetKey = primaryIndexColumns && primaryIndexColumns.length === 1 ? primaryIndexColumns[0].name : 'id';
|
|
97
95
|
}
|
|
98
96
|
if (!sourceKey && targetKey) {
|
|
99
97
|
// snake-case
|
|
@@ -18,7 +18,7 @@ export var EntityMetadata;
|
|
|
18
18
|
fields: {},
|
|
19
19
|
indexes: [],
|
|
20
20
|
foreignKeys: [],
|
|
21
|
-
eventListeners: {}
|
|
21
|
+
eventListeners: {},
|
|
22
22
|
};
|
|
23
23
|
Reflect.defineMetadata(ENTITY_METADATA_KEY, meta, ctor);
|
|
24
24
|
// Merge base entity columns into this one
|
|
@@ -90,7 +90,7 @@ export var EntityMetadata;
|
|
|
90
90
|
enumerable: false,
|
|
91
91
|
configurable: true,
|
|
92
92
|
writable: true,
|
|
93
|
-
value: Object.values(entity.fields).map(m => m.name)
|
|
93
|
+
value: Object.values(entity.fields).map(m => m.name),
|
|
94
94
|
});
|
|
95
95
|
return entity._fieldNames;
|
|
96
96
|
}
|
|
@@ -141,7 +141,7 @@ export var EntityMetadata;
|
|
|
141
141
|
if (!src.foreignKeys)
|
|
142
142
|
return;
|
|
143
143
|
for (const f of src.foreignKeys) {
|
|
144
|
-
if (await f.resolveTarget() === trg)
|
|
144
|
+
if ((await f.resolveTarget()) === trg)
|
|
145
145
|
return f;
|
|
146
146
|
}
|
|
147
147
|
}
|
|
@@ -150,7 +150,7 @@ export var EntityMetadata;
|
|
|
150
150
|
entity.indexes = entity.indexes || [];
|
|
151
151
|
index = {
|
|
152
152
|
...index,
|
|
153
|
-
columns: Array.isArray(index.columns) ? index.columns : [index.columns]
|
|
153
|
+
columns: Array.isArray(index.columns) ? index.columns : [index.columns],
|
|
154
154
|
};
|
|
155
155
|
if (index.primary)
|
|
156
156
|
entity.indexes.forEach(idx => delete idx.primary);
|
|
@@ -163,7 +163,7 @@ export var EntityMetadata;
|
|
|
163
163
|
source: entity.ctor,
|
|
164
164
|
sourceKey: propertyKey,
|
|
165
165
|
target,
|
|
166
|
-
targetKey
|
|
166
|
+
targetKey,
|
|
167
167
|
});
|
|
168
168
|
entity.foreignKeys.push(fk);
|
|
169
169
|
}
|
|
@@ -252,7 +252,7 @@ export var EntityMetadata;
|
|
|
252
252
|
let l = association;
|
|
253
253
|
let i = 1;
|
|
254
254
|
while (l) {
|
|
255
|
-
l.name = entity.name + '.' + propertyKey + '#' +
|
|
255
|
+
l.name = entity.name + '.' + propertyKey + '#' + i++;
|
|
256
256
|
l = l.next;
|
|
257
257
|
}
|
|
258
258
|
entity.fields[propertyKey.toLowerCase()] = prop;
|
|
@@ -264,7 +264,7 @@ export var EntityMetadata;
|
|
|
264
264
|
...options,
|
|
265
265
|
columns: Array.isArray(column) ? column : [column],
|
|
266
266
|
unique: true,
|
|
267
|
-
primary: true
|
|
267
|
+
primary: true,
|
|
268
268
|
});
|
|
269
269
|
}
|
|
270
270
|
EntityMetadata.setPrimaryKeys = setPrimaryKeys;
|
|
@@ -7,7 +7,7 @@ export class LinkChain {
|
|
|
7
7
|
target,
|
|
8
8
|
source: null,
|
|
9
9
|
sourceKey,
|
|
10
|
-
targetKey: targetKey
|
|
10
|
+
targetKey: targetKey,
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
where(conditions) {
|
|
@@ -30,7 +30,7 @@ export class LinkChain {
|
|
|
30
30
|
source: this.current.target,
|
|
31
31
|
target,
|
|
32
32
|
sourceKey: parentKey,
|
|
33
|
-
targetKey: targetKey
|
|
33
|
+
targetKey: targetKey,
|
|
34
34
|
});
|
|
35
35
|
child.prior = this.current;
|
|
36
36
|
this.current.next = child;
|
|
@@ -22,8 +22,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
22
22
|
create(values, options) {
|
|
23
23
|
return this._execute(async (connection) => {
|
|
24
24
|
const keyValue = await this._create(values, { ...options, connection, returning: true });
|
|
25
|
-
const result = keyValue &&
|
|
26
|
-
await this._find(keyValue, { ...options, connection });
|
|
25
|
+
const result = keyValue && (await this._find(keyValue, { ...options, connection }));
|
|
27
26
|
if (!result)
|
|
28
27
|
throw new Error('Unable to insert new row');
|
|
29
28
|
return result;
|
|
@@ -116,7 +115,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
116
115
|
const keyValues = await CreateCommand.execute({
|
|
117
116
|
...options,
|
|
118
117
|
entity: this._entity,
|
|
119
|
-
values
|
|
118
|
+
values,
|
|
120
119
|
});
|
|
121
120
|
if (options.returning && !keyValues)
|
|
122
121
|
throw new Error('Unable to insert new row');
|
|
@@ -133,13 +132,13 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
133
132
|
return !!(await CountCommand.execute({
|
|
134
133
|
...options,
|
|
135
134
|
filter,
|
|
136
|
-
entity: this._entity
|
|
135
|
+
entity: this._entity,
|
|
137
136
|
}));
|
|
138
137
|
}
|
|
139
138
|
async _count(options) {
|
|
140
139
|
return CountCommand.execute({
|
|
141
140
|
...options,
|
|
142
|
-
entity: this._entity
|
|
141
|
+
entity: this._entity,
|
|
143
142
|
});
|
|
144
143
|
}
|
|
145
144
|
async _findMany(options) {
|
|
@@ -151,7 +150,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
151
150
|
async _findOne(options) {
|
|
152
151
|
const rows = await this._findMany({
|
|
153
152
|
...options,
|
|
154
|
-
limit: 1
|
|
153
|
+
limit: 1,
|
|
155
154
|
});
|
|
156
155
|
return rows && rows[0];
|
|
157
156
|
}
|
|
@@ -184,7 +183,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
184
183
|
...options,
|
|
185
184
|
entity: this._entity,
|
|
186
185
|
filter: options?.filter,
|
|
187
|
-
params: options?.params
|
|
186
|
+
params: options?.params,
|
|
188
187
|
});
|
|
189
188
|
}
|
|
190
189
|
async _update(keyValue, values, options) {
|
|
@@ -204,7 +203,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
204
203
|
...options,
|
|
205
204
|
entity: this._entity,
|
|
206
205
|
values: updateValues,
|
|
207
|
-
filter
|
|
206
|
+
filter,
|
|
208
207
|
});
|
|
209
208
|
return rowsAffected ? keyValues : undefined;
|
|
210
209
|
}
|
|
@@ -214,7 +213,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
214
213
|
return await UpdateCommand.execute({
|
|
215
214
|
...options,
|
|
216
215
|
entity: this._entity,
|
|
217
|
-
values
|
|
216
|
+
values,
|
|
218
217
|
});
|
|
219
218
|
}
|
|
220
219
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export function applyMixins(derivedCtor, baseCtor, filter) {
|
|
2
2
|
for (const name of Object.getOwnPropertyNames(baseCtor.prototype)) {
|
|
3
|
-
if (
|
|
4
|
-
|
|
3
|
+
if (name === 'constructor' ||
|
|
4
|
+
name === '__proto__' ||
|
|
5
|
+
name === 'toJSON' ||
|
|
6
|
+
name === 'toString' ||
|
|
7
|
+
(filter && !filter(name)))
|
|
5
8
|
continue;
|
|
6
|
-
Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name) ||
|
|
7
|
-
Object.create(null));
|
|
9
|
+
Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name) || Object.create(null));
|
|
8
10
|
}
|
|
9
11
|
}
|
|
@@ -4,7 +4,7 @@ export function extractKeyValues(entityDef, valueOrInstance, keepOther) {
|
|
|
4
4
|
const primaryIndex = EntityMetadata.getPrimaryIndex(entityDef);
|
|
5
5
|
if (!primaryIndex)
|
|
6
6
|
throw new Error(`No primary fields defined for "${entityDef.name}" entity`);
|
|
7
|
-
const validateCol =
|
|
7
|
+
const validateCol = k => {
|
|
8
8
|
const col = EntityMetadata.getField(entityDef, k);
|
|
9
9
|
if (!col)
|
|
10
10
|
throw new Error(`Unknown column (${k}) defined as primary key in entity "${entityDef.name}"`);
|
|
@@ -17,19 +17,19 @@ const padZero = (n) => (n < 9 ? '0' : '') + n;
|
|
|
17
17
|
function serializeDataValue(dataType, v) {
|
|
18
18
|
if (v == null)
|
|
19
19
|
return;
|
|
20
|
-
if (v instanceof Date &&
|
|
21
|
-
(
|
|
22
|
-
|
|
23
|
-
padZero(v.getMonth() + 1) +
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
padZero(v.
|
|
20
|
+
if (v instanceof Date && (dataType === DataType.DATE || dataType === DataType.TIMESTAMP)) {
|
|
21
|
+
return (v.getFullYear() +
|
|
22
|
+
'-' +
|
|
23
|
+
padZero(v.getMonth() + 1) +
|
|
24
|
+
'-' +
|
|
25
|
+
padZero(v.getDate()) +
|
|
26
|
+
(dataType === DataType.TIMESTAMP
|
|
27
|
+
? 'T' + padZero(v.getHours()) + ':' + padZero(v.getMinutes()) + ':' + padZero(v.getSeconds())
|
|
28
|
+
: ''));
|
|
28
29
|
}
|
|
29
30
|
if (v instanceof Buffer)
|
|
30
31
|
return v.toString('base64');
|
|
31
|
-
if (typeof v === 'number' && (dataType === DataType.SMALLINT ||
|
|
32
|
-
dataType === DataType.INTEGER))
|
|
32
|
+
if (typeof v === 'number' && (dataType === DataType.SMALLINT || dataType === DataType.INTEGER))
|
|
33
33
|
return Math.trunc(v);
|
|
34
34
|
if (typeof v === 'bigint')
|
|
35
35
|
return v.toString();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqb/connect",
|
|
3
3
|
"description": "Multi-dialect database connection framework written with TypeScript",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.12.0",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Eray Hanoglu <e.hanoglu@panates.com>",
|
|
@@ -30,10 +30,11 @@
|
|
|
30
30
|
"clean": "npm run clean:src | npm run clean:dist | npm run clean:cover",
|
|
31
31
|
"clean:src": "ts-cleanup -s src --all",
|
|
32
32
|
"clean:dist": "rimraf ../../build/connectt",
|
|
33
|
-
"clean:cover": "rimraf ../../coverage/connect"
|
|
33
|
+
"clean:cover": "rimraf ../../coverage/connect",
|
|
34
|
+
"format": "prettier . --write --log-level=warn"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"debug": "^4.3.
|
|
37
|
+
"debug": "^4.3.5",
|
|
37
38
|
"lightning-pool": "^4.2.2",
|
|
38
39
|
"lodash": "^4.17.21",
|
|
39
40
|
"power-tasks": "^1.7.3",
|
|
@@ -41,16 +42,16 @@
|
|
|
41
42
|
"putil-merge": "^3.12.1",
|
|
42
43
|
"putil-promisify": "^1.10.1",
|
|
43
44
|
"putil-varhelpers": "^1.6.5",
|
|
44
|
-
"reflect-metadata": "^0.2.1",
|
|
45
45
|
"strict-typed-events": "^2.3.3",
|
|
46
|
-
"ts-gems": "^3.
|
|
46
|
+
"ts-gems": "^3.4.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/debug": "^4.1.12",
|
|
50
|
-
"@types/lodash": "^4.17.
|
|
50
|
+
"@types/lodash": "^4.17.4"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@sqb/builder": "^4.
|
|
53
|
+
"@sqb/builder": "^4.12.0",
|
|
54
|
+
"reflect-metadata": "^0.2.2"
|
|
54
55
|
},
|
|
55
56
|
"engines": {
|
|
56
57
|
"node": ">=16.0",
|
|
@@ -28,8 +28,8 @@ export declare namespace Entity {
|
|
|
28
28
|
function mixin<A, B, C, D>(derivedCtor: Type<A>, baseB: Type<B>, baseC: Type<C>, baseD: Type<D>): Type<A & B & C & D>;
|
|
29
29
|
function mixin<A, B, C, D, E>(derivedCtor: Type<A>, baseB: Type<B>, baseC: Type<C>, baseD: Type<D>, baseE: Type<E>): Type<A & B & C & D & E>;
|
|
30
30
|
function mixin<A, B, C, D, E, F>(derivedCtor: Type<A>, baseB: Type<B>, baseC: Type<C>, baseD: Type<D>, baseE: Type<E>, baseF: Type<F>): Type<A & B & C & D & E & F>;
|
|
31
|
-
function Pick<T, K extends keyof T>(classRef: Type<T>, keys: readonly K[]): Type<Pick<T, typeof keys[number]>>;
|
|
32
|
-
function Omit<T, K extends keyof T>(classRef: Type<T>, keys: readonly K[]): Type<Omit<T, typeof keys[number]>>;
|
|
31
|
+
function Pick<T, K extends keyof T>(classRef: Type<T>, keys: readonly K[]): Type<Pick<T, (typeof keys)[number]>>;
|
|
32
|
+
function Omit<T, K extends keyof T>(classRef: Type<T>, keys: readonly K[]): Type<Omit<T, (typeof keys)[number]>>;
|
|
33
33
|
function Union<A, B>(baseA: Type<A>, baseB: Type<B>): Type<A & B>;
|
|
34
34
|
function Union<A, B, C>(baseA: Type<A>, baseB: Type<B>, baseC: Type<C>): Type<A & B & C>;
|
|
35
35
|
function Union<A, B, C, D>(baseA: Type<A>, baseB: Type<B>, baseC: Type<C>, baseD: Type<D>): Type<A & B & C & D>;
|
package/types/orm/orm.type.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type ColumnAutoGenerationStrategy = 'increment' | 'uuid' | 'rowid' | 'tim
|
|
|
8
8
|
export type ColumnTransformFunction = (value: any, name: string) => any;
|
|
9
9
|
export type TypeResolver<T> = () => Type<T> | Promise<Type<T>>;
|
|
10
10
|
export type TypeThunk<T = any> = Type<T> | TypeResolver<T>;
|
|
11
|
-
export type EnumValue =
|
|
11
|
+
export type EnumValue = FieldValue[] | Object;
|
|
12
12
|
export type FieldValue = string | number | boolean | Date | null;
|
|
13
13
|
export type DefaultValueGetter = (obj?: any) => FieldValue | undefined;
|
|
14
14
|
export interface AssociationSettings {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PartialDTO, PatchDTO, StrictOmit, Type } from 'ts-gems';
|
|
2
|
+
import { LogicalOperator } from '@sqb/builder';
|
|
2
3
|
import { FieldInfoMap } from '../client/field-info-map.js';
|
|
3
4
|
import { SqbClient } from '../client/sqb-client.js';
|
|
4
5
|
import { SqbConnection } from '../client/sqb-connection.js';
|
|
@@ -10,7 +11,7 @@ interface Projection {
|
|
|
10
11
|
include?: string[];
|
|
11
12
|
}
|
|
12
13
|
interface Filtering {
|
|
13
|
-
filter?:
|
|
14
|
+
filter?: LogicalOperator | LogicalOperator[] | object | object[];
|
|
14
15
|
params?: any;
|
|
15
16
|
}
|
|
16
17
|
export declare namespace Repository {
|