@sqb/connect 4.2.1 → 4.5.1
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 +67 -0
- package/{dist/client/Adapter.js → cjs/client/adapter.js} +0 -0
- package/{dist/client/CursorStream.js → cjs/client/cursor-stream.js} +5 -2
- package/{dist/client/Cursor.js → cjs/client/cursor.js} +18 -11
- package/{dist → cjs}/client/extensions.js +0 -0
- package/{dist/client/FieldInfoMap.js → cjs/client/field-info-map.js} +2 -0
- package/{dist → cjs}/client/helpers.js +2 -2
- package/{dist/client/SqbClient.js → cjs/client/sqb-client.js} +16 -10
- package/{dist/client/SqbConnection.js → cjs/client/sqb-connection.js} +17 -14
- package/{dist → cjs}/client/types.js +0 -0
- package/cjs/index.js +42 -0
- package/{dist → cjs}/orm/backward.js +8 -8
- package/{dist → cjs}/orm/base-entity.js +8 -7
- package/{dist → cjs}/orm/commands/command.helper.js +9 -9
- package/{dist → cjs}/orm/commands/count.command.js +2 -2
- package/{dist → cjs}/orm/commands/create.command.js +12 -12
- package/{dist → cjs}/orm/commands/destroy.command.js +2 -2
- package/{dist → cjs}/orm/commands/find.command.js +100 -88
- package/{dist → cjs}/orm/commands/row-converter.js +10 -7
- package/{dist → cjs}/orm/commands/update.command.js +10 -10
- package/{dist → cjs}/orm/decorators/column.decorator.js +3 -3
- package/{dist → cjs}/orm/decorators/embedded.decorator.js +3 -3
- package/cjs/orm/decorators/entity.decorator.js +179 -0
- package/{dist → cjs}/orm/decorators/events.decorator.js +13 -13
- package/{dist → cjs}/orm/decorators/foreignkey.decorator.js +3 -3
- package/{dist → cjs}/orm/decorators/index.decorator.js +5 -5
- package/cjs/orm/decorators/link.decorator.js +70 -0
- package/{dist → cjs}/orm/decorators/primarykey.decorator.js +7 -7
- package/{dist → cjs}/orm/decorators/transform.decorator.js +5 -5
- package/cjs/orm/model/association-field-metadata.js +24 -0
- package/{dist → cjs}/orm/model/association-node.js +5 -2
- package/{dist → cjs}/orm/model/association.js +31 -39
- package/{dist/orm/model/column-element-metadata.js → cjs/orm/model/column-field-metadata.js} +8 -8
- package/{dist/orm/model/embedded-element-metadata.js → cjs/orm/model/embedded-field-metadata.js} +8 -8
- package/{dist → cjs}/orm/model/entity-metadata.js +90 -91
- package/{dist/orm/model/element-metadata.js → cjs/orm/model/field-metadata.js} +0 -0
- package/{dist → cjs}/orm/model/index-metadata.js +0 -0
- package/{dist → cjs}/orm/model/link-chain.js +12 -15
- package/{dist → cjs}/orm/orm.const.js +0 -0
- package/{dist → cjs}/orm/orm.type.js +0 -0
- package/{dist → cjs}/orm/repository.class.js +25 -22
- package/{dist → cjs}/orm/util/apply-mixins.js +0 -0
- package/{dist → cjs}/orm/util/extract-keyvalues.js +5 -5
- package/{dist → cjs}/orm/util/orm.helper.js +10 -10
- package/{dist/orm/util/serialize-element.js → cjs/orm/util/serialize-field.js} +2 -2
- package/cjs/package.json +3 -0
- package/{dist → cjs}/types.js +0 -0
- package/{dist/client/Adapter.d.ts → esm/client/adapter.d.ts} +1 -1
- package/esm/client/adapter.js +1 -0
- package/{dist/client/CursorStream.d.ts → esm/client/cursor-stream.d.ts} +1 -1
- package/esm/client/cursor-stream.js +96 -0
- package/{dist/client/Cursor.d.ts → esm/client/cursor.d.ts} +5 -5
- package/esm/client/cursor.js +252 -0
- package/{dist → esm}/client/extensions.d.ts +1 -1
- package/esm/client/extensions.js +9 -0
- package/{dist/client/FieldInfoMap.d.ts → esm/client/field-info-map.d.ts} +1 -1
- package/esm/client/field-info-map.js +50 -0
- package/{dist → esm}/client/helpers.d.ts +3 -3
- package/esm/client/helpers.js +125 -0
- package/{dist/client/SqbClient.d.ts → esm/client/sqb-client.d.ts} +4 -10
- package/esm/client/sqb-client.js +166 -0
- package/{dist/client/SqbConnection.d.ts → esm/client/sqb-connection.d.ts} +4 -4
- package/esm/client/sqb-connection.js +270 -0
- package/{dist → esm}/client/types.d.ts +5 -13
- package/esm/client/types.js +1 -0
- package/esm/index.d.ts +33 -0
- package/esm/index.js +32 -0
- package/{dist → esm}/orm/backward.d.ts +1 -1
- package/esm/orm/backward.js +17 -0
- package/{dist → esm}/orm/base-entity.d.ts +1 -1
- package/esm/orm/base-entity.js +25 -0
- package/{dist → esm}/orm/commands/command.helper.d.ts +2 -2
- package/esm/orm/commands/command.helper.js +135 -0
- package/{dist → esm}/orm/commands/count.command.d.ts +3 -3
- package/esm/orm/commands/count.command.js +26 -0
- package/{dist → esm}/orm/commands/create.command.d.ts +2 -2
- package/esm/orm/commands/create.command.js +85 -0
- package/{dist → esm}/orm/commands/destroy.command.d.ts +3 -3
- package/esm/orm/commands/destroy.command.js +26 -0
- package/{dist → esm}/orm/commands/find.command.d.ts +9 -9
- package/esm/orm/commands/find.command.js +318 -0
- package/{dist → esm}/orm/commands/row-converter.d.ts +5 -5
- package/esm/orm/commands/row-converter.js +186 -0
- package/{dist → esm}/orm/commands/update.command.d.ts +3 -3
- package/esm/orm/commands/update.command.js +80 -0
- package/esm/orm/decorators/column.decorator.d.ts +4 -0
- package/esm/orm/decorators/column.decorator.js +19 -0
- package/esm/orm/decorators/embedded.decorator.d.ts +3 -0
- package/esm/orm/decorators/embedded.decorator.js +12 -0
- package/{dist → esm}/orm/decorators/entity.decorator.d.ts +17 -17
- package/esm/orm/decorators/entity.decorator.js +175 -0
- package/{dist → esm}/orm/decorators/events.decorator.d.ts +0 -0
- package/esm/orm/decorators/events.decorator.js +55 -0
- package/{dist → esm}/orm/decorators/foreignkey.decorator.d.ts +1 -1
- package/esm/orm/decorators/foreignkey.decorator.js +9 -0
- package/{dist → esm}/orm/decorators/index.decorator.d.ts +1 -1
- package/esm/orm/decorators/index.decorator.js +17 -0
- package/esm/orm/decorators/link.decorator.d.ts +13 -0
- package/esm/orm/decorators/link.decorator.js +66 -0
- package/{dist → esm}/orm/decorators/primarykey.decorator.d.ts +1 -1
- package/esm/orm/decorators/primarykey.decorator.js +20 -0
- package/{dist → esm}/orm/decorators/transform.decorator.d.ts +1 -1
- package/esm/orm/decorators/transform.decorator.js +19 -0
- package/esm/orm/model/association-field-metadata.d.ts +12 -0
- package/esm/orm/model/association-field-metadata.js +20 -0
- package/{dist → esm}/orm/model/association-node.d.ts +1 -1
- package/esm/orm/model/association-node.js +24 -0
- package/{dist → esm}/orm/model/association.d.ts +6 -7
- package/esm/orm/model/association.js +118 -0
- package/{dist/orm/model/column-element-metadata.d.ts → esm/orm/model/column-field-metadata.d.ts} +10 -14
- package/esm/orm/model/column-field-metadata.js +28 -0
- package/esm/orm/model/embedded-field-metadata.d.ts +14 -0
- package/esm/orm/model/embedded-field-metadata.js +25 -0
- package/esm/orm/model/entity-metadata.d.ts +50 -0
- package/esm/orm/model/entity-metadata.js +337 -0
- package/esm/orm/model/field-metadata.d.ts +16 -0
- package/esm/orm/model/field-metadata.js +1 -0
- package/{dist → esm}/orm/model/index-metadata.d.ts +0 -0
- package/esm/orm/model/index-metadata.js +1 -0
- package/esm/orm/model/link-chain.d.ts +13 -0
- package/esm/orm/model/link-chain.js +43 -0
- package/{dist → esm}/orm/orm.const.d.ts +0 -0
- package/esm/orm/orm.const.js +2 -0
- package/{dist → esm}/orm/orm.type.d.ts +3 -4
- package/esm/orm/orm.type.js +1 -0
- package/{dist → esm}/orm/repository.class.d.ts +31 -31
- package/esm/orm/repository.class.js +238 -0
- package/{dist → esm}/orm/util/apply-mixins.d.ts +0 -0
- package/esm/orm/util/apply-mixins.js +9 -0
- package/{dist → esm}/orm/util/extract-keyvalues.d.ts +1 -1
- package/esm/orm/util/extract-keyvalues.js +57 -0
- package/esm/orm/util/orm.helper.d.ts +13 -0
- package/esm/orm/util/orm.helper.js +28 -0
- package/esm/orm/util/serialize-field.d.ts +2 -0
- package/esm/orm/util/serialize-field.js +39 -0
- package/esm/types.d.ts +8 -0
- package/esm/types.js +1 -0
- package/package.json +53 -40
- package/dist/index.d.ts +0 -33
- package/dist/index.js +0 -42
- package/dist/orm/decorators/column.decorator.d.ts +0 -4
- package/dist/orm/decorators/embedded.decorator.d.ts +0 -3
- package/dist/orm/decorators/entity.decorator.js +0 -179
- package/dist/orm/decorators/link.decorator.d.ts +0 -23
- package/dist/orm/decorators/link.decorator.js +0 -88
- package/dist/orm/model/association-element-metadata.d.ts +0 -10
- package/dist/orm/model/association-element-metadata.js +0 -15
- package/dist/orm/model/element-metadata.d.ts +0 -7
- package/dist/orm/model/embedded-element-metadata.d.ts +0 -14
- package/dist/orm/model/entity-metadata.d.ts +0 -50
- package/dist/orm/model/link-chain.d.ts +0 -15
- package/dist/orm/util/orm.helper.d.ts +0 -13
- package/dist/orm/util/serialize-element.d.ts +0 -2
- package/dist/types.d.ts +0 -2
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
|
|
2
|
+
<p style="text-align:center">
|
|
3
|
+
<img src="https://user-images.githubusercontent.com/3836517/32965280-1a2b63ce-cbe7-11e7-8ee1-ba47313503c5.png" width="500px" alt="SQB Logo"/>
|
|
4
|
+
</p>
|
|
5
|
+
|
|
6
|
+
<br>
|
|
7
|
+
|
|
8
|
+
[![NPM Version][npm-image]][npm-url]
|
|
9
|
+
[![NPM Downloads][downloads-image]][downloads-url]
|
|
10
|
+
[![Build Status][travis-image]][travis-url]
|
|
11
|
+
[![Test Coverage][coveralls-image]][coveralls-url]
|
|
12
|
+
[![Dependencies][dependencies-image]][dependencies-url]
|
|
13
|
+
[![DevDependencies][devdependencies-image]][devdependencies-url]
|
|
14
|
+
[![Package Quality][quality-image]][quality-url]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## About SQB
|
|
18
|
+
|
|
19
|
+
SQB is an extensible, multi-dialect SQL query builder and Database connection wrapper for NodeJS.
|
|
20
|
+
|
|
21
|
+
## Main goals
|
|
22
|
+
|
|
23
|
+
- Single code base for any sql based database
|
|
24
|
+
- Powerful and simplified query coding scheme
|
|
25
|
+
- Fast applications with low memory requirements
|
|
26
|
+
- Let applications work with large data tables efficiently
|
|
27
|
+
- Support latest JavaScript language standards
|
|
28
|
+
- Lightweight and extensible framework.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
You can report bugs and discuss features on the [GitHub issues](https://github.com/sqbjs/sqb/issues) page
|
|
32
|
+
|
|
33
|
+
Thanks to all of the great [contributions](https://github.com/sqbjs/sqb/graphs/contributors) to the project.
|
|
34
|
+
|
|
35
|
+
You may want to check detailed [DOCUMENTATION](https://sqbjs.github.io/sqb/)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
$ npm install @sqb/connect --save
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Node Compatibility
|
|
45
|
+
|
|
46
|
+
- node >= 16.x
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### License
|
|
50
|
+
SQB is available under [MIT](LICENSE) license.
|
|
51
|
+
|
|
52
|
+
[npm-image]: https://img.shields.io/npm/v/@sqb/connect.svg
|
|
53
|
+
[npm-url]: https://npmjs.org/package/@sqb/connect
|
|
54
|
+
[travis-image]: https://img.shields.io/travis/sqbjs/@sqb/connect/master.svg
|
|
55
|
+
[travis-url]: https://travis-ci.org/sqbjs/@sqb/connect
|
|
56
|
+
[coveralls-image]: https://img.shields.io/coveralls/sqbjs/@sqb/connect/master.svg
|
|
57
|
+
[coveralls-url]: https://coveralls.io/r/sqbjs/@sqb/connect
|
|
58
|
+
[downloads-image]: https://img.shields.io/npm/dm/@sqb/connect.svg
|
|
59
|
+
[downloads-url]: https://npmjs.org/package/@sqb/connect
|
|
60
|
+
[gitter-image]: https://badges.gitter.im/sqbjs/@sqb/connect.svg
|
|
61
|
+
[gitter-url]: https://gitter.im/sqbjs/@sqb/connect?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
|
62
|
+
[dependencies-image]: https://david-dm.org/sqbjs/@sqb/connect/status.svg
|
|
63
|
+
[dependencies-url]:https://david-dm.org/sqbjs/@sqb/connect
|
|
64
|
+
[devdependencies-image]: https://david-dm.org/sqbjs/@sqb/connect/dev-status.svg
|
|
65
|
+
[devdependencies-url]:https://david-dm.org/sqbjs/@sqb/connect?type=dev
|
|
66
|
+
[quality-image]: http://npm.packagequality.com/shield/@sqb/connect.png
|
|
67
|
+
[quality-url]: http://packagequality.com/#?package=@sqb/connect
|
|
File without changes
|
|
@@ -7,10 +7,13 @@ const stream_1 = require("stream");
|
|
|
7
7
|
const inspect = Symbol.for('nodejs.util.inspect.custom');
|
|
8
8
|
const debug = (0, debug_1.default)('sqb:cursorstream');
|
|
9
9
|
class CursorStream extends stream_1.Readable {
|
|
10
|
+
_cursor;
|
|
11
|
+
_objectMode;
|
|
12
|
+
_limit;
|
|
13
|
+
_rowNum = -1;
|
|
14
|
+
_eof = false;
|
|
10
15
|
constructor(cursor, options) {
|
|
11
16
|
super(options);
|
|
12
|
-
this._rowNum = -1;
|
|
13
|
-
this._eof = false;
|
|
14
17
|
this._cursor = cursor;
|
|
15
18
|
this._objectMode = options?.objectMode;
|
|
16
19
|
this._limit = options?.limit || Number.MAX_SAFE_INTEGER;
|
|
@@ -7,17 +7,24 @@ const doublylinked_1 = tslib_1.__importDefault(require("doublylinked"));
|
|
|
7
7
|
const putil_taskqueue_1 = tslib_1.__importDefault(require("putil-taskqueue"));
|
|
8
8
|
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
9
9
|
const strict_typed_events_1 = require("strict-typed-events");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
10
|
+
const cursor_stream_js_1 = require("./cursor-stream.js");
|
|
11
|
+
const helpers_js_1 = require("./helpers.js");
|
|
12
12
|
const debug = (0, debug_1.default)('sqb:cursor');
|
|
13
13
|
class Cursor extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_typed_events_1.AsyncEventEmitter) {
|
|
14
|
+
_connection;
|
|
15
|
+
_fields;
|
|
16
|
+
_prefetchRows;
|
|
17
|
+
_request;
|
|
18
|
+
_intlcur;
|
|
19
|
+
_taskQueue = new putil_taskqueue_1.default();
|
|
20
|
+
_fetchCache = new doublylinked_1.default();
|
|
21
|
+
_rowNum = 0;
|
|
22
|
+
_fetchedAll = false;
|
|
23
|
+
_fetchedRows = 0;
|
|
24
|
+
_row;
|
|
25
|
+
_cache;
|
|
14
26
|
constructor(connection, fields, adapterCursor, request) {
|
|
15
27
|
super();
|
|
16
|
-
this._taskQueue = new putil_taskqueue_1.default();
|
|
17
|
-
this._fetchCache = new doublylinked_1.default();
|
|
18
|
-
this._rowNum = 0;
|
|
19
|
-
this._fetchedAll = false;
|
|
20
|
-
this._fetchedRows = 0;
|
|
21
28
|
this._connection = connection;
|
|
22
29
|
this._intlcur = adapterCursor;
|
|
23
30
|
this._fields = fields;
|
|
@@ -161,7 +168,7 @@ class Cursor extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_ty
|
|
|
161
168
|
* Creates and returns a readable stream.
|
|
162
169
|
*/
|
|
163
170
|
toStream(options) {
|
|
164
|
-
return new
|
|
171
|
+
return new cursor_stream_js_1.CursorStream(this, options);
|
|
165
172
|
}
|
|
166
173
|
toString() {
|
|
167
174
|
return '[object ' + Object.getPrototypeOf(this).constructor.name + ']';
|
|
@@ -228,9 +235,9 @@ class Cursor extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_ty
|
|
|
228
235
|
debug('Fetched %d rows from database', rows.length);
|
|
229
236
|
// Normalize rows
|
|
230
237
|
rows = this._request.objectRows ?
|
|
231
|
-
(0,
|
|
232
|
-
(0,
|
|
233
|
-
(0,
|
|
238
|
+
(0, helpers_js_1.normalizeRowsToObjectRows)(this._fields, this._intlcur.rowType, rows, this._request) :
|
|
239
|
+
(0, helpers_js_1.normalizeRowsToArrayRows)(this._fields, this._intlcur.rowType, rows, this._request);
|
|
240
|
+
(0, helpers_js_1.callFetchHooks)(rows, this._request);
|
|
234
241
|
for (const [idx, row] of rows.entries()) {
|
|
235
242
|
this.emit('fetch', row, (this._rowNum + idx + 1));
|
|
236
243
|
}
|
|
File without changes
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.callFetchHooks = exports.normalizeRowsToArrayRows = exports.normalizeRowsToObjectRows = exports.wrapAdapterFields = exports.applyNamingStrategy = void 0;
|
|
4
4
|
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
5
|
-
const
|
|
5
|
+
const field_info_map_js_1 = require("./field-info-map.js");
|
|
6
6
|
function applyNamingStrategy(value, namingStrategy) {
|
|
7
7
|
if (typeof namingStrategy === 'string' && namingStrategy !== 'original') {
|
|
8
8
|
switch (namingStrategy.toLowerCase()) {
|
|
@@ -32,7 +32,7 @@ function wrapAdapterFields(oldFields, fieldNaming) {
|
|
|
32
32
|
if (name)
|
|
33
33
|
return { ...f, name, index };
|
|
34
34
|
};
|
|
35
|
-
const result = new
|
|
35
|
+
const result = new field_info_map_js_1.FieldInfoMap();
|
|
36
36
|
let i = 0;
|
|
37
37
|
oldFields.forEach(f => {
|
|
38
38
|
const x = mapFieldInfo(f, i);
|
|
@@ -6,26 +6,29 @@ const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
|
6
6
|
const lightning_pool_1 = require("lightning-pool");
|
|
7
7
|
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
8
8
|
const strict_typed_events_1 = require("strict-typed-events");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
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
13
|
const debug = (0, debug_1.default)('sqb:client');
|
|
14
14
|
const inspect = Symbol.for('nodejs.util.inspect.custom');
|
|
15
15
|
class SqbClient extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_typed_events_1.AsyncEventEmitter) {
|
|
16
|
+
_adapter;
|
|
17
|
+
_pool;
|
|
18
|
+
_defaults;
|
|
19
|
+
_entities = {};
|
|
16
20
|
constructor(config) {
|
|
17
21
|
super();
|
|
18
|
-
this._entities = {};
|
|
19
22
|
if (!(config && typeof config === 'object'))
|
|
20
23
|
throw new TypeError('Configuration object required');
|
|
21
24
|
let adapter;
|
|
22
25
|
if (config.driver) {
|
|
23
|
-
adapter =
|
|
26
|
+
adapter = extensions_js_1.adapters.find(x => x.driver === config.driver);
|
|
24
27
|
if (!adapter)
|
|
25
28
|
throw new Error(`No database adapter registered for "${config.driver}" driver`);
|
|
26
29
|
}
|
|
27
30
|
else if (config.dialect) {
|
|
28
|
-
adapter =
|
|
31
|
+
adapter = extensions_js_1.adapters.find(x => x.dialect === config.dialect);
|
|
29
32
|
if (!adapter)
|
|
30
33
|
throw new Error(`No database adapter registered for "${config.dialect}" dialect`);
|
|
31
34
|
}
|
|
@@ -97,7 +100,7 @@ class SqbClient extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict
|
|
|
97
100
|
const options = arg1;
|
|
98
101
|
const adapterConnection = await this._pool.acquire();
|
|
99
102
|
const opts = { autoCommit: this.defaults.autoCommit, ...options };
|
|
100
|
-
const connection = new
|
|
103
|
+
const connection = new sqb_connection_js_1.SqbConnection(this, adapterConnection, opts);
|
|
101
104
|
await this.emitAsyncSerial('acquire', connection);
|
|
102
105
|
connection.on('execute', (request) => this.emit('execute', request));
|
|
103
106
|
connection.on('error', (error) => this.emit('error', error));
|
|
@@ -110,6 +113,9 @@ class SqbClient extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict
|
|
|
110
113
|
const ms = terminateWait == null ? Infinity : 0;
|
|
111
114
|
return this._pool.close(ms);
|
|
112
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Executes a query or callback with a new acquired connection.
|
|
118
|
+
*/
|
|
113
119
|
async execute(query, options) {
|
|
114
120
|
debug('execute');
|
|
115
121
|
const connection = await this.acquire();
|
|
@@ -146,10 +152,10 @@ class SqbClient extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict
|
|
|
146
152
|
}
|
|
147
153
|
else
|
|
148
154
|
ctor = entity;
|
|
149
|
-
const entityDef =
|
|
155
|
+
const entityDef = entity_metadata_js_1.EntityMetadata.get(ctor);
|
|
150
156
|
if (!entityDef)
|
|
151
157
|
throw new Error(`You must provide an @Entity annotated constructor`);
|
|
152
|
-
return new
|
|
158
|
+
return new repository_class_js_1.Repository(entityDef, this, opts?.schema);
|
|
153
159
|
}
|
|
154
160
|
getEntity(name) {
|
|
155
161
|
return this._entities[name];
|
|
@@ -8,18 +8,21 @@ const putil_taskqueue_1 = tslib_1.__importDefault(require("putil-taskqueue"));
|
|
|
8
8
|
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
9
9
|
const strict_typed_events_1 = require("strict-typed-events");
|
|
10
10
|
const builder_1 = require("@sqb/builder");
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
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
15
|
const debug = (0, debug_1.default)('sqb:connection');
|
|
16
16
|
class SqbConnection extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_typed_events_1.AsyncEventEmitter) {
|
|
17
|
+
client;
|
|
18
|
+
_intlcon;
|
|
19
|
+
_tasks = new putil_taskqueue_1.default();
|
|
20
|
+
_options;
|
|
21
|
+
_inTransaction = false;
|
|
22
|
+
_refCount = 1;
|
|
17
23
|
constructor(client, adapterConnection, options) {
|
|
18
24
|
super();
|
|
19
25
|
this.client = client;
|
|
20
|
-
this._tasks = new putil_taskqueue_1.default();
|
|
21
|
-
this._inTransaction = false;
|
|
22
|
-
this._refCount = 1;
|
|
23
26
|
this._intlcon = adapterConnection;
|
|
24
27
|
this._options = options || {};
|
|
25
28
|
}
|
|
@@ -96,10 +99,10 @@ class SqbConnection extends (0, strict_typed_events_1.TypedEventEmitterClass)(st
|
|
|
96
99
|
}
|
|
97
100
|
else
|
|
98
101
|
ctor = entity;
|
|
99
|
-
const entityDef =
|
|
102
|
+
const entityDef = entity_metadata_js_1.EntityMetadata.get(ctor);
|
|
100
103
|
if (!entityDef)
|
|
101
104
|
throw new Error(`You must provide an @Entity annotated constructor`);
|
|
102
|
-
return new
|
|
105
|
+
return new repository_class_js_1.Repository(entityDef, this, opts?.schema);
|
|
103
106
|
}
|
|
104
107
|
async getSchema() {
|
|
105
108
|
assert_1.default.ok(this._intlcon, `Can't set schema, because connection is released`);
|
|
@@ -142,16 +145,16 @@ class SqbConnection extends (0, strict_typed_events_1.TypedEventEmitterClass)(st
|
|
|
142
145
|
throw new Error('Adapter did not returned fields info');
|
|
143
146
|
if (!response.rowType)
|
|
144
147
|
throw new Error('Adapter did not returned rowType');
|
|
145
|
-
result.fields = (0,
|
|
148
|
+
result.fields = (0, helpers_js_1.wrapAdapterFields)(response.fields, request.fieldNaming);
|
|
146
149
|
result.rowType = response.rowType;
|
|
147
150
|
if (response.rows) {
|
|
148
151
|
result.rows = request.objectRows ?
|
|
149
|
-
(0,
|
|
150
|
-
(0,
|
|
151
|
-
(0,
|
|
152
|
+
(0, helpers_js_1.normalizeRowsToObjectRows)(result.fields, response.rowType, response.rows, request) :
|
|
153
|
+
(0, helpers_js_1.normalizeRowsToArrayRows)(result.fields, response.rowType, response.rows, request);
|
|
154
|
+
(0, helpers_js_1.callFetchHooks)(result.rows, request);
|
|
152
155
|
}
|
|
153
156
|
else if (response.cursor) {
|
|
154
|
-
const cursor = result.cursor = new
|
|
157
|
+
const cursor = result.cursor = new cursor_js_1.Cursor(this, result.fields, response.cursor, request);
|
|
155
158
|
const hook = () => cursor.close();
|
|
156
159
|
cursor.once('close', () => this.off('close', hook));
|
|
157
160
|
this.on('close', hook);
|
|
File without changes
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEntityClass = exports.isAssociationField = exports.isEmbeddedField = exports.isColumnField = exports.unRegisterAdapter = exports.registerAdapter = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
require("reflect-metadata");
|
|
6
|
+
tslib_1.__exportStar(require("./types.js"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./client/types.js"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./client/adapter.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/cursor.js"), exports);
|
|
12
|
+
var extensions_js_1 = require("./client/extensions.js");
|
|
13
|
+
Object.defineProperty(exports, "registerAdapter", { enumerable: true, get: function () { return extensions_js_1.registerAdapter; } });
|
|
14
|
+
Object.defineProperty(exports, "unRegisterAdapter", { enumerable: true, get: function () { return extensions_js_1.unRegisterAdapter; } });
|
|
15
|
+
tslib_1.__exportStar(require("./orm/orm.type.js"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./orm/orm.const.js"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./orm/base-entity.js"), exports);
|
|
18
|
+
tslib_1.__exportStar(require("./orm/repository.class.js"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./orm/model/entity-metadata.js"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./orm/model/field-metadata.js"), exports);
|
|
21
|
+
tslib_1.__exportStar(require("./orm/model/column-field-metadata.js"), exports);
|
|
22
|
+
tslib_1.__exportStar(require("./orm/model/embedded-field-metadata.js"), exports);
|
|
23
|
+
tslib_1.__exportStar(require("./orm/model/association-field-metadata.js"), exports);
|
|
24
|
+
tslib_1.__exportStar(require("./orm/model/association.js"), exports);
|
|
25
|
+
tslib_1.__exportStar(require("./orm/model/association-node.js"), exports);
|
|
26
|
+
tslib_1.__exportStar(require("./orm/model/index-metadata.js"), exports);
|
|
27
|
+
tslib_1.__exportStar(require("./orm/model/link-chain.js"), exports);
|
|
28
|
+
tslib_1.__exportStar(require("./orm/decorators/column.decorator.js"), exports);
|
|
29
|
+
tslib_1.__exportStar(require("./orm/decorators/embedded.decorator.js"), exports);
|
|
30
|
+
tslib_1.__exportStar(require("./orm/decorators/entity.decorator.js"), exports);
|
|
31
|
+
tslib_1.__exportStar(require("./orm/decorators/events.decorator.js"), exports);
|
|
32
|
+
tslib_1.__exportStar(require("./orm/decorators/foreignkey.decorator.js"), exports);
|
|
33
|
+
tslib_1.__exportStar(require("./orm/decorators/index.decorator.js"), exports);
|
|
34
|
+
tslib_1.__exportStar(require("./orm/decorators/link.decorator.js"), exports);
|
|
35
|
+
tslib_1.__exportStar(require("./orm/decorators/primarykey.decorator.js"), exports);
|
|
36
|
+
tslib_1.__exportStar(require("./orm/decorators/transform.decorator.js"), exports);
|
|
37
|
+
var orm_helper_js_1 = require("./orm/util/orm.helper.js");
|
|
38
|
+
Object.defineProperty(exports, "isColumnField", { enumerable: true, get: function () { return orm_helper_js_1.isColumnField; } });
|
|
39
|
+
Object.defineProperty(exports, "isEmbeddedField", { enumerable: true, get: function () { return orm_helper_js_1.isEmbeddedField; } });
|
|
40
|
+
Object.defineProperty(exports, "isAssociationField", { enumerable: true, get: function () { return orm_helper_js_1.isAssociationField; } });
|
|
41
|
+
Object.defineProperty(exports, "isEntityClass", { enumerable: true, get: function () { return orm_helper_js_1.isEntityClass; } });
|
|
42
|
+
tslib_1.__exportStar(require("./orm/backward.js"), exports);
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UnionEntity = exports.PickEntity = exports.OmitEntity = exports.mixinEntities = exports.getNonAssociationElementNames = exports.getUpdateColumnNames = exports.getInsertColumnNames = void 0;
|
|
4
|
-
const
|
|
4
|
+
const entity_decorator_js_1 = require("./decorators/entity.decorator.js");
|
|
5
5
|
function getInsertColumnNames(ctor) {
|
|
6
|
-
return
|
|
6
|
+
return entity_decorator_js_1.Entity.getInsertColumnNames(ctor);
|
|
7
7
|
}
|
|
8
8
|
exports.getInsertColumnNames = getInsertColumnNames;
|
|
9
9
|
function getUpdateColumnNames(ctor) {
|
|
10
|
-
return
|
|
10
|
+
return entity_decorator_js_1.Entity.getUpdateColumnNames(ctor);
|
|
11
11
|
}
|
|
12
12
|
exports.getUpdateColumnNames = getUpdateColumnNames;
|
|
13
13
|
function getNonAssociationElementNames(ctor) {
|
|
14
|
-
return
|
|
14
|
+
return entity_decorator_js_1.Entity.getNonAssociationFieldNames(ctor);
|
|
15
15
|
}
|
|
16
16
|
exports.getNonAssociationElementNames = getNonAssociationElementNames;
|
|
17
17
|
function mixinEntities(derivedCtor, ...bases) {
|
|
18
18
|
// @ts-ignore
|
|
19
|
-
return
|
|
19
|
+
return entity_decorator_js_1.Entity.mixin(derivedCtor, ...bases);
|
|
20
20
|
}
|
|
21
21
|
exports.mixinEntities = mixinEntities;
|
|
22
|
-
exports.OmitEntity =
|
|
23
|
-
exports.PickEntity =
|
|
24
|
-
exports.UnionEntity =
|
|
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;
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseEntity = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const entity_decorator_js_1 = require("./decorators/entity.decorator.js");
|
|
5
|
+
const orm_const_js_1 = require("./orm.const.js");
|
|
6
6
|
class BaseEntity {
|
|
7
|
+
[orm_const_js_1.REPOSITORY_KEY];
|
|
7
8
|
constructor(partial) {
|
|
8
|
-
const
|
|
9
|
-
if (
|
|
10
|
-
for (const k of
|
|
9
|
+
const fields = entity_decorator_js_1.Entity.getColumnFieldNames(Object.getPrototypeOf(this).constructor);
|
|
10
|
+
if (fields && partial) {
|
|
11
|
+
for (const k of fields)
|
|
11
12
|
if (partial[k] !== undefined)
|
|
12
13
|
this[k] = partial[k];
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
async destroy() {
|
|
16
|
-
const repo = this[
|
|
17
|
+
const repo = this[orm_const_js_1.REPOSITORY_KEY];
|
|
17
18
|
return !!(repo && repo.destroy(this));
|
|
18
19
|
}
|
|
19
20
|
async exists() {
|
|
20
|
-
const repo = this[
|
|
21
|
+
const repo = this[orm_const_js_1.REPOSITORY_KEY];
|
|
21
22
|
return !!(repo && repo.exists(this));
|
|
22
23
|
}
|
|
23
24
|
toJSON() {
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.prepareFilter = exports.joinAssociation = exports.joinAssociationGetLast = exports.joinAssociationGetFirst = void 0;
|
|
4
4
|
const builder_1 = require("@sqb/builder");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const embedded_field_metadata_js_1 = require("../model/embedded-field-metadata.js");
|
|
6
|
+
const entity_metadata_js_1 = require("../model/entity-metadata.js");
|
|
7
|
+
const orm_helper_js_1 = require("../util/orm.helper.js");
|
|
8
8
|
async function joinAssociationGetFirst(joinInfos, association, parentAlias, innerJoin) {
|
|
9
9
|
const joins = await joinAssociation(joinInfos, association, parentAlias, innerJoin);
|
|
10
10
|
return joins[0];
|
|
@@ -81,26 +81,26 @@ async function prepareFilter(entityDef, filter, trgOp, tableAlias = 'T') {
|
|
|
81
81
|
let subSelect;
|
|
82
82
|
for (let i = 0; i < l; i++) {
|
|
83
83
|
pt = itemPath[i];
|
|
84
|
-
const col =
|
|
84
|
+
const col = entity_metadata_js_1.EntityMetadata.getField(_curEntity, pt);
|
|
85
85
|
if (!col)
|
|
86
86
|
throw new Error(`Unknown property (${item._left}) defined in filter`);
|
|
87
87
|
// if last item on path
|
|
88
88
|
if (i === l - 1) {
|
|
89
|
-
if (!(0,
|
|
89
|
+
if (!(0, orm_helper_js_1.isColumnField)(col))
|
|
90
90
|
throw new Error(`Invalid column expression (${item._left}) defined in filter`);
|
|
91
91
|
const ctor = Object.getPrototypeOf(item).constructor;
|
|
92
92
|
trgOp.add(new ctor((0, builder_1.Field)(_curAlias + '.' + _curPrefix + col.fieldName + _curSuffix, col.dataType, col.isArray), item._right));
|
|
93
93
|
}
|
|
94
94
|
else {
|
|
95
|
-
if ((0,
|
|
95
|
+
if ((0, orm_helper_js_1.isColumnField)(col))
|
|
96
96
|
throw new Error(`Invalid column (${item._left}) defined in filter`);
|
|
97
|
-
if ((0,
|
|
98
|
-
_curEntity = await
|
|
97
|
+
if ((0, orm_helper_js_1.isEmbeddedField)(col)) {
|
|
98
|
+
_curEntity = await embedded_field_metadata_js_1.EmbeddedFieldMetadata.resolveType(col);
|
|
99
99
|
_curPrefix = _curPrefix + (col.fieldNamePrefix || '');
|
|
100
100
|
_curSuffix = (col.fieldNameSuffix || '') + _curSuffix;
|
|
101
101
|
continue;
|
|
102
102
|
}
|
|
103
|
-
if (!(0,
|
|
103
|
+
if (!(0, orm_helper_js_1.isAssociationField)(col))
|
|
104
104
|
throw new Error(`Invalid column (${item._left}) defined in filter`);
|
|
105
105
|
let node;
|
|
106
106
|
_curEntity = await col.association.resolveTarget();
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CountCommand = void 0;
|
|
4
4
|
const builder_1 = require("@sqb/builder");
|
|
5
|
-
const
|
|
5
|
+
const command_helper_js_1 = require("./command.helper.js");
|
|
6
6
|
class CountCommand {
|
|
7
7
|
// istanbul ignore next
|
|
8
8
|
constructor() {
|
|
@@ -13,7 +13,7 @@ class CountCommand {
|
|
|
13
13
|
let where;
|
|
14
14
|
if (filter) {
|
|
15
15
|
where = (0, builder_1.And)();
|
|
16
|
-
await (0,
|
|
16
|
+
await (0, command_helper_js_1.prepareFilter)(entity, filter, where, 'T');
|
|
17
17
|
}
|
|
18
18
|
const query = (0, builder_1.Select)((0, builder_1.Count)()).from(entity.tableName + ' T');
|
|
19
19
|
if (where)
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CreateCommand = void 0;
|
|
4
4
|
const builder_1 = require("@sqb/builder");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
5
|
+
const column_field_metadata_js_1 = require("../model/column-field-metadata.js");
|
|
6
|
+
const embedded_field_metadata_js_1 = require("../model/embedded-field-metadata.js");
|
|
7
|
+
const entity_metadata_js_1 = require("../model/entity-metadata.js");
|
|
8
|
+
const orm_helper_js_1 = require("../util/orm.helper.js");
|
|
9
9
|
class CreateCommand {
|
|
10
10
|
// istanbul ignore next
|
|
11
11
|
constructor() {
|
|
@@ -26,10 +26,10 @@ class CreateCommand {
|
|
|
26
26
|
// Prepare
|
|
27
27
|
await this._prepareParams(ctx, entity, args.values);
|
|
28
28
|
if (!ctx.colCount)
|
|
29
|
-
throw new Error('No
|
|
29
|
+
throw new Error('No field given to create new entity instance');
|
|
30
30
|
const query = (0, builder_1.Insert)(tableName, ctx.queryValues);
|
|
31
31
|
if (args.returning) {
|
|
32
|
-
const primaryIndexColumns =
|
|
32
|
+
const primaryIndexColumns = entity_metadata_js_1.EntityMetadata.getPrimaryIndexColumns(entity);
|
|
33
33
|
if (primaryIndexColumns.length)
|
|
34
34
|
query.returning(...primaryIndexColumns.map(col => col.fieldName));
|
|
35
35
|
}
|
|
@@ -41,7 +41,7 @@ class CreateCommand {
|
|
|
41
41
|
if (args.returning && qr.fields && qr.rows?.length) {
|
|
42
42
|
const keyValues = {};
|
|
43
43
|
for (const f of qr.fields.values()) {
|
|
44
|
-
const el =
|
|
44
|
+
const el = entity_metadata_js_1.EntityMetadata.getColumnFieldByFieldName(entity, f.fieldName);
|
|
45
45
|
if (el)
|
|
46
46
|
keyValues[el.name] = qr.rows[0][f.index];
|
|
47
47
|
}
|
|
@@ -52,9 +52,9 @@ class CreateCommand {
|
|
|
52
52
|
let v;
|
|
53
53
|
prefix = prefix || '';
|
|
54
54
|
suffix = suffix || '';
|
|
55
|
-
for (const col of Object.values(entity.
|
|
55
|
+
for (const col of Object.values(entity.fields)) {
|
|
56
56
|
v = values[col.name];
|
|
57
|
-
if ((0,
|
|
57
|
+
if ((0, orm_helper_js_1.isColumnField)(col)) {
|
|
58
58
|
if (col.noInsert)
|
|
59
59
|
continue;
|
|
60
60
|
if (v == null && col.default !== undefined) {
|
|
@@ -68,7 +68,7 @@ class CreateCommand {
|
|
|
68
68
|
throw new Error(`${entity.name}.${col.name} is required and can't be null`);
|
|
69
69
|
continue;
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
column_field_metadata_js_1.ColumnFieldMetadata.checkEnumValue(col, v);
|
|
72
72
|
const fieldName = prefix + col.fieldName + suffix;
|
|
73
73
|
const k = '$input_' + fieldName;
|
|
74
74
|
ctx.queryValues[fieldName] = (0, builder_1.Param)({
|
|
@@ -79,8 +79,8 @@ class CreateCommand {
|
|
|
79
79
|
ctx.queryParams[k] = v;
|
|
80
80
|
ctx.colCount++;
|
|
81
81
|
}
|
|
82
|
-
else if (v != null && (0,
|
|
83
|
-
const type = await
|
|
82
|
+
else if (v != null && (0, orm_helper_js_1.isEmbeddedField)(col)) {
|
|
83
|
+
const type = await embedded_field_metadata_js_1.EmbeddedFieldMetadata.resolveType(col);
|
|
84
84
|
await this._prepareParams(ctx, type, v, col.fieldNamePrefix, col.fieldNameSuffix);
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DestroyCommand = void 0;
|
|
4
4
|
const builder_1 = require("@sqb/builder");
|
|
5
|
-
const
|
|
5
|
+
const command_helper_js_1 = require("./command.helper.js");
|
|
6
6
|
class DestroyCommand {
|
|
7
7
|
// istanbul ignore next
|
|
8
8
|
constructor() {
|
|
@@ -13,7 +13,7 @@ class DestroyCommand {
|
|
|
13
13
|
let where;
|
|
14
14
|
if (filter) {
|
|
15
15
|
where = (0, builder_1.And)();
|
|
16
|
-
await (0,
|
|
16
|
+
await (0, command_helper_js_1.prepareFilter)(entity, filter, where);
|
|
17
17
|
}
|
|
18
18
|
const query = (0, builder_1.Delete)(entity.tableName + ' T');
|
|
19
19
|
if (where)
|