@sqb/connect 4.14.1 → 4.15.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/esm/client/adapter.js +2 -1
- package/esm/client/cursor-stream.js +9 -4
- package/esm/client/cursor.js +22 -17
- package/esm/client/extensions.js +5 -1
- package/esm/client/field-info-map.js +5 -1
- package/esm/client/helpers.js +19 -12
- package/esm/client/sqb-client.js +32 -27
- package/esm/client/sqb-connection.js +41 -36
- package/esm/client/types.js +5 -1
- package/esm/index.js +40 -32
- package/esm/orm/backward.js +19 -12
- package/esm/orm/base-entity.js +10 -6
- package/esm/orm/commands/command.helper.js +34 -28
- package/esm/orm/commands/count.command.js +10 -6
- package/esm/orm/commands/create.command.js +18 -14
- package/esm/orm/commands/delete.command.js +10 -6
- package/esm/orm/commands/find.command.js +34 -30
- package/esm/orm/commands/row-converter.js +7 -3
- package/esm/orm/commands/update.command.js +18 -14
- package/esm/orm/decorators/column.decorator.js +10 -7
- package/esm/orm/decorators/embedded.decorator.js +7 -4
- package/esm/orm/decorators/entity.decorator.js +56 -53
- package/esm/orm/decorators/events.decorator.js +27 -19
- package/esm/orm/decorators/foreignkey.decorator.js +7 -4
- package/esm/orm/decorators/index.decorator.js +9 -6
- package/esm/orm/decorators/link.decorator.js +11 -8
- package/esm/orm/decorators/primarykey.decorator.js +11 -8
- package/esm/orm/decorators/transform.decorator.js +11 -7
- package/esm/orm/model/association-field-metadata.js +8 -4
- package/esm/orm/model/association-node.js +6 -2
- package/esm/orm/model/association.js +20 -16
- package/esm/orm/model/column-field-metadata.js +8 -4
- package/esm/orm/model/embedded-field-metadata.js +7 -4
- package/esm/orm/model/entity-metadata.js +50 -47
- package/esm/orm/model/field-metadata.js +2 -1
- package/esm/orm/model/index-metadata.js +2 -1
- package/esm/orm/model/link-chain.js +8 -4
- package/esm/orm/orm.const.js +6 -3
- package/esm/orm/orm.type.js +2 -1
- package/esm/orm/repository.class.js +26 -22
- package/esm/orm/util/apply-mixins.js +4 -1
- package/esm/orm/util/extract-keyvalues.js +9 -6
- package/esm/orm/util/orm.helper.js +20 -10
- package/esm/orm/util/parse-fields-projection.js +11 -6
- package/esm/orm/util/serialize-field.js +13 -10
- package/package.json +28 -22
- package/cjs/package.json +0 -3
package/esm/client/adapter.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CursorStream = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
6
|
+
const stream_1 = require("stream");
|
|
3
7
|
const inspect = Symbol.for('nodejs.util.inspect.custom');
|
|
4
|
-
const debug =
|
|
5
|
-
|
|
8
|
+
const debug = (0, debug_1.default)('sqb:cursorstream');
|
|
9
|
+
class CursorStream extends stream_1.Readable {
|
|
6
10
|
constructor(cursor, options) {
|
|
7
11
|
super(options);
|
|
8
12
|
this._rowNum = -1;
|
|
@@ -94,3 +98,4 @@ export class CursorStream extends Readable {
|
|
|
94
98
|
}
|
|
95
99
|
}
|
|
96
100
|
}
|
|
101
|
+
exports.CursorStream = CursorStream;
|
package/esm/client/cursor.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Cursor = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
6
|
+
const doublylinked_1 = tslib_1.__importDefault(require("doublylinked"));
|
|
7
|
+
const power_tasks_1 = require("power-tasks");
|
|
8
|
+
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
9
|
+
const strict_typed_events_1 = require("strict-typed-events");
|
|
10
|
+
const cursor_stream_js_1 = require("./cursor-stream.js");
|
|
11
|
+
const helpers_js_1 = require("./helpers.js");
|
|
12
|
+
const debug = (0, debug_1.default)('sqb:cursor');
|
|
13
|
+
class Cursor extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_typed_events_1.AsyncEventEmitter) {
|
|
10
14
|
constructor(connection, fields, adapterCursor, request) {
|
|
11
15
|
super();
|
|
12
|
-
this._taskQueue = new TaskQueue();
|
|
13
|
-
this._fetchCache = new
|
|
16
|
+
this._taskQueue = new power_tasks_1.TaskQueue();
|
|
17
|
+
this._fetchCache = new doublylinked_1.default();
|
|
14
18
|
this._rowNum = 0;
|
|
15
19
|
this._fetchedAll = false;
|
|
16
20
|
this._fetchedRows = 0;
|
|
@@ -75,7 +79,7 @@ export class Cursor extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
75
79
|
if (this.fetchedRows)
|
|
76
80
|
throw new Error('Cache can be enabled before fetching rows');
|
|
77
81
|
if (!this._cache)
|
|
78
|
-
this._cache = new
|
|
82
|
+
this._cache = new doublylinked_1.default();
|
|
79
83
|
}
|
|
80
84
|
/**
|
|
81
85
|
* Closes cursor
|
|
@@ -157,7 +161,7 @@ export class Cursor extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
157
161
|
* Creates and returns a readable stream.
|
|
158
162
|
*/
|
|
159
163
|
toStream(options) {
|
|
160
|
-
return new CursorStream(this, options);
|
|
164
|
+
return new cursor_stream_js_1.CursorStream(this, options);
|
|
161
165
|
}
|
|
162
166
|
toString() {
|
|
163
167
|
return '[object ' + Object.getPrototypeOf(this).constructor.name + ']';
|
|
@@ -169,7 +173,7 @@ export class Cursor extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
169
173
|
*
|
|
170
174
|
*/
|
|
171
175
|
async _seek(step, silent) {
|
|
172
|
-
step = coerceToInt(step, 0);
|
|
176
|
+
step = (0, putil_varhelpers_1.coerceToInt)(step, 0);
|
|
173
177
|
if (!step || (step > 0 && this.isClosed))
|
|
174
178
|
return this.rowNum;
|
|
175
179
|
if (step < 0 && !this._cache)
|
|
@@ -226,9 +230,9 @@ export class Cursor extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
226
230
|
debug('Fetched %d rows from database', rows.length);
|
|
227
231
|
// Normalize rows
|
|
228
232
|
rows = this._request.objectRows
|
|
229
|
-
? normalizeRowsToObjectRows(this._fields, this._intlcur.rowType, rows, this._request)
|
|
230
|
-
: normalizeRowsToArrayRows(this._fields, this._intlcur.rowType, rows, this._request);
|
|
231
|
-
callFetchHooks(rows, this._request);
|
|
233
|
+
? (0, helpers_js_1.normalizeRowsToObjectRows)(this._fields, this._intlcur.rowType, rows, this._request)
|
|
234
|
+
: (0, helpers_js_1.normalizeRowsToArrayRows)(this._fields, this._intlcur.rowType, rows, this._request);
|
|
235
|
+
(0, helpers_js_1.callFetchHooks)(rows, this._request);
|
|
232
236
|
for (const [idx, row] of rows.entries()) {
|
|
233
237
|
this.emit('fetch', row, this._rowNum + idx + 1);
|
|
234
238
|
}
|
|
@@ -245,3 +249,4 @@ export class Cursor extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
245
249
|
return this.close();
|
|
246
250
|
}
|
|
247
251
|
}
|
|
252
|
+
exports.Cursor = Cursor;
|
package/esm/client/extensions.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AdapterRegistry = void 0;
|
|
4
|
+
class AdapterRegistry {
|
|
2
5
|
static get size() {
|
|
3
6
|
return this.adapters.length;
|
|
4
7
|
}
|
|
@@ -34,4 +37,5 @@ export class AdapterRegistry {
|
|
|
34
37
|
return !!this.adapters.find(x => x === extension);
|
|
35
38
|
}
|
|
36
39
|
}
|
|
40
|
+
exports.AdapterRegistry = AdapterRegistry;
|
|
37
41
|
AdapterRegistry.adapters = [];
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FieldInfoMap = void 0;
|
|
4
|
+
class FieldInfoMap {
|
|
2
5
|
constructor() {
|
|
3
6
|
Object.defineProperty(this, '_obj', {
|
|
4
7
|
enumerable: false,
|
|
@@ -46,3 +49,4 @@ export class FieldInfoMap {
|
|
|
46
49
|
return { ...this._obj };
|
|
47
50
|
}
|
|
48
51
|
}
|
|
52
|
+
exports.FieldInfoMap = FieldInfoMap;
|
package/esm/client/helpers.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyNamingStrategy = applyNamingStrategy;
|
|
4
|
+
exports.wrapAdapterFields = wrapAdapterFields;
|
|
5
|
+
exports.normalizeRowsToObjectRows = normalizeRowsToObjectRows;
|
|
6
|
+
exports.normalizeRowsToArrayRows = normalizeRowsToArrayRows;
|
|
7
|
+
exports.callFetchHooks = callFetchHooks;
|
|
8
|
+
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
9
|
+
const field_info_map_js_1 = require("./field-info-map.js");
|
|
10
|
+
function applyNamingStrategy(value, namingStrategy) {
|
|
4
11
|
if (typeof namingStrategy === 'string' && namingStrategy !== 'original') {
|
|
5
12
|
switch (namingStrategy.toLowerCase()) {
|
|
6
13
|
case 'lowercase':
|
|
@@ -9,13 +16,13 @@ export function applyNamingStrategy(value, namingStrategy) {
|
|
|
9
16
|
return value.toUpperCase();
|
|
10
17
|
case 'camelcase':
|
|
11
18
|
if (!value.match(/[a-z]/))
|
|
12
|
-
return camelCase(value.toLowerCase());
|
|
13
|
-
value = camelCase(value);
|
|
19
|
+
return (0, putil_varhelpers_1.camelCase)(value.toLowerCase());
|
|
20
|
+
value = (0, putil_varhelpers_1.camelCase)(value);
|
|
14
21
|
return value[0].toLowerCase() + value.substring(1);
|
|
15
22
|
case 'pascalcase':
|
|
16
23
|
if (!value.match(/[a-z]/))
|
|
17
|
-
return pascalCase(value.toLowerCase());
|
|
18
|
-
return pascalCase(value);
|
|
24
|
+
return (0, putil_varhelpers_1.pascalCase)(value.toLowerCase());
|
|
25
|
+
return (0, putil_varhelpers_1.pascalCase)(value);
|
|
19
26
|
default:
|
|
20
27
|
break;
|
|
21
28
|
}
|
|
@@ -24,13 +31,13 @@ export function applyNamingStrategy(value, namingStrategy) {
|
|
|
24
31
|
return namingStrategy(value);
|
|
25
32
|
return value;
|
|
26
33
|
}
|
|
27
|
-
|
|
34
|
+
function wrapAdapterFields(oldFields, fieldNaming) {
|
|
28
35
|
const mapFieldInfo = (f, index) => {
|
|
29
36
|
const name = applyNamingStrategy(f.fieldName, fieldNaming);
|
|
30
37
|
if (name)
|
|
31
38
|
return { ...f, name, index };
|
|
32
39
|
};
|
|
33
|
-
const result = new FieldInfoMap();
|
|
40
|
+
const result = new field_info_map_js_1.FieldInfoMap();
|
|
34
41
|
let i = 0;
|
|
35
42
|
oldFields.forEach(f => {
|
|
36
43
|
const x = mapFieldInfo(f, i);
|
|
@@ -41,10 +48,10 @@ export function wrapAdapterFields(oldFields, fieldNaming) {
|
|
|
41
48
|
});
|
|
42
49
|
return result;
|
|
43
50
|
}
|
|
44
|
-
|
|
51
|
+
function normalizeRowsToObjectRows(fields, rowType, oldRows, options) {
|
|
45
52
|
return normalizeRows(fields, rowType, oldRows, { ...options, objectRows: true });
|
|
46
53
|
}
|
|
47
|
-
|
|
54
|
+
function normalizeRowsToArrayRows(fields, rowType, oldRows, options) {
|
|
48
55
|
return normalizeRows(fields, rowType, oldRows, { ...options, objectRows: false });
|
|
49
56
|
}
|
|
50
57
|
function normalizeRows(fields, rowType, oldRows, options) {
|
|
@@ -115,7 +122,7 @@ function normalizeRows(fields, rowType, oldRows, options) {
|
|
|
115
122
|
return r;
|
|
116
123
|
});
|
|
117
124
|
}
|
|
118
|
-
|
|
125
|
+
function callFetchHooks(rows, request) {
|
|
119
126
|
const fetchHooks = request.fetchHooks;
|
|
120
127
|
if (!fetchHooks)
|
|
121
128
|
return;
|
package/esm/client/sqb-client.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SqbClient = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
6
|
+
const lightning_pool_1 = require("lightning-pool");
|
|
7
|
+
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
8
|
+
const strict_typed_events_1 = require("strict-typed-events");
|
|
9
|
+
const entity_metadata_js_1 = require("../orm/model/entity-metadata.js");
|
|
10
|
+
const repository_class_js_1 = require("../orm/repository.class.js");
|
|
11
|
+
const extensions_js_1 = require("./extensions.js");
|
|
12
|
+
const sqb_connection_js_1 = require("./sqb-connection.js");
|
|
13
|
+
const debug = (0, debug_1.default)('sqb:client');
|
|
10
14
|
const inspect = Symbol.for('nodejs.util.inspect.custom');
|
|
11
|
-
|
|
15
|
+
class SqbClient extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_typed_events_1.AsyncEventEmitter) {
|
|
12
16
|
constructor(config) {
|
|
13
17
|
super();
|
|
14
18
|
this._entities = {};
|
|
@@ -16,12 +20,12 @@ export class SqbClient extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
16
20
|
throw new TypeError('Configuration object required');
|
|
17
21
|
let adapter;
|
|
18
22
|
if (config.driver) {
|
|
19
|
-
adapter = AdapterRegistry.findDriver(config.driver);
|
|
23
|
+
adapter = extensions_js_1.AdapterRegistry.findDriver(config.driver);
|
|
20
24
|
if (!adapter)
|
|
21
25
|
throw new Error(`No database adapter registered for "${config.driver}" driver`);
|
|
22
26
|
}
|
|
23
27
|
else if (config.dialect) {
|
|
24
|
-
adapter = AdapterRegistry.findDialect(config.dialect);
|
|
28
|
+
adapter = extensions_js_1.AdapterRegistry.findDialect(config.dialect);
|
|
25
29
|
if (!adapter)
|
|
26
30
|
throw new Error(`No database adapter registered for "${config.dialect}" dialect`);
|
|
27
31
|
}
|
|
@@ -31,16 +35,16 @@ export class SqbClient extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
31
35
|
this._defaults = config.defaults || {};
|
|
32
36
|
const poolOptions = {};
|
|
33
37
|
const popts = config.pool || {};
|
|
34
|
-
poolOptions.acquireMaxRetries = coerceToInt(popts.acquireMaxRetries, 0);
|
|
35
|
-
poolOptions.acquireRetryWait = coerceToInt(popts.acquireRetryWait, 2000);
|
|
36
|
-
poolOptions.acquireTimeoutMillis = coerceToInt(popts.acquireTimeoutMillis, 0);
|
|
37
|
-
poolOptions.idleTimeoutMillis = coerceToInt(popts.idleTimeoutMillis, 30000);
|
|
38
|
-
poolOptions.max = coerceToInt(popts.max, 10);
|
|
39
|
-
poolOptions.maxQueue = coerceToInt(popts.maxQueue, 1000);
|
|
40
|
-
poolOptions.max = coerceToInt(popts.max, 10);
|
|
41
|
-
poolOptions.min = coerceToInt(popts.min, 0);
|
|
42
|
-
poolOptions.minIdle = coerceToInt(popts.minIdle, 0);
|
|
43
|
-
poolOptions.validation = coerceToBoolean(popts.validation, false);
|
|
38
|
+
poolOptions.acquireMaxRetries = (0, putil_varhelpers_1.coerceToInt)(popts.acquireMaxRetries, 0);
|
|
39
|
+
poolOptions.acquireRetryWait = (0, putil_varhelpers_1.coerceToInt)(popts.acquireRetryWait, 2000);
|
|
40
|
+
poolOptions.acquireTimeoutMillis = (0, putil_varhelpers_1.coerceToInt)(popts.acquireTimeoutMillis, 0);
|
|
41
|
+
poolOptions.idleTimeoutMillis = (0, putil_varhelpers_1.coerceToInt)(popts.idleTimeoutMillis, 30000);
|
|
42
|
+
poolOptions.max = (0, putil_varhelpers_1.coerceToInt)(popts.max, 10);
|
|
43
|
+
poolOptions.maxQueue = (0, putil_varhelpers_1.coerceToInt)(popts.maxQueue, 1000);
|
|
44
|
+
poolOptions.max = (0, putil_varhelpers_1.coerceToInt)(popts.max, 10);
|
|
45
|
+
poolOptions.min = (0, putil_varhelpers_1.coerceToInt)(popts.min, 0);
|
|
46
|
+
poolOptions.minIdle = (0, putil_varhelpers_1.coerceToInt)(popts.minIdle, 0);
|
|
47
|
+
poolOptions.validation = (0, putil_varhelpers_1.coerceToBoolean)(popts.validation, false);
|
|
44
48
|
const cfg = { ...config };
|
|
45
49
|
const poolFactory = {
|
|
46
50
|
create: () => adapter.connect(cfg),
|
|
@@ -48,7 +52,7 @@ export class SqbClient extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
48
52
|
reset: async (instance) => instance.reset(),
|
|
49
53
|
validate: instance => instance.test(),
|
|
50
54
|
};
|
|
51
|
-
this._pool = createPool(poolFactory, poolOptions);
|
|
55
|
+
this._pool = (0, lightning_pool_1.createPool)(poolFactory, poolOptions);
|
|
52
56
|
this._pool.on('closing', () => this.emit('closing'));
|
|
53
57
|
this._pool.on('close', () => this.emit('close'));
|
|
54
58
|
this._pool.on('terminate', () => this.emit('terminate'));
|
|
@@ -74,7 +78,7 @@ export class SqbClient extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
74
78
|
* Returns true if pool is closed
|
|
75
79
|
*/
|
|
76
80
|
get isClosed() {
|
|
77
|
-
return this._pool.state === PoolState.CLOSED;
|
|
81
|
+
return this._pool.state === lightning_pool_1.PoolState.CLOSED;
|
|
78
82
|
}
|
|
79
83
|
get pool() {
|
|
80
84
|
return this._pool;
|
|
@@ -93,7 +97,7 @@ export class SqbClient extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
93
97
|
const options = arg1;
|
|
94
98
|
const adapterConnection = await this._pool.acquire();
|
|
95
99
|
const opts = { autoCommit: this.defaults.autoCommit, ...options };
|
|
96
|
-
const connection = new SqbConnection(this, adapterConnection, opts);
|
|
100
|
+
const connection = new sqb_connection_js_1.SqbConnection(this, adapterConnection, opts);
|
|
97
101
|
await this.emitAsyncSerial('acquire', connection);
|
|
98
102
|
connection.on('execute', (request) => this.emit('execute', request));
|
|
99
103
|
connection.on('error', (error) => this.emit('error', error));
|
|
@@ -146,10 +150,10 @@ export class SqbClient extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
146
150
|
}
|
|
147
151
|
else
|
|
148
152
|
ctor = entity;
|
|
149
|
-
const entityDef = EntityMetadata.get(ctor);
|
|
153
|
+
const entityDef = entity_metadata_js_1.EntityMetadata.get(ctor);
|
|
150
154
|
if (!entityDef)
|
|
151
155
|
throw new Error(`You must provide an @Entity annotated constructor`);
|
|
152
|
-
return new Repository(entityDef, this, opts?.schema);
|
|
156
|
+
return new repository_class_js_1.Repository(entityDef, this, opts?.schema);
|
|
153
157
|
}
|
|
154
158
|
getEntity(name) {
|
|
155
159
|
return this._entities[name];
|
|
@@ -161,3 +165,4 @@ export class SqbClient extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
161
165
|
return this.toString();
|
|
162
166
|
}
|
|
163
167
|
}
|
|
168
|
+
exports.SqbClient = SqbClient;
|
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SqbConnection = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const builder_1 = require("@sqb/builder");
|
|
6
|
+
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
7
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
8
|
+
const power_tasks_1 = require("power-tasks");
|
|
9
|
+
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
10
|
+
const strict_typed_events_1 = require("strict-typed-events");
|
|
11
|
+
const entity_metadata_js_1 = require("../orm/model/entity-metadata.js");
|
|
12
|
+
const repository_class_js_1 = require("../orm/repository.class.js");
|
|
13
|
+
const cursor_js_1 = require("./cursor.js");
|
|
14
|
+
const helpers_js_1 = require("./helpers.js");
|
|
15
|
+
const debug = (0, debug_1.default)('sqb:connection');
|
|
16
|
+
class SqbConnection extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_typed_events_1.AsyncEventEmitter) {
|
|
13
17
|
constructor(client, adapterConnection, options) {
|
|
14
18
|
super();
|
|
15
19
|
this.client = client;
|
|
16
|
-
this._tasks = new TaskQueue();
|
|
20
|
+
this._tasks = new power_tasks_1.TaskQueue();
|
|
17
21
|
this._inTransaction = false;
|
|
18
22
|
this._refCount = 1;
|
|
19
23
|
this._intlcon = adapterConnection;
|
|
@@ -94,26 +98,26 @@ export class SqbConnection extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
94
98
|
}
|
|
95
99
|
else
|
|
96
100
|
ctor = entity;
|
|
97
|
-
const entityDef = EntityMetadata.get(ctor);
|
|
101
|
+
const entityDef = entity_metadata_js_1.EntityMetadata.get(ctor);
|
|
98
102
|
if (!entityDef)
|
|
99
103
|
throw new Error(`You must provide an @Entity annotated constructor`);
|
|
100
|
-
return new Repository(entityDef, this, opts?.schema);
|
|
104
|
+
return new repository_class_js_1.Repository(entityDef, this, opts?.schema);
|
|
101
105
|
}
|
|
102
106
|
async getSchema() {
|
|
103
|
-
|
|
104
|
-
|
|
107
|
+
assert_1.default.ok(this._intlcon, `Can't set schema, because connection is released`);
|
|
108
|
+
assert_1.default.ok(this._intlcon.getSchema, `${this.client.dialect} adapter does have Schema support`);
|
|
105
109
|
return await this._intlcon.getSchema();
|
|
106
110
|
}
|
|
107
111
|
async setSchema(schema) {
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
assert_1.default.ok(this._intlcon, `Can't set schema, because connection is released`);
|
|
113
|
+
assert_1.default.ok(this._intlcon.setSchema, `${this.client.dialect} adapter does have Schema support`);
|
|
110
114
|
await this._intlcon.setSchema(schema);
|
|
111
115
|
}
|
|
112
116
|
/**
|
|
113
117
|
* Executes a query
|
|
114
118
|
*/
|
|
115
119
|
async _execute(query, options) {
|
|
116
|
-
|
|
120
|
+
assert_1.default.ok(this._intlcon, `Can't execute query, because connection is released`);
|
|
117
121
|
const intlcon = this._intlcon;
|
|
118
122
|
this.retain();
|
|
119
123
|
try {
|
|
@@ -140,16 +144,16 @@ export class SqbConnection extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
140
144
|
throw new Error('Adapter did not returned fields info');
|
|
141
145
|
if (!response.rowType)
|
|
142
146
|
throw new Error('Adapter did not returned rowType');
|
|
143
|
-
result.fields = wrapAdapterFields(response.fields, request.fieldNaming);
|
|
147
|
+
result.fields = (0, helpers_js_1.wrapAdapterFields)(response.fields, request.fieldNaming);
|
|
144
148
|
result.rowType = response.rowType;
|
|
145
149
|
if (response.rows) {
|
|
146
150
|
result.rows = request.objectRows
|
|
147
|
-
? normalizeRowsToObjectRows(result.fields, response.rowType, response.rows, request)
|
|
148
|
-
: normalizeRowsToArrayRows(result.fields, response.rowType, response.rows, request);
|
|
149
|
-
callFetchHooks(result.rows, request);
|
|
151
|
+
? (0, helpers_js_1.normalizeRowsToObjectRows)(result.fields, response.rowType, response.rows, request)
|
|
152
|
+
: (0, helpers_js_1.normalizeRowsToArrayRows)(result.fields, response.rowType, response.rows, request);
|
|
153
|
+
(0, helpers_js_1.callFetchHooks)(result.rows, request);
|
|
150
154
|
}
|
|
151
155
|
else if (response.cursor) {
|
|
152
|
-
const cursor = (result.cursor = new Cursor(this, result.fields, response.cursor, request));
|
|
156
|
+
const cursor = (result.cursor = new cursor_js_1.Cursor(this, result.fields, response.cursor, request));
|
|
153
157
|
const hook = () => cursor.close();
|
|
154
158
|
cursor.once('close', () => this.off('close', hook));
|
|
155
159
|
this.on('close', hook);
|
|
@@ -227,20 +231,20 @@ export class SqbConnection extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
227
231
|
sql: '',
|
|
228
232
|
autoCommit: this.inTransaction
|
|
229
233
|
? false
|
|
230
|
-
: coerceToBoolean(coalesce(options.autoCommit, this._options?.autoCommit, defaults.autoCommit), true),
|
|
231
|
-
cursor: coerceToBoolean(coalesce(options.cursor, defaults.cursor), false),
|
|
232
|
-
objectRows: coerceToBoolean(coalesce(options.objectRows, defaults.objectRows), true),
|
|
233
|
-
ignoreNulls: coerceToBoolean(coalesce(options.ignoreNulls, defaults.ignoreNulls), false),
|
|
234
|
-
fetchRows: coerceToInt(coalesce(options.fetchRows, defaults.fetchRows), 100),
|
|
235
|
-
fieldNaming: coalesce(options.namingStrategy, defaults.fieldNaming),
|
|
236
|
-
transform: coalesce(options.transform, defaults.transform),
|
|
237
|
-
showSql: coerceToBoolean(coalesce(options.showSql, defaults.showSql), false),
|
|
238
|
-
prettyPrint: coerceToBoolean(coalesce(options.prettyPrint, defaults.prettyPrint), false),
|
|
239
|
-
action: coerceToString(options.action),
|
|
234
|
+
: (0, putil_varhelpers_1.coerceToBoolean)((0, putil_varhelpers_1.coalesce)(options.autoCommit, this._options?.autoCommit, defaults.autoCommit), true),
|
|
235
|
+
cursor: (0, putil_varhelpers_1.coerceToBoolean)((0, putil_varhelpers_1.coalesce)(options.cursor, defaults.cursor), false),
|
|
236
|
+
objectRows: (0, putil_varhelpers_1.coerceToBoolean)((0, putil_varhelpers_1.coalesce)(options.objectRows, defaults.objectRows), true),
|
|
237
|
+
ignoreNulls: (0, putil_varhelpers_1.coerceToBoolean)((0, putil_varhelpers_1.coalesce)(options.ignoreNulls, defaults.ignoreNulls), false),
|
|
238
|
+
fetchRows: (0, putil_varhelpers_1.coerceToInt)((0, putil_varhelpers_1.coalesce)(options.fetchRows, defaults.fetchRows), 100),
|
|
239
|
+
fieldNaming: (0, putil_varhelpers_1.coalesce)(options.namingStrategy, defaults.fieldNaming),
|
|
240
|
+
transform: (0, putil_varhelpers_1.coalesce)(options.transform, defaults.transform),
|
|
241
|
+
showSql: (0, putil_varhelpers_1.coerceToBoolean)((0, putil_varhelpers_1.coalesce)(options.showSql, defaults.showSql), false),
|
|
242
|
+
prettyPrint: (0, putil_varhelpers_1.coerceToBoolean)((0, putil_varhelpers_1.coalesce)(options.prettyPrint, defaults.prettyPrint), false),
|
|
243
|
+
action: (0, putil_varhelpers_1.coerceToString)(options.action),
|
|
240
244
|
fetchAsString: options.fetchAsString,
|
|
241
245
|
};
|
|
242
246
|
request.ignoreNulls = request.ignoreNulls && request.objectRows;
|
|
243
|
-
if (query instanceof classes.Query) {
|
|
247
|
+
if (query instanceof builder_1.classes.Query) {
|
|
244
248
|
if (this._intlcon.onGenerateQuery)
|
|
245
249
|
this._intlcon.onGenerateQuery(request, query);
|
|
246
250
|
const q = query.generate({
|
|
@@ -273,3 +277,4 @@ export class SqbConnection extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
273
277
|
return request;
|
|
274
278
|
}
|
|
275
279
|
}
|
|
280
|
+
exports.SqbConnection = SqbConnection;
|
package/esm/client/types.js
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataType = void 0;
|
|
4
|
+
var builder_1 = require("@sqb/builder");
|
|
5
|
+
Object.defineProperty(exports, "DataType", { enumerable: true, get: function () { return builder_1.DataType; } });
|
package/esm/index.js
CHANGED
|
@@ -1,32 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEntityClass = exports.isEmbeddedField = exports.isColumnField = exports.isAssociationField = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
require("reflect-metadata");
|
|
6
|
+
tslib_1.__exportStar(require("./client/adapter.js"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./client/cursor.js"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./client/extensions.js"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./client/sqb-client.js"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./client/sqb-connection.js"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./client/types.js"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./orm/backward.js"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./orm/base-entity.js"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./orm/decorators/column.decorator.js"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./orm/decorators/embedded.decorator.js"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./orm/decorators/entity.decorator.js"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./orm/decorators/events.decorator.js"), exports);
|
|
18
|
+
tslib_1.__exportStar(require("./orm/decorators/foreignkey.decorator.js"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./orm/decorators/index.decorator.js"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./orm/decorators/link.decorator.js"), exports);
|
|
21
|
+
tslib_1.__exportStar(require("./orm/decorators/primarykey.decorator.js"), exports);
|
|
22
|
+
tslib_1.__exportStar(require("./orm/decorators/transform.decorator.js"), exports);
|
|
23
|
+
tslib_1.__exportStar(require("./orm/model/association.js"), exports);
|
|
24
|
+
tslib_1.__exportStar(require("./orm/model/association-field-metadata.js"), exports);
|
|
25
|
+
tslib_1.__exportStar(require("./orm/model/association-node.js"), exports);
|
|
26
|
+
tslib_1.__exportStar(require("./orm/model/column-field-metadata.js"), exports);
|
|
27
|
+
tslib_1.__exportStar(require("./orm/model/embedded-field-metadata.js"), exports);
|
|
28
|
+
tslib_1.__exportStar(require("./orm/model/entity-metadata.js"), exports);
|
|
29
|
+
tslib_1.__exportStar(require("./orm/model/field-metadata.js"), exports);
|
|
30
|
+
tslib_1.__exportStar(require("./orm/model/index-metadata.js"), exports);
|
|
31
|
+
tslib_1.__exportStar(require("./orm/model/link-chain.js"), exports);
|
|
32
|
+
tslib_1.__exportStar(require("./orm/orm.const.js"), exports);
|
|
33
|
+
tslib_1.__exportStar(require("./orm/orm.type.js"), exports);
|
|
34
|
+
tslib_1.__exportStar(require("./orm/repository.class.js"), exports);
|
|
35
|
+
var orm_helper_js_1 = require("./orm/util/orm.helper.js");
|
|
36
|
+
Object.defineProperty(exports, "isAssociationField", { enumerable: true, get: function () { return orm_helper_js_1.isAssociationField; } });
|
|
37
|
+
Object.defineProperty(exports, "isColumnField", { enumerable: true, get: function () { return orm_helper_js_1.isColumnField; } });
|
|
38
|
+
Object.defineProperty(exports, "isEmbeddedField", { enumerable: true, get: function () { return orm_helper_js_1.isEmbeddedField; } });
|
|
39
|
+
Object.defineProperty(exports, "isEntityClass", { enumerable: true, get: function () { return orm_helper_js_1.isEntityClass; } });
|
|
40
|
+
tslib_1.__exportStar(require("./orm/util/parse-fields-projection.js"), exports);
|
package/esm/orm/backward.js
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnionEntity = exports.PickEntity = exports.OmitEntity = void 0;
|
|
4
|
+
exports.getInsertColumnNames = getInsertColumnNames;
|
|
5
|
+
exports.getUpdateColumnNames = getUpdateColumnNames;
|
|
6
|
+
exports.getNonAssociationElementNames = getNonAssociationElementNames;
|
|
7
|
+
exports.mixinEntities = mixinEntities;
|
|
8
|
+
const entity_decorator_js_1 = require("./decorators/entity.decorator.js");
|
|
9
|
+
function getInsertColumnNames(ctor) {
|
|
10
|
+
return entity_decorator_js_1.Entity.getInsertColumnNames(ctor);
|
|
4
11
|
}
|
|
5
|
-
|
|
6
|
-
return Entity.getUpdateColumnNames(ctor);
|
|
12
|
+
function getUpdateColumnNames(ctor) {
|
|
13
|
+
return entity_decorator_js_1.Entity.getUpdateColumnNames(ctor);
|
|
7
14
|
}
|
|
8
|
-
|
|
9
|
-
return Entity.getNonAssociationFieldNames(ctor);
|
|
15
|
+
function getNonAssociationElementNames(ctor) {
|
|
16
|
+
return entity_decorator_js_1.Entity.getNonAssociationFieldNames(ctor);
|
|
10
17
|
}
|
|
11
|
-
|
|
18
|
+
function mixinEntities(derivedCtor, ...bases) {
|
|
12
19
|
// @ts-ignore
|
|
13
|
-
return Entity.mixin(derivedCtor, ...bases);
|
|
20
|
+
return entity_decorator_js_1.Entity.mixin(derivedCtor, ...bases);
|
|
14
21
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
exports.OmitEntity = entity_decorator_js_1.Entity.Omit;
|
|
23
|
+
exports.PickEntity = entity_decorator_js_1.Entity.Pick;
|
|
24
|
+
exports.UnionEntity = entity_decorator_js_1.Entity.Union;
|
package/esm/orm/base-entity.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseEntity = void 0;
|
|
4
|
+
const entity_decorator_js_1 = require("./decorators/entity.decorator.js");
|
|
5
|
+
const orm_const_js_1 = require("./orm.const.js");
|
|
6
|
+
class BaseEntity {
|
|
4
7
|
constructor(partial) {
|
|
5
|
-
const fields = Entity.getColumnFieldNames(Object.getPrototypeOf(this).constructor);
|
|
8
|
+
const fields = entity_decorator_js_1.Entity.getColumnFieldNames(Object.getPrototypeOf(this).constructor);
|
|
6
9
|
if (fields && partial) {
|
|
7
10
|
for (const k of fields)
|
|
8
11
|
if (partial[k] !== undefined)
|
|
@@ -10,11 +13,11 @@ export class BaseEntity {
|
|
|
10
13
|
}
|
|
11
14
|
}
|
|
12
15
|
async destroy() {
|
|
13
|
-
const repo = this[REPOSITORY_KEY];
|
|
16
|
+
const repo = this[orm_const_js_1.REPOSITORY_KEY];
|
|
14
17
|
return !!(repo && repo.destroy(this));
|
|
15
18
|
}
|
|
16
19
|
async exists() {
|
|
17
|
-
const repo = this[REPOSITORY_KEY];
|
|
20
|
+
const repo = this[orm_const_js_1.REPOSITORY_KEY];
|
|
18
21
|
return !!(repo && repo.exists(this));
|
|
19
22
|
}
|
|
20
23
|
toJSON() {
|
|
@@ -22,3 +25,4 @@ export class BaseEntity {
|
|
|
22
25
|
return this;
|
|
23
26
|
}
|
|
24
27
|
}
|
|
28
|
+
exports.BaseEntity = BaseEntity;
|