@sqb/connect 4.0.15 → 4.1.2
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/dist/client/Adapter.d.ts +1 -1
- package/dist/client/Cursor.d.ts +2 -2
- package/dist/client/Cursor.js +3 -3
- package/dist/client/CursorStream.js +1 -1
- package/dist/client/SqbClient.d.ts +2 -2
- package/dist/client/SqbClient.js +5 -5
- package/dist/client/SqbConnection.d.ts +3 -3
- package/dist/client/SqbConnection.js +7 -7
- package/dist/client/helpers.d.ts +2 -2
- package/dist/client/types.d.ts +4 -4
- package/dist/index.d.ts +20 -15
- package/dist/index.js +21 -16
- package/dist/orm/backward.d.ts +8 -0
- package/dist/orm/backward.js +19 -0
- package/dist/orm/base-entity.d.ts +8 -0
- package/dist/orm/base-entity.js +28 -0
- package/dist/orm/commands/command.helper.d.ts +4 -4
- package/dist/orm/commands/command.helper.js +5 -3
- package/dist/orm/commands/count.command.d.ts +3 -3
- package/dist/orm/commands/create.command.d.ts +4 -4
- package/dist/orm/commands/create.command.js +13 -7
- package/dist/orm/commands/destroy.command.d.ts +3 -3
- package/dist/orm/commands/find.command.d.ts +9 -9
- package/dist/orm/commands/find.command.js +13 -11
- package/dist/orm/commands/row-converter.d.ts +4 -4
- package/dist/orm/commands/update.command.d.ts +5 -5
- package/dist/orm/commands/update.command.js +7 -5
- package/dist/orm/decorators/column.decorator.d.ts +2 -2
- package/dist/orm/decorators/column.decorator.js +13 -4
- package/dist/orm/decorators/embedded.decorator.d.ts +3 -2
- package/dist/orm/decorators/embedded.decorator.js +6 -7
- package/dist/orm/decorators/entity.decorator.d.ts +31 -4
- package/dist/orm/decorators/entity.decorator.js +147 -5
- package/dist/orm/decorators/events.decorator.js +13 -25
- package/dist/orm/decorators/foreignkey.decorator.js +3 -3
- package/dist/orm/decorators/index.decorator.d.ts +3 -3
- package/dist/orm/decorators/index.decorator.js +5 -6
- package/dist/orm/decorators/link.decorator.d.ts +1 -1
- package/dist/orm/decorators/link.decorator.js +3 -3
- package/dist/orm/decorators/primarykey.decorator.d.ts +3 -3
- package/dist/orm/decorators/primarykey.decorator.js +7 -6
- package/dist/orm/decorators/transform.decorator.js +5 -5
- package/dist/orm/model/association-element-metadata.d.ts +10 -0
- package/dist/orm/model/association-element-metadata.js +15 -0
- package/dist/orm/model/association.d.ts +6 -6
- package/dist/orm/model/association.js +9 -8
- package/dist/orm/model/{entity-column-element.d.ts → column-element-metadata.d.ts} +21 -10
- package/dist/orm/model/column-element-metadata.js +32 -0
- package/dist/orm/model/element-metadata.d.ts +7 -0
- package/dist/orm/model/element-metadata.js +2 -0
- package/dist/orm/model/embedded-element-metadata.d.ts +14 -0
- package/dist/orm/model/embedded-element-metadata.js +28 -0
- package/dist/orm/model/entity-metadata.d.ts +50 -0
- package/dist/orm/model/entity-metadata.js +341 -0
- package/dist/orm/model/index-metadata.d.ts +18 -0
- package/dist/orm/model/index-metadata.js +2 -0
- package/dist/orm/orm.const.d.ts +1 -1
- package/dist/orm/orm.const.js +3 -3
- package/dist/orm/orm.type.d.ts +1 -92
- package/dist/orm/repository.class.d.ts +5 -4
- package/dist/orm/repository.class.js +27 -5
- package/dist/orm/util/apply-mixins.d.ts +1 -0
- package/dist/orm/util/apply-mixins.js +12 -0
- package/dist/orm/util/extract-keyvalues.d.ts +2 -2
- package/dist/orm/util/extract-keyvalues.js +3 -2
- package/dist/orm/util/orm.helper.d.ts +8 -9
- package/dist/orm/util/orm.helper.js +8 -9
- package/dist/orm/util/serialize-element.d.ts +2 -2
- package/package.json +4 -4
- package/dist/orm/base-entity.class.d.ts +0 -16
- package/dist/orm/base-entity.class.js +0 -56
- package/dist/orm/model/abstract-entityelement.d.ts +0 -8
- package/dist/orm/model/abstract-entityelement.js +0 -10
- package/dist/orm/model/entity-association-element.d.ts +0 -9
- package/dist/orm/model/entity-association-element.js +0 -13
- package/dist/orm/model/entity-column-element.js +0 -27
- package/dist/orm/model/entity-model.d.ts +0 -59
- package/dist/orm/model/entity-model.js +0 -295
- package/dist/orm/model/entity-object-element.d.ts +0 -12
- package/dist/orm/model/entity-object-element.js +0 -24
- package/dist/orm/model/index-meta.d.ts +0 -9
- package/dist/orm/model/index-meta.js +0 -16
- package/dist/orm/util/entity-mapping.d.ts +0 -12
- package/dist/orm/util/entity-mapping.js +0 -154
package/dist/client/Adapter.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Maybe } from 'ts-gems';
|
|
2
2
|
import { classes } from '@sqb/builder';
|
|
3
|
-
import { ClientConfiguration, QueryRequest, RowType
|
|
3
|
+
import { ClientConfiguration, DataType, QueryRequest, RowType } from './types';
|
|
4
4
|
export interface Adapter {
|
|
5
5
|
driver: string;
|
|
6
6
|
dialect: string;
|
package/dist/client/Cursor.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Adapter } from './Adapter';
|
|
2
|
-
import {
|
|
2
|
+
import { CursorStream, CursorStreamOptions } from './CursorStream';
|
|
3
3
|
import { FieldInfoMap } from './FieldInfoMap';
|
|
4
|
+
import { SqbConnection } from './SqbConnection';
|
|
4
5
|
import { ObjectRow, QueryRequest } from './types';
|
|
5
|
-
import { CursorStream, CursorStreamOptions } from './CursorStream';
|
|
6
6
|
interface CursorEvents {
|
|
7
7
|
close: () => void;
|
|
8
8
|
error: (error: unknown) => void;
|
package/dist/client/Cursor.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Cursor = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
6
6
|
const doublylinked_1 = tslib_1.__importDefault(require("doublylinked"));
|
|
7
7
|
const putil_taskqueue_1 = tslib_1.__importDefault(require("putil-taskqueue"));
|
|
8
|
-
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
9
8
|
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
10
|
-
const
|
|
9
|
+
const strict_typed_events_1 = require("strict-typed-events");
|
|
11
10
|
const CursorStream_1 = require("./CursorStream");
|
|
11
|
+
const helpers_1 = require("./helpers");
|
|
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
14
|
constructor(connection, fields, adapterCursor, request) {
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CursorStream = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const stream_1 = require("stream");
|
|
6
5
|
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
6
|
+
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 {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Pool as LightningPool } from 'lightning-pool';
|
|
2
2
|
import { Maybe, Type } from 'ts-gems';
|
|
3
3
|
import { classes } from '@sqb/builder';
|
|
4
|
-
import { ClientConfiguration, QueryExecuteOptions, TransactionFunction, ClientDefaults, ConnectionOptions, QueryRequest, ObjectQueryResult, ArrayQueryResult } from './types';
|
|
5
|
-
import { SqbConnection } from './SqbConnection';
|
|
6
4
|
import { Repository } from '../orm/repository.class';
|
|
5
|
+
import { SqbConnection } from './SqbConnection';
|
|
6
|
+
import { ArrayQueryResult, ClientConfiguration, ClientDefaults, ConnectionOptions, ObjectQueryResult, QueryExecuteOptions, QueryRequest, TransactionFunction } from './types';
|
|
7
7
|
declare const inspect: unique symbol;
|
|
8
8
|
interface SqbClientEvents {
|
|
9
9
|
execute: (request: QueryRequest) => void;
|
package/dist/client/SqbClient.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SqbClient = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
5
6
|
const lightning_pool_1 = require("lightning-pool");
|
|
6
7
|
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
7
8
|
const strict_typed_events_1 = require("strict-typed-events");
|
|
8
|
-
const
|
|
9
|
-
const SqbConnection_1 = require("./SqbConnection");
|
|
10
|
-
const extensions_1 = require("./extensions");
|
|
9
|
+
const entity_metadata_1 = require("../orm/model/entity-metadata");
|
|
11
10
|
const repository_class_1 = require("../orm/repository.class");
|
|
12
|
-
const
|
|
11
|
+
const extensions_1 = require("./extensions");
|
|
12
|
+
const SqbConnection_1 = require("./SqbConnection");
|
|
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) {
|
|
@@ -146,7 +146,7 @@ class SqbClient extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict
|
|
|
146
146
|
}
|
|
147
147
|
else
|
|
148
148
|
ctor = entity;
|
|
149
|
-
const entityDef =
|
|
149
|
+
const entityDef = entity_metadata_1.EntityMetadata.get(ctor);
|
|
150
150
|
if (!entityDef)
|
|
151
151
|
throw new Error(`You must provide an @Entity annotated constructor`);
|
|
152
152
|
return new repository_class_1.Repository(entityDef, this, opts?.schema);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { classes } from '@sqb/builder';
|
|
2
1
|
import { Type } from 'ts-gems';
|
|
2
|
+
import { classes } from '@sqb/builder';
|
|
3
|
+
import { Repository } from '../orm/repository.class';
|
|
4
|
+
import { Adapter } from './Adapter';
|
|
3
5
|
import { SqbClient } from './SqbClient';
|
|
4
6
|
import { ConnectionOptions, QueryExecuteOptions, QueryRequest } from './types';
|
|
5
|
-
import { Adapter } from './Adapter';
|
|
6
|
-
import { Repository } from '../orm/repository.class';
|
|
7
7
|
interface SqbConnectionEvents {
|
|
8
8
|
close: () => void;
|
|
9
9
|
execute: (request: QueryRequest) => void;
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SqbConnection = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const builder_1 = require("@sqb/builder");
|
|
6
|
-
const strict_typed_events_1 = require("strict-typed-events");
|
|
7
5
|
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
8
6
|
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
9
|
-
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
10
7
|
const putil_taskqueue_1 = tslib_1.__importDefault(require("putil-taskqueue"));
|
|
11
|
-
const
|
|
12
|
-
const
|
|
8
|
+
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
9
|
+
const strict_typed_events_1 = require("strict-typed-events");
|
|
10
|
+
const builder_1 = require("@sqb/builder");
|
|
11
|
+
const entity_metadata_1 = require("../orm/model/entity-metadata");
|
|
13
12
|
const repository_class_1 = require("../orm/repository.class");
|
|
14
|
-
const
|
|
13
|
+
const Cursor_1 = require("./Cursor");
|
|
14
|
+
const helpers_1 = require("./helpers");
|
|
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
17
|
constructor(client, adapterConnection, options) {
|
|
@@ -96,7 +96,7 @@ class SqbConnection extends (0, strict_typed_events_1.TypedEventEmitterClass)(st
|
|
|
96
96
|
}
|
|
97
97
|
else
|
|
98
98
|
ctor = entity;
|
|
99
|
-
const entityDef =
|
|
99
|
+
const entityDef = entity_metadata_1.EntityMetadata.get(ctor);
|
|
100
100
|
if (!entityDef)
|
|
101
101
|
throw new Error(`You must provide an @Entity annotated constructor`);
|
|
102
102
|
return new repository_class_1.Repository(entityDef, this, opts?.schema);
|
package/dist/client/helpers.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Maybe } from 'ts-gems';
|
|
2
|
-
import { ArrayRowset, FieldNaming, ObjectRowset, QueryRequest } from './types';
|
|
3
|
-
import { FieldInfoMap } from './FieldInfoMap';
|
|
4
2
|
import { Adapter } from './Adapter';
|
|
3
|
+
import { FieldInfoMap } from './FieldInfoMap';
|
|
4
|
+
import { ArrayRowset, FieldNaming, ObjectRowset, QueryRequest } from './types';
|
|
5
5
|
export declare function applyNamingStrategy(value: string, namingStrategy?: FieldNaming): Maybe<string>;
|
|
6
6
|
export declare function wrapAdapterFields(oldFields: Adapter.Field[], fieldNaming?: FieldNaming): FieldInfoMap;
|
|
7
7
|
export declare function normalizeRowsToObjectRows(fields: FieldInfoMap, rowType: 'array' | 'object', oldRows: ObjectRowset | ArrayRowset, options?: Pick<QueryRequest, 'ignoreNulls' | 'transform'>): Record<string, any>[];
|
package/dist/client/types.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import type { PoolConfiguration } from 'lightning-pool';
|
|
1
2
|
import { Maybe } from 'ts-gems';
|
|
2
3
|
import { DataType, ParamOptions } from '@sqb/builder';
|
|
3
|
-
import type { SqbConnection } from './SqbConnection';
|
|
4
|
-
import type { FieldInfoMap } from './FieldInfoMap';
|
|
5
|
-
import type { Cursor } from './Cursor';
|
|
6
|
-
import type { PoolConfiguration } from 'lightning-pool';
|
|
7
4
|
import type { Adapter } from './Adapter';
|
|
5
|
+
import type { Cursor } from './Cursor';
|
|
6
|
+
import type { FieldInfoMap } from './FieldInfoMap';
|
|
7
|
+
import type { SqbConnection } from './SqbConnection';
|
|
8
8
|
export { DataType } from '@sqb/builder';
|
|
9
9
|
export declare type ExecuteHookFunction = (connection: SqbConnection, request: QueryRequest) => Promise<void>;
|
|
10
10
|
export declare type FetchFunction = (row: any, request: QueryRequest) => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
1
2
|
export { Type, Maybe, DeepPartial, DeepPickWritable, DeepBuildable } from 'ts-gems';
|
|
2
3
|
export * from './types';
|
|
3
4
|
export * from './client/types';
|
|
@@ -7,22 +8,26 @@ export * from './client/SqbConnection';
|
|
|
7
8
|
export * from './client/Cursor';
|
|
8
9
|
export { registerAdapter, unRegisterAdapter } from './client/extensions';
|
|
9
10
|
export * from './orm/orm.type';
|
|
10
|
-
export * from './orm/
|
|
11
|
-
export * from './orm/
|
|
12
|
-
export * from './orm/
|
|
13
|
-
export * from './orm/
|
|
11
|
+
export * from './orm/orm.const';
|
|
12
|
+
export * from './orm/base-entity';
|
|
13
|
+
export * from './orm/repository.class';
|
|
14
|
+
export * from './orm/model/entity-metadata';
|
|
15
|
+
export * from './orm/model/element-metadata';
|
|
16
|
+
export * from './orm/model/column-element-metadata';
|
|
17
|
+
export * from './orm/model/embedded-element-metadata';
|
|
18
|
+
export * from './orm/model/association-element-metadata';
|
|
19
|
+
export * from './orm/model/association';
|
|
20
|
+
export * from './orm/model/association-node';
|
|
21
|
+
export * from './orm/model/index-metadata';
|
|
22
|
+
export * from './orm/model/link-chain';
|
|
14
23
|
export * from './orm/decorators/column.decorator';
|
|
15
|
-
export * from './orm/decorators/link.decorator';
|
|
16
24
|
export * from './orm/decorators/embedded.decorator';
|
|
17
|
-
export * from './orm/decorators/
|
|
25
|
+
export * from './orm/decorators/entity.decorator';
|
|
18
26
|
export * from './orm/decorators/events.decorator';
|
|
27
|
+
export * from './orm/decorators/foreignkey.decorator';
|
|
28
|
+
export * from './orm/decorators/index.decorator';
|
|
29
|
+
export * from './orm/decorators/link.decorator';
|
|
30
|
+
export * from './orm/decorators/primarykey.decorator';
|
|
19
31
|
export * from './orm/decorators/transform.decorator';
|
|
20
|
-
export
|
|
21
|
-
export * from './orm/
|
|
22
|
-
export * from './orm/model/entity-column-element';
|
|
23
|
-
export * from './orm/model/entity-object-element';
|
|
24
|
-
export * from './orm/model/entity-association-element';
|
|
25
|
-
export * from './orm/model/association';
|
|
26
|
-
export * from './orm/model/index-meta';
|
|
27
|
-
export * from './orm/util/entity-mapping';
|
|
28
|
-
export { isColumnElement, isObjectElement, isAssociationElement, isEntityClass } from './orm/util/orm.helper';
|
|
32
|
+
export { isColumnElement, isEmbeddedElement, isAssociationElement, isEntityClass } from './orm/util/orm.helper';
|
|
33
|
+
export * from './orm/backward';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isEntityClass = exports.isAssociationElement = exports.
|
|
3
|
+
exports.isEntityClass = exports.isAssociationElement = exports.isEmbeddedElement = exports.isColumnElement = exports.unRegisterAdapter = exports.registerAdapter = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
require("reflect-metadata");
|
|
5
6
|
tslib_1.__exportStar(require("./types"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./client/types"), exports);
|
|
7
8
|
tslib_1.__exportStar(require("./client/Adapter"), exports);
|
|
@@ -12,26 +13,30 @@ var extensions_1 = require("./client/extensions");
|
|
|
12
13
|
Object.defineProperty(exports, "registerAdapter", { enumerable: true, get: function () { return extensions_1.registerAdapter; } });
|
|
13
14
|
Object.defineProperty(exports, "unRegisterAdapter", { enumerable: true, get: function () { return extensions_1.unRegisterAdapter; } });
|
|
14
15
|
tslib_1.__exportStar(require("./orm/orm.type"), exports);
|
|
15
|
-
tslib_1.__exportStar(require("./orm/
|
|
16
|
-
tslib_1.__exportStar(require("./orm/
|
|
17
|
-
tslib_1.__exportStar(require("./orm/
|
|
18
|
-
tslib_1.__exportStar(require("./orm/
|
|
16
|
+
tslib_1.__exportStar(require("./orm/orm.const"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./orm/base-entity"), exports);
|
|
18
|
+
tslib_1.__exportStar(require("./orm/repository.class"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./orm/model/entity-metadata"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./orm/model/element-metadata"), exports);
|
|
21
|
+
tslib_1.__exportStar(require("./orm/model/column-element-metadata"), exports);
|
|
22
|
+
tslib_1.__exportStar(require("./orm/model/embedded-element-metadata"), exports);
|
|
23
|
+
tslib_1.__exportStar(require("./orm/model/association-element-metadata"), exports);
|
|
24
|
+
tslib_1.__exportStar(require("./orm/model/association"), exports);
|
|
25
|
+
tslib_1.__exportStar(require("./orm/model/association-node"), exports);
|
|
26
|
+
tslib_1.__exportStar(require("./orm/model/index-metadata"), exports);
|
|
27
|
+
tslib_1.__exportStar(require("./orm/model/link-chain"), exports);
|
|
19
28
|
tslib_1.__exportStar(require("./orm/decorators/column.decorator"), exports);
|
|
20
|
-
tslib_1.__exportStar(require("./orm/decorators/link.decorator"), exports);
|
|
21
29
|
tslib_1.__exportStar(require("./orm/decorators/embedded.decorator"), exports);
|
|
22
|
-
tslib_1.__exportStar(require("./orm/decorators/
|
|
30
|
+
tslib_1.__exportStar(require("./orm/decorators/entity.decorator"), exports);
|
|
23
31
|
tslib_1.__exportStar(require("./orm/decorators/events.decorator"), exports);
|
|
32
|
+
tslib_1.__exportStar(require("./orm/decorators/foreignkey.decorator"), exports);
|
|
33
|
+
tslib_1.__exportStar(require("./orm/decorators/index.decorator"), exports);
|
|
34
|
+
tslib_1.__exportStar(require("./orm/decorators/link.decorator"), exports);
|
|
35
|
+
tslib_1.__exportStar(require("./orm/decorators/primarykey.decorator"), exports);
|
|
24
36
|
tslib_1.__exportStar(require("./orm/decorators/transform.decorator"), exports);
|
|
25
|
-
tslib_1.__exportStar(require("./orm/repository.class"), exports);
|
|
26
|
-
tslib_1.__exportStar(require("./orm/model/entity-model"), exports);
|
|
27
|
-
tslib_1.__exportStar(require("./orm/model/entity-column-element"), exports);
|
|
28
|
-
tslib_1.__exportStar(require("./orm/model/entity-object-element"), exports);
|
|
29
|
-
tslib_1.__exportStar(require("./orm/model/entity-association-element"), exports);
|
|
30
|
-
tslib_1.__exportStar(require("./orm/model/association"), exports);
|
|
31
|
-
tslib_1.__exportStar(require("./orm/model/index-meta"), exports);
|
|
32
|
-
tslib_1.__exportStar(require("./orm/util/entity-mapping"), exports);
|
|
33
37
|
var orm_helper_1 = require("./orm/util/orm.helper");
|
|
34
38
|
Object.defineProperty(exports, "isColumnElement", { enumerable: true, get: function () { return orm_helper_1.isColumnElement; } });
|
|
35
|
-
Object.defineProperty(exports, "
|
|
39
|
+
Object.defineProperty(exports, "isEmbeddedElement", { enumerable: true, get: function () { return orm_helper_1.isEmbeddedElement; } });
|
|
36
40
|
Object.defineProperty(exports, "isAssociationElement", { enumerable: true, get: function () { return orm_helper_1.isAssociationElement; } });
|
|
37
41
|
Object.defineProperty(exports, "isEntityClass", { enumerable: true, get: function () { return orm_helper_1.isEntityClass; } });
|
|
42
|
+
tslib_1.__exportStar(require("./orm/backward"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PickWritable, Type } from 'ts-gems';
|
|
2
|
+
import { Entity } from './decorators/entity.decorator';
|
|
3
|
+
export declare function getInsertColumnNames<T, K extends keyof PickWritable<T>>(ctor: Type<T>): K[];
|
|
4
|
+
export declare function getUpdateColumnNames<T, K extends keyof PickWritable<T>>(ctor: Type<T>): K[];
|
|
5
|
+
export declare function getNonAssociationElementNames<T, K extends keyof PickWritable<T>>(ctor: Type<T>): K[];
|
|
6
|
+
export declare const OmitEntity: typeof Entity.Omit;
|
|
7
|
+
export declare const PickEntity: typeof Entity.Pick;
|
|
8
|
+
export declare const UnionEntity: typeof Entity.Union;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnionEntity = exports.PickEntity = exports.OmitEntity = exports.getNonAssociationElementNames = exports.getUpdateColumnNames = exports.getInsertColumnNames = void 0;
|
|
4
|
+
const entity_decorator_1 = require("./decorators/entity.decorator");
|
|
5
|
+
function getInsertColumnNames(ctor) {
|
|
6
|
+
return entity_decorator_1.Entity.getInsertColumnNames(ctor);
|
|
7
|
+
}
|
|
8
|
+
exports.getInsertColumnNames = getInsertColumnNames;
|
|
9
|
+
function getUpdateColumnNames(ctor) {
|
|
10
|
+
return entity_decorator_1.Entity.getUpdateColumnNames(ctor);
|
|
11
|
+
}
|
|
12
|
+
exports.getUpdateColumnNames = getUpdateColumnNames;
|
|
13
|
+
function getNonAssociationElementNames(ctor) {
|
|
14
|
+
return entity_decorator_1.Entity.getNonAssociationElementNames(ctor);
|
|
15
|
+
}
|
|
16
|
+
exports.getNonAssociationElementNames = getNonAssociationElementNames;
|
|
17
|
+
exports.OmitEntity = entity_decorator_1.Entity.Omit;
|
|
18
|
+
exports.PickEntity = entity_decorator_1.Entity.Pick;
|
|
19
|
+
exports.UnionEntity = entity_decorator_1.Entity.Union;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseEntity = void 0;
|
|
4
|
+
const entity_decorator_1 = require("./decorators/entity.decorator");
|
|
5
|
+
const orm_const_1 = require("./orm.const");
|
|
6
|
+
class BaseEntity {
|
|
7
|
+
constructor(partial) {
|
|
8
|
+
const elements = entity_decorator_1.Entity.getColumnNames(Object.getPrototypeOf(this).constructor);
|
|
9
|
+
if (elements && partial) {
|
|
10
|
+
for (const k of elements)
|
|
11
|
+
if (partial[k] !== undefined)
|
|
12
|
+
this[k] = partial[k];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
async destroy() {
|
|
16
|
+
const repo = this[orm_const_1.REPOSITORY_KEY];
|
|
17
|
+
return repo.destroy(this);
|
|
18
|
+
}
|
|
19
|
+
async exists() {
|
|
20
|
+
const repo = this[orm_const_1.REPOSITORY_KEY];
|
|
21
|
+
return repo.exists(this);
|
|
22
|
+
}
|
|
23
|
+
toJSON() {
|
|
24
|
+
// this method is an placeholder an will be overwritten by declareEntity() method
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.BaseEntity = BaseEntity;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { JoinStatement, LogicalOperator } from '@sqb/builder';
|
|
2
|
-
import { EntityModel } from '../model/entity-model';
|
|
3
2
|
import { AssociationNode } from '../model/association-node';
|
|
3
|
+
import { EntityMetadata } from '../model/entity-metadata';
|
|
4
4
|
export interface JoinInfo {
|
|
5
5
|
association: AssociationNode;
|
|
6
|
-
sourceEntity:
|
|
7
|
-
targetEntity:
|
|
6
|
+
sourceEntity: EntityMetadata;
|
|
7
|
+
targetEntity: EntityMetadata;
|
|
8
8
|
joinAlias: string;
|
|
9
9
|
join: JoinStatement;
|
|
10
10
|
}
|
|
11
11
|
export declare function joinAssociationGetFirst(joinInfos: JoinInfo[], association: AssociationNode, parentAlias: string, innerJoin?: boolean): Promise<JoinInfo>;
|
|
12
12
|
export declare function joinAssociationGetLast(joinInfos: JoinInfo[], association: AssociationNode, parentAlias: string, innerJoin?: boolean): Promise<JoinInfo>;
|
|
13
13
|
export declare function joinAssociation(joinInfos: JoinInfo[], association: AssociationNode, parentAlias: string, innerJoin?: boolean): Promise<JoinInfo[]>;
|
|
14
|
-
export declare function prepareFilter(entityDef:
|
|
14
|
+
export declare function prepareFilter(entityDef: EntityMetadata, filter: any, trgOp: LogicalOperator, tableAlias?: string): Promise<void>;
|
|
@@ -2,6 +2,8 @@
|
|
|
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 embedded_element_metadata_1 = require("../model/embedded-element-metadata");
|
|
6
|
+
const entity_metadata_1 = require("../model/entity-metadata");
|
|
5
7
|
const orm_helper_1 = require("../util/orm.helper");
|
|
6
8
|
async function joinAssociationGetFirst(joinInfos, association, parentAlias, innerJoin) {
|
|
7
9
|
const joins = await joinAssociation(joinInfos, association, parentAlias, innerJoin);
|
|
@@ -79,7 +81,7 @@ async function prepareFilter(entityDef, filter, trgOp, tableAlias = 'T') {
|
|
|
79
81
|
let subSelect;
|
|
80
82
|
for (let i = 0; i < l; i++) {
|
|
81
83
|
pt = itemPath[i];
|
|
82
|
-
const col =
|
|
84
|
+
const col = entity_metadata_1.EntityMetadata.getElement(_curEntity, pt);
|
|
83
85
|
if (!col)
|
|
84
86
|
throw new Error(`Unknown property (${item._left}) defined in filter`);
|
|
85
87
|
// if last item on path
|
|
@@ -92,8 +94,8 @@ async function prepareFilter(entityDef, filter, trgOp, tableAlias = 'T') {
|
|
|
92
94
|
else {
|
|
93
95
|
if ((0, orm_helper_1.isColumnElement)(col))
|
|
94
96
|
throw new Error(`Invalid column (${item._left}) defined in filter`);
|
|
95
|
-
if ((0, orm_helper_1.
|
|
96
|
-
_curEntity = await
|
|
97
|
+
if ((0, orm_helper_1.isEmbeddedElement)(col)) {
|
|
98
|
+
_curEntity = await embedded_element_metadata_1.EmbeddedElementMetadata.resolveType(col);
|
|
97
99
|
_curPrefix = _curPrefix + (col.fieldNamePrefix || '');
|
|
98
100
|
_curSuffix = (col.fieldNameSuffix || '') + _curSuffix;
|
|
99
101
|
continue;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { EntityModel } from '../model/entity-model';
|
|
2
|
-
import { Repository } from '../repository.class';
|
|
3
1
|
import { SqbConnection } from '../../client/SqbConnection';
|
|
2
|
+
import { EntityMetadata } from '../model/entity-metadata';
|
|
3
|
+
import { Repository } from '../repository.class';
|
|
4
4
|
export declare type CountCommandArgs = {
|
|
5
|
-
entity:
|
|
5
|
+
entity: EntityMetadata;
|
|
6
6
|
connection: SqbConnection;
|
|
7
7
|
} & Repository.CountOptions;
|
|
8
8
|
export declare class CountCommand {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { EntityModel } from '../model/entity-model';
|
|
2
1
|
import { SqbConnection } from '../../client/SqbConnection';
|
|
2
|
+
import { EntityMetadata } from '../model/entity-metadata';
|
|
3
3
|
export declare type CreateCommandArgs = {
|
|
4
|
-
entity:
|
|
4
|
+
entity: EntityMetadata;
|
|
5
5
|
connection: SqbConnection;
|
|
6
6
|
values: any;
|
|
7
7
|
returning?: boolean;
|
|
8
8
|
};
|
|
9
9
|
declare type CreateCommandContext = {
|
|
10
|
-
entity:
|
|
10
|
+
entity: EntityMetadata;
|
|
11
11
|
queryParams: any;
|
|
12
12
|
queryValues: any;
|
|
13
13
|
colCount: number;
|
|
@@ -15,6 +15,6 @@ declare type CreateCommandContext = {
|
|
|
15
15
|
export declare class CreateCommand {
|
|
16
16
|
protected constructor();
|
|
17
17
|
static execute(args: CreateCommandArgs): Promise<any>;
|
|
18
|
-
protected static _prepareParams(ctx: CreateCommandContext, entity:
|
|
18
|
+
protected static _prepareParams(ctx: CreateCommandContext, entity: EntityMetadata, values: any, prefix?: string, suffix?: string): Promise<void>;
|
|
19
19
|
}
|
|
20
20
|
export {};
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CreateCommand = void 0;
|
|
4
4
|
const builder_1 = require("@sqb/builder");
|
|
5
|
+
const column_element_metadata_1 = require("../model/column-element-metadata");
|
|
6
|
+
const embedded_element_metadata_1 = require("../model/embedded-element-metadata");
|
|
7
|
+
const entity_metadata_1 = require("../model/entity-metadata");
|
|
5
8
|
const orm_helper_1 = require("../util/orm.helper");
|
|
6
9
|
class CreateCommand {
|
|
7
10
|
// istanbul ignore next
|
|
@@ -25,8 +28,11 @@ class CreateCommand {
|
|
|
25
28
|
if (!ctx.colCount)
|
|
26
29
|
throw new Error('No element given to create new entity instance');
|
|
27
30
|
const query = (0, builder_1.Insert)(tableName, ctx.queryValues);
|
|
28
|
-
if (args.returning
|
|
29
|
-
|
|
31
|
+
if (args.returning) {
|
|
32
|
+
const primaryIndexColumns = entity_metadata_1.EntityMetadata.getPrimaryIndexColumns(entity);
|
|
33
|
+
if (primaryIndexColumns.length)
|
|
34
|
+
query.returning(...primaryIndexColumns.map(col => col.fieldName));
|
|
35
|
+
}
|
|
30
36
|
const qr = await args.connection.execute(query, {
|
|
31
37
|
params: ctx.queryParams,
|
|
32
38
|
objectRows: false,
|
|
@@ -35,7 +41,7 @@ class CreateCommand {
|
|
|
35
41
|
if (args.returning && qr.fields && qr.rows?.length) {
|
|
36
42
|
const keyValues = {};
|
|
37
43
|
for (const f of qr.fields.values()) {
|
|
38
|
-
const el =
|
|
44
|
+
const el = entity_metadata_1.EntityMetadata.getColumnElementByFieldName(entity, f.fieldName);
|
|
39
45
|
if (el)
|
|
40
46
|
keyValues[el.name] = qr.rows[0][f.index];
|
|
41
47
|
}
|
|
@@ -46,7 +52,7 @@ class CreateCommand {
|
|
|
46
52
|
let v;
|
|
47
53
|
prefix = prefix || '';
|
|
48
54
|
suffix = suffix || '';
|
|
49
|
-
for (const col of entity.elements
|
|
55
|
+
for (const col of Object.values(entity.elements)) {
|
|
50
56
|
v = values[col.name];
|
|
51
57
|
if ((0, orm_helper_1.isColumnElement)(col)) {
|
|
52
58
|
if (col.noInsert)
|
|
@@ -62,7 +68,7 @@ class CreateCommand {
|
|
|
62
68
|
throw new Error(`${entity.name}.${col.name} is required and can't be null`);
|
|
63
69
|
continue;
|
|
64
70
|
}
|
|
65
|
-
|
|
71
|
+
column_element_metadata_1.ColumnElementMetadata.checkEnumValue(col, v);
|
|
66
72
|
const fieldName = prefix + col.fieldName + suffix;
|
|
67
73
|
const k = '$input_' + fieldName;
|
|
68
74
|
ctx.queryValues[fieldName] = (0, builder_1.Param)({
|
|
@@ -73,8 +79,8 @@ class CreateCommand {
|
|
|
73
79
|
ctx.queryParams[k] = v;
|
|
74
80
|
ctx.colCount++;
|
|
75
81
|
}
|
|
76
|
-
else if (v != null && (0, orm_helper_1.
|
|
77
|
-
const type = await
|
|
82
|
+
else if (v != null && (0, orm_helper_1.isEmbeddedElement)(col)) {
|
|
83
|
+
const type = await embedded_element_metadata_1.EmbeddedElementMetadata.resolveType(col);
|
|
78
84
|
await this._prepareParams(ctx, type, v, col.fieldNamePrefix, col.fieldNameSuffix);
|
|
79
85
|
}
|
|
80
86
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { EntityModel } from '../model/entity-model';
|
|
2
|
-
import { Repository } from '../repository.class';
|
|
3
1
|
import { SqbConnection } from '../../client/SqbConnection';
|
|
2
|
+
import { EntityMetadata } from '../model/entity-metadata';
|
|
3
|
+
import { Repository } from '../repository.class';
|
|
4
4
|
export declare type DestroyCommandArgs = {
|
|
5
|
-
entity:
|
|
5
|
+
entity: EntityMetadata;
|
|
6
6
|
connection: SqbConnection;
|
|
7
7
|
} & Repository.DestroyOptions;
|
|
8
8
|
export declare class DestroyCommand {
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
+
import { SqbConnection } from '../../client/SqbConnection';
|
|
2
|
+
import { AssociationNode } from '../model/association-node';
|
|
3
|
+
import { EntityMetadata } from '../model/entity-metadata';
|
|
1
4
|
import type { Repository } from '../repository.class';
|
|
2
|
-
import type { EntityModel } from '../model/entity-model';
|
|
3
5
|
import { RowConverter } from './row-converter';
|
|
4
|
-
import { AssociationNode } from '../model/association-node';
|
|
5
|
-
import { SqbConnection } from '../../client/SqbConnection';
|
|
6
6
|
export declare type FindCommandArgs = {
|
|
7
|
-
entity:
|
|
7
|
+
entity: EntityMetadata;
|
|
8
8
|
connection: SqbConnection;
|
|
9
9
|
} & Repository.FindAllOptions;
|
|
10
10
|
export declare class FindCommand {
|
|
11
11
|
maxEagerFetch: number;
|
|
12
12
|
maxSubQueries: number;
|
|
13
|
-
readonly mainEntity:
|
|
14
|
-
readonly resultEntity:
|
|
13
|
+
readonly mainEntity: EntityMetadata;
|
|
14
|
+
readonly resultEntity: EntityMetadata;
|
|
15
15
|
readonly converter: RowConverter;
|
|
16
16
|
readonly mainAlias: string;
|
|
17
17
|
resultAlias: string;
|
|
@@ -19,8 +19,8 @@ export declare class FindCommand {
|
|
|
19
19
|
private _selectColumns;
|
|
20
20
|
private _filter;
|
|
21
21
|
private _sort?;
|
|
22
|
-
protected constructor(selectEntity:
|
|
23
|
-
static create(source:
|
|
22
|
+
protected constructor(selectEntity: EntityMetadata, outputEntity: EntityMetadata);
|
|
23
|
+
static create(source: EntityMetadata | AssociationNode, opts?: {
|
|
24
24
|
maxSubQueries?: number;
|
|
25
25
|
maxEagerFetch?: number;
|
|
26
26
|
}): Promise<FindCommand>;
|
|
@@ -28,7 +28,7 @@ export declare class FindCommand {
|
|
|
28
28
|
addElements(opts?: {
|
|
29
29
|
tableAlias?: string;
|
|
30
30
|
converter?: RowConverter;
|
|
31
|
-
entity?:
|
|
31
|
+
entity?: EntityMetadata;
|
|
32
32
|
elements?: string[];
|
|
33
33
|
include?: string[];
|
|
34
34
|
exclude?: string[];
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FindCommand = void 0;
|
|
4
4
|
const builder_1 = require("@sqb/builder");
|
|
5
|
-
const
|
|
5
|
+
const entity_decorator_1 = require("../decorators/entity.decorator");
|
|
6
6
|
const association_node_1 = require("../model/association-node");
|
|
7
|
+
const embedded_element_metadata_1 = require("../model/embedded-element-metadata");
|
|
8
|
+
const entity_metadata_1 = require("../model/entity-metadata");
|
|
7
9
|
const orm_helper_1 = require("../util/orm.helper");
|
|
8
10
|
const command_helper_1 = require("./command.helper");
|
|
9
|
-
const
|
|
11
|
+
const row_converter_1 = require("./row-converter");
|
|
10
12
|
const SORT_ORDER_PATTERN = /^([-+])?(.*)$/;
|
|
11
13
|
class FindCommand {
|
|
12
14
|
constructor(selectEntity, outputEntity) {
|
|
@@ -76,7 +78,7 @@ class FindCommand {
|
|
|
76
78
|
const _exclude = opts.exclude ?
|
|
77
79
|
opts.exclude.map(x => x.toLowerCase()) : undefined;
|
|
78
80
|
const requestElements = _elements ? [..._elements] :
|
|
79
|
-
|
|
81
|
+
entity_decorator_1.Entity.getNonAssociationElementNames(entity.ctor)
|
|
80
82
|
.map(x => x.toLowerCase());
|
|
81
83
|
if (_include)
|
|
82
84
|
requestElements.push(..._include);
|
|
@@ -84,8 +86,8 @@ class FindCommand {
|
|
|
84
86
|
opts.sort.map(x => x.toLowerCase()) : undefined;
|
|
85
87
|
const prefix = opts.prefix || '';
|
|
86
88
|
const suffix = opts.suffix || '';
|
|
87
|
-
for (const key of entity.
|
|
88
|
-
const col =
|
|
89
|
+
for (const key of Object.keys(entity.elements)) {
|
|
90
|
+
const col = entity_metadata_1.EntityMetadata.getElement(entity, key);
|
|
89
91
|
if (!col)
|
|
90
92
|
continue;
|
|
91
93
|
const colNameLower = col.name.toLowerCase();
|
|
@@ -108,8 +110,8 @@ class FindCommand {
|
|
|
108
110
|
});
|
|
109
111
|
continue;
|
|
110
112
|
}
|
|
111
|
-
if ((0, orm_helper_1.
|
|
112
|
-
const typ = await
|
|
113
|
+
if ((0, orm_helper_1.isEmbeddedElement)(col)) {
|
|
114
|
+
const typ = await embedded_element_metadata_1.EmbeddedElementMetadata.resolveType(col);
|
|
113
115
|
const subConverter = converter.addObjectProperty({
|
|
114
116
|
name: col.name,
|
|
115
117
|
type: typ.ctor
|
|
@@ -213,9 +215,9 @@ class FindCommand {
|
|
|
213
215
|
if (elName.includes('.')) {
|
|
214
216
|
const a = elName.split('.');
|
|
215
217
|
while (a.length > 1) {
|
|
216
|
-
const col =
|
|
217
|
-
if ((0, orm_helper_1.
|
|
218
|
-
_entityDef = await
|
|
218
|
+
const col = entity_metadata_1.EntityMetadata.getElement(_entityDef, a.shift() || '');
|
|
219
|
+
if ((0, orm_helper_1.isEmbeddedElement)(col)) {
|
|
220
|
+
_entityDef = await embedded_element_metadata_1.EmbeddedElementMetadata.resolveType(col);
|
|
219
221
|
if (col.fieldNamePrefix)
|
|
220
222
|
prefix += col.fieldNamePrefix;
|
|
221
223
|
if (col.fieldNameSuffix)
|
|
@@ -237,7 +239,7 @@ class FindCommand {
|
|
|
237
239
|
continue;
|
|
238
240
|
elName = a.shift() || '';
|
|
239
241
|
}
|
|
240
|
-
const col =
|
|
242
|
+
const col = entity_metadata_1.EntityMetadata.getElement(_entityDef, elName);
|
|
241
243
|
if (!col)
|
|
242
244
|
throw new Error(`Unknown element (${elName}) declared in sort property`);
|
|
243
245
|
if (!(0, orm_helper_1.isColumnElement)(col))
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Type } from 'ts-gems';
|
|
2
|
+
import { DataType } from '@sqb/builder';
|
|
2
3
|
import type { FieldInfoMap } from '../../client/FieldInfoMap';
|
|
3
|
-
import type { FindCommand } from './find.command';
|
|
4
|
-
import type { Repository } from '../repository.class';
|
|
5
|
-
import { ColumnTransformFunction } from '../orm.type';
|
|
6
4
|
import { SqbConnection } from '../../client/SqbConnection';
|
|
7
|
-
import {
|
|
5
|
+
import { ColumnTransformFunction } from '../orm.type';
|
|
6
|
+
import type { Repository } from '../repository.class';
|
|
7
|
+
import type { FindCommand } from './find.command';
|
|
8
8
|
export interface ValueProperty {
|
|
9
9
|
fieldAlias: string;
|
|
10
10
|
dataType?: DataType;
|