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