@sqb/connect 4.0.7 → 4.0.8
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/package.json +4 -4
- package/dist/client/Adapter.d.ts +0 -57
- package/dist/client/Adapter.js +0 -2
- package/dist/client/Cursor.d.ts +0 -116
- package/dist/client/Cursor.js +0 -250
- package/dist/client/CursorStream.d.ts +0 -29
- package/dist/client/CursorStream.js +0 -98
- package/dist/client/FieldInfoMap.d.ts +0 -10
- package/dist/client/FieldInfoMap.js +0 -33
- package/dist/client/SqbClient.d.ts +0 -70
- package/dist/client/SqbClient.js +0 -165
- package/dist/client/SqbConnection.d.ts +0 -74
- package/dist/client/SqbConnection.js +0 -272
- package/dist/client/extensions.d.ts +0 -4
- package/dist/client/extensions.js +0 -14
- package/dist/client/helpers.d.ts +0 -9
- package/dist/client/helpers.js +0 -133
- package/dist/client/types.d.ts +0 -189
- package/dist/client/types.js +0 -5
- package/dist/index.d.ts +0 -28
- package/dist/index.js +0 -37
- package/dist/orm/base-entity.class.d.ts +0 -16
- package/dist/orm/base-entity.class.js +0 -56
- package/dist/orm/commands/command.helper.d.ts +0 -14
- package/dist/orm/commands/command.helper.js +0 -140
- package/dist/orm/commands/count.command.d.ts +0 -11
- package/dist/orm/commands/count.command.js +0 -30
- package/dist/orm/commands/create.command.d.ts +0 -20
- package/dist/orm/commands/create.command.js +0 -83
- package/dist/orm/commands/destroy.command.d.ts +0 -11
- package/dist/orm/commands/destroy.command.js +0 -30
- package/dist/orm/commands/find.command.d.ts +0 -44
- package/dist/orm/commands/find.command.js +0 -308
- package/dist/orm/commands/row-converter.d.ts +0 -55
- package/dist/orm/commands/row-converter.js +0 -187
- package/dist/orm/commands/update.command.d.ts +0 -22
- package/dist/orm/commands/update.command.js +0 -82
- package/dist/orm/decorators/column.decorator.d.ts +0 -4
- package/dist/orm/decorators/column.decorator.js +0 -14
- package/dist/orm/decorators/embedded.decorator.d.ts +0 -2
- package/dist/orm/decorators/embedded.decorator.js +0 -17
- package/dist/orm/decorators/entity.decorator.d.ts +0 -6
- package/dist/orm/decorators/entity.decorator.js +0 -23
- package/dist/orm/decorators/events.decorator.d.ts +0 -6
- package/dist/orm/decorators/events.decorator.js +0 -76
- package/dist/orm/decorators/foreignkey.decorator.d.ts +0 -2
- package/dist/orm/decorators/foreignkey.decorator.js +0 -13
- package/dist/orm/decorators/index.decorator.d.ts +0 -3
- package/dist/orm/decorators/index.decorator.js +0 -22
- package/dist/orm/decorators/link.decorator.d.ts +0 -23
- package/dist/orm/decorators/link.decorator.js +0 -88
- package/dist/orm/decorators/primarykey.decorator.d.ts +0 -3
- package/dist/orm/decorators/primarykey.decorator.js +0 -23
- package/dist/orm/decorators/transform.decorator.d.ts +0 -3
- package/dist/orm/decorators/transform.decorator.js +0 -24
- package/dist/orm/model/abstract-entityelement.d.ts +0 -8
- package/dist/orm/model/abstract-entityelement.js +0 -10
- package/dist/orm/model/association-node.d.ts +0 -9
- package/dist/orm/model/association-node.js +0 -25
- package/dist/orm/model/association.d.ts +0 -28
- package/dist/orm/model/association.js +0 -129
- 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.d.ts +0 -68
- 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/model/link-chain.d.ts +0 -15
- package/dist/orm/model/link-chain.js +0 -50
- package/dist/orm/orm.const.d.ts +0 -2
- package/dist/orm/orm.const.js +0 -5
- package/dist/orm/orm.type.d.ts +0 -112
- package/dist/orm/orm.type.js +0 -2
- package/dist/orm/repository.class.d.ts +0 -125
- package/dist/orm/repository.class.js +0 -217
- package/dist/orm/util/entity-mapping.d.ts +0 -12
- package/dist/orm/util/entity-mapping.js +0 -154
- package/dist/orm/util/extract-keyvalues.d.ts +0 -2
- package/dist/orm/util/extract-keyvalues.js +0 -60
- package/dist/orm/util/orm.helper.d.ts +0 -14
- package/dist/orm/util/orm.helper.js +0 -39
- package/dist/orm/util/serialize-element.d.ts +0 -2
- package/dist/orm/util/serialize-element.js +0 -43
- package/dist/types.d.ts +0 -2
- package/dist/types.js +0 -2
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Type } from 'ts-gems';
|
|
2
|
-
import { AssociationKind, TypeResolver, TypeThunk } from '../orm.type';
|
|
3
|
-
import { AssociationNode } from './association-node';
|
|
4
|
-
export declare class LinkChain<T> {
|
|
5
|
-
target: TypeThunk<T>;
|
|
6
|
-
first: AssociationNode;
|
|
7
|
-
current: AssociationNode;
|
|
8
|
-
constructor(target: TypeThunk<T>, kind: AssociationKind, targetKey?: keyof T, sourceKey?: string);
|
|
9
|
-
where(conditions: object | object[]): this;
|
|
10
|
-
linkToOne<K>(target: Type<K> | TypeResolver<K>, targetColumn?: keyof K, parentColumn?: keyof T): LinkChain<K>;
|
|
11
|
-
linkToMany<K>(target: Type<K> | TypeResolver<K>, targetColumn?: keyof K, parentColumn?: keyof T): LinkChain<K>;
|
|
12
|
-
linkFromOne<K>(target: Type<K> | TypeResolver<K>, targetColumn?: keyof K, parentColumn?: keyof T): LinkChain<K>;
|
|
13
|
-
linkFromMany<K>(target: Type<K> | TypeResolver<K>, targetColumn?: keyof K, parentColumn?: keyof T): LinkChain<K>;
|
|
14
|
-
private _newNode;
|
|
15
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LinkChain = void 0;
|
|
4
|
-
const association_node_1 = require("./association-node");
|
|
5
|
-
class LinkChain {
|
|
6
|
-
constructor(target, kind, targetKey, sourceKey) {
|
|
7
|
-
this.target = target;
|
|
8
|
-
this.first = this.current = new association_node_1.AssociationNode('', {
|
|
9
|
-
kind,
|
|
10
|
-
target,
|
|
11
|
-
source: null,
|
|
12
|
-
sourceKey,
|
|
13
|
-
targetKey: targetKey
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
where(conditions) {
|
|
17
|
-
this.current.conditions = this.current.conditions || [];
|
|
18
|
-
if (Array.isArray(conditions))
|
|
19
|
-
this.current.conditions.push(...conditions);
|
|
20
|
-
else
|
|
21
|
-
this.current.conditions.push(conditions);
|
|
22
|
-
return this;
|
|
23
|
-
}
|
|
24
|
-
linkToOne(target, targetColumn, parentColumn) {
|
|
25
|
-
return this._newNode(target, 'to', targetColumn, parentColumn);
|
|
26
|
-
}
|
|
27
|
-
linkToMany(target, targetColumn, parentColumn) {
|
|
28
|
-
return this._newNode(target, 'to-many', targetColumn, parentColumn);
|
|
29
|
-
}
|
|
30
|
-
linkFromOne(target, targetColumn, parentColumn) {
|
|
31
|
-
return this._newNode(target, 'from', targetColumn, parentColumn);
|
|
32
|
-
}
|
|
33
|
-
linkFromMany(target, targetColumn, parentColumn) {
|
|
34
|
-
return this._newNode(target, 'from-many', targetColumn, parentColumn);
|
|
35
|
-
}
|
|
36
|
-
_newNode(target, kind, targetKey, parentKey) {
|
|
37
|
-
const child = new association_node_1.AssociationNode(this.current.name, {
|
|
38
|
-
kind,
|
|
39
|
-
source: this.current.target,
|
|
40
|
-
target,
|
|
41
|
-
sourceKey: parentKey,
|
|
42
|
-
targetKey: targetKey
|
|
43
|
-
});
|
|
44
|
-
child.prior = this.current;
|
|
45
|
-
this.current.next = child;
|
|
46
|
-
this.current = child;
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.LinkChain = LinkChain;
|
package/dist/orm/orm.const.d.ts
DELETED
package/dist/orm/orm.const.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.REPOSITORY_KEY = exports.ENTITY_DEFINITION_KEY = void 0;
|
|
4
|
-
exports.ENTITY_DEFINITION_KEY = Symbol.for('sqb.entity-definition');
|
|
5
|
-
exports.REPOSITORY_KEY = Symbol.for('sqb.entity.repository');
|
package/dist/orm/orm.type.d.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { Type } from 'ts-gems';
|
|
2
|
-
import { DataType } from '..';
|
|
3
|
-
export declare type ElementKind = 'column' | 'object' | 'association';
|
|
4
|
-
export declare type AssociationKind = 'to' | 'to-many' | 'from' | 'from-many';
|
|
5
|
-
/**
|
|
6
|
-
* Indicates auto generation strategy
|
|
7
|
-
*/
|
|
8
|
-
export declare type ColumnAutoGenerationStrategy = 'increment' | 'uuid' | 'rowid' | 'timestamp' | 'custom';
|
|
9
|
-
export declare type ColumnTransformFunction = (value: any, name: string) => any;
|
|
10
|
-
export declare type TypeResolver<T> = () => Type<T> | Promise<Type<T>>;
|
|
11
|
-
export declare type TypeThunk<T = any> = Type<T> | TypeResolver<T>;
|
|
12
|
-
export declare type EnumValue = (FieldValue)[] | Object;
|
|
13
|
-
export declare type FieldValue = string | number | boolean | Date | null;
|
|
14
|
-
export declare type DefaultValueGetter = (obj?: any) => FieldValue;
|
|
15
|
-
export interface EntityConfig {
|
|
16
|
-
/**
|
|
17
|
-
* Name of the table name. Default: entity class name.
|
|
18
|
-
*/
|
|
19
|
-
tableName?: string;
|
|
20
|
-
/**
|
|
21
|
-
* Schema name which entity belongs to
|
|
22
|
-
*/
|
|
23
|
-
schema?: string;
|
|
24
|
-
/**
|
|
25
|
-
* Table comment
|
|
26
|
-
*/
|
|
27
|
-
comment?: string;
|
|
28
|
-
}
|
|
29
|
-
export interface IndexOptions {
|
|
30
|
-
/**
|
|
31
|
-
* Name of the index
|
|
32
|
-
*/
|
|
33
|
-
name?: string;
|
|
34
|
-
/**
|
|
35
|
-
* Specifies if index is unique
|
|
36
|
-
*/
|
|
37
|
-
unique?: boolean;
|
|
38
|
-
}
|
|
39
|
-
export interface AssociationSettings {
|
|
40
|
-
source: TypeThunk;
|
|
41
|
-
target: TypeThunk;
|
|
42
|
-
sourceKey?: string;
|
|
43
|
-
targetKey?: string;
|
|
44
|
-
kind?: AssociationKind;
|
|
45
|
-
}
|
|
46
|
-
export interface DataPropertyOptions {
|
|
47
|
-
type?: Function;
|
|
48
|
-
/**
|
|
49
|
-
* Column data type
|
|
50
|
-
*/
|
|
51
|
-
dataType?: DataType;
|
|
52
|
-
/**
|
|
53
|
-
*
|
|
54
|
-
*/
|
|
55
|
-
isArray?: boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Field name in the database table. Default: property name
|
|
58
|
-
*/
|
|
59
|
-
fieldName?: string;
|
|
60
|
-
/**
|
|
61
|
-
* Field comment
|
|
62
|
-
*/
|
|
63
|
-
comment?: string;
|
|
64
|
-
/**
|
|
65
|
-
* Character or byte length of column
|
|
66
|
-
*/
|
|
67
|
-
length?: number;
|
|
68
|
-
/**
|
|
69
|
-
* Column's default value
|
|
70
|
-
*/
|
|
71
|
-
default?: FieldValue | DefaultValueGetter;
|
|
72
|
-
/**
|
|
73
|
-
* The precision for a decimal field
|
|
74
|
-
*/
|
|
75
|
-
precision?: number;
|
|
76
|
-
/**
|
|
77
|
-
* The scale for a decimal field
|
|
78
|
-
*/
|
|
79
|
-
scale?: number;
|
|
80
|
-
/**
|
|
81
|
-
* Fields's collation.
|
|
82
|
-
*/
|
|
83
|
-
collation?: string;
|
|
84
|
-
/**
|
|
85
|
-
* Indicates auto generation strategy
|
|
86
|
-
*/
|
|
87
|
-
autoGenerated?: ColumnAutoGenerationStrategy;
|
|
88
|
-
/**
|
|
89
|
-
* Indicates enum values
|
|
90
|
-
*/
|
|
91
|
-
enum?: EnumValue;
|
|
92
|
-
/**
|
|
93
|
-
* Indicates if column value can be null
|
|
94
|
-
*/
|
|
95
|
-
notNull?: boolean;
|
|
96
|
-
/**
|
|
97
|
-
* Indicates whether or not to hide this column by default when making queries.
|
|
98
|
-
*/
|
|
99
|
-
hidden?: boolean;
|
|
100
|
-
/**
|
|
101
|
-
* Indicates if column value is used in update queries
|
|
102
|
-
*/
|
|
103
|
-
noUpdate?: boolean;
|
|
104
|
-
/**
|
|
105
|
-
* Indicates if column value is used in insert queries
|
|
106
|
-
*/
|
|
107
|
-
noInsert?: boolean;
|
|
108
|
-
}
|
|
109
|
-
export interface EmbeddedTypeOptions {
|
|
110
|
-
fieldNamePrefix?: string;
|
|
111
|
-
fieldNameSuffix?: string;
|
|
112
|
-
}
|
package/dist/orm/orm.type.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { DeepPartial, Type } from 'ts-gems';
|
|
2
|
-
import { AsyncEventEmitter } from 'strict-typed-events';
|
|
3
|
-
import { SqbClient } from '../client/SqbClient';
|
|
4
|
-
import { SqbConnection } from '../client/SqbConnection';
|
|
5
|
-
import { EntityModel } from './model/entity-model';
|
|
6
|
-
import { QueryRequest, TransactionFunction } from '../client/types';
|
|
7
|
-
import { InstanceValues } from '../types';
|
|
8
|
-
import { FieldInfoMap } from '../client/FieldInfoMap';
|
|
9
|
-
export declare namespace Repository {
|
|
10
|
-
type TransformRowFunction = (fields: FieldInfoMap, row: object, obj: object) => void;
|
|
11
|
-
interface CommandOptions {
|
|
12
|
-
connection?: SqbConnection;
|
|
13
|
-
}
|
|
14
|
-
interface CreateOptions extends CommandOptions {
|
|
15
|
-
elements?: string[];
|
|
16
|
-
include?: string[];
|
|
17
|
-
exclude?: string[];
|
|
18
|
-
}
|
|
19
|
-
interface CountOptions extends CommandOptions {
|
|
20
|
-
filter?: any;
|
|
21
|
-
params?: any;
|
|
22
|
-
}
|
|
23
|
-
interface ExistsOptions extends CommandOptions {
|
|
24
|
-
filter?: any;
|
|
25
|
-
params?: any;
|
|
26
|
-
}
|
|
27
|
-
interface DestroyOptions extends CommandOptions {
|
|
28
|
-
filter?: any;
|
|
29
|
-
params?: any;
|
|
30
|
-
}
|
|
31
|
-
interface FindOneOptions extends CommandOptions {
|
|
32
|
-
elements?: string[];
|
|
33
|
-
include?: string[];
|
|
34
|
-
exclude?: string[];
|
|
35
|
-
filter?: any;
|
|
36
|
-
params?: any;
|
|
37
|
-
sort?: string[];
|
|
38
|
-
offset?: number;
|
|
39
|
-
distinct?: boolean;
|
|
40
|
-
onTransformRow?: TransformRowFunction;
|
|
41
|
-
}
|
|
42
|
-
interface FindAllOptions extends FindOneOptions {
|
|
43
|
-
limit?: number;
|
|
44
|
-
maxEagerFetch?: number;
|
|
45
|
-
maxSubQueries?: number;
|
|
46
|
-
}
|
|
47
|
-
interface GetOptions extends CommandOptions {
|
|
48
|
-
elements?: string[];
|
|
49
|
-
include?: string[];
|
|
50
|
-
exclude?: string[];
|
|
51
|
-
filter?: any;
|
|
52
|
-
params?: any;
|
|
53
|
-
}
|
|
54
|
-
interface UpdateOptions extends CommandOptions {
|
|
55
|
-
elements?: string[];
|
|
56
|
-
include?: string[];
|
|
57
|
-
exclude?: string[];
|
|
58
|
-
filter?: any;
|
|
59
|
-
params?: any;
|
|
60
|
-
}
|
|
61
|
-
interface UpdateAllOptions extends CommandOptions {
|
|
62
|
-
filter?: any;
|
|
63
|
-
params?: any;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
interface RepositoryEvents {
|
|
67
|
-
execute: (request: QueryRequest) => void;
|
|
68
|
-
error: (error: Error) => void;
|
|
69
|
-
acquire: (connection: SqbConnection) => Promise<void>;
|
|
70
|
-
}
|
|
71
|
-
export declare class Repository<T> extends AsyncEventEmitter<RepositoryEvents> {
|
|
72
|
-
private readonly _executor;
|
|
73
|
-
private readonly _entity;
|
|
74
|
-
private readonly _schema?;
|
|
75
|
-
constructor(entityDef: EntityModel, executor: SqbClient | SqbConnection, schema?: string);
|
|
76
|
-
get entity(): EntityModel;
|
|
77
|
-
get type(): Type<T>;
|
|
78
|
-
create(values: InstanceValues<T>, options?: Repository.CreateOptions): Promise<DeepPartial<T>>;
|
|
79
|
-
createOnly(values: InstanceValues<T>, options?: Repository.CreateOptions): Promise<void>;
|
|
80
|
-
exists(keyValue: any | Record<string, any>, options?: Repository.ExistsOptions): Promise<boolean>;
|
|
81
|
-
count(options?: Repository.CountOptions): Promise<number>;
|
|
82
|
-
findAll(options?: Repository.FindAllOptions): Promise<DeepPartial<T>[]>;
|
|
83
|
-
findOne(options?: Repository.FindOneOptions): Promise<DeepPartial<T> | undefined>;
|
|
84
|
-
findByPk(keyValue: any | Record<string, any>, options?: Repository.GetOptions): Promise<DeepPartial<T> | undefined>;
|
|
85
|
-
destroy(keyValue: any | Record<string, any>, options?: Repository.DestroyOptions): Promise<boolean>;
|
|
86
|
-
destroyAll(options?: Repository.DestroyOptions): Promise<number>;
|
|
87
|
-
update(keyValue: any | Record<string, any>, values: InstanceValues<T>, options?: Repository.UpdateOptions): Promise<DeepPartial<T> | undefined>;
|
|
88
|
-
updateOnly(keyValue: any | Record<string, any>, values: InstanceValues<T>, options?: Repository.UpdateOptions): Promise<DeepPartial<T>>;
|
|
89
|
-
updateAll(values: InstanceValues<T>, options?: Repository.UpdateAllOptions): Promise<number>;
|
|
90
|
-
protected _execute(fn: TransactionFunction, opts?: Repository.CommandOptions): Promise<any>;
|
|
91
|
-
protected _create(values: InstanceValues<T>, options: Repository.CreateOptions & {
|
|
92
|
-
connection: SqbConnection;
|
|
93
|
-
}): Promise<DeepPartial<T>>;
|
|
94
|
-
protected _createOnly(values: InstanceValues<T>, options: Repository.CreateOptions & {
|
|
95
|
-
connection: SqbConnection;
|
|
96
|
-
}): Promise<void>;
|
|
97
|
-
protected _exists(keyValue: any | Record<string, any>, options: Repository.ExistsOptions & {
|
|
98
|
-
connection: SqbConnection;
|
|
99
|
-
}): Promise<boolean>;
|
|
100
|
-
protected _count(options: Repository.CountOptions & {
|
|
101
|
-
connection: SqbConnection;
|
|
102
|
-
}): Promise<number>;
|
|
103
|
-
protected _findAll(options: Repository.FindAllOptions & {
|
|
104
|
-
connection: SqbConnection;
|
|
105
|
-
}): Promise<DeepPartial<T>[]>;
|
|
106
|
-
protected _findOne(options: Repository.FindOneOptions & {
|
|
107
|
-
connection: SqbConnection;
|
|
108
|
-
}): Promise<DeepPartial<T> | undefined>;
|
|
109
|
-
protected _findByPk(keyValue: any | Record<string, any>, options: Repository.GetOptions & {
|
|
110
|
-
connection: SqbConnection;
|
|
111
|
-
}): Promise<DeepPartial<T> | undefined>;
|
|
112
|
-
protected _destroy(keyValue: any | Record<string, any>, options: Repository.DestroyOptions & {
|
|
113
|
-
connection: SqbConnection;
|
|
114
|
-
}): Promise<boolean>;
|
|
115
|
-
protected _destroyAll(options: Repository.DestroyOptions & {
|
|
116
|
-
connection: SqbConnection;
|
|
117
|
-
}): Promise<number>;
|
|
118
|
-
protected _update(keyValue: any | Record<string, any>, values: InstanceValues<T>, options: Repository.UpdateOptions & {
|
|
119
|
-
connection: SqbConnection;
|
|
120
|
-
}): Promise<Record<string, any> | undefined>;
|
|
121
|
-
protected _updateAll(values: InstanceValues<T>, options: Repository.UpdateAllOptions & {
|
|
122
|
-
connection: SqbConnection;
|
|
123
|
-
}): Promise<number>;
|
|
124
|
-
}
|
|
125
|
-
export {};
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Repository = void 0;
|
|
4
|
-
const strict_typed_events_1 = require("strict-typed-events");
|
|
5
|
-
const SqbConnection_1 = require("../client/SqbConnection");
|
|
6
|
-
const extract_keyvalues_1 = require("./util/extract-keyvalues");
|
|
7
|
-
const count_command_1 = require("./commands/count.command");
|
|
8
|
-
const create_command_1 = require("./commands/create.command");
|
|
9
|
-
const find_command_1 = require("./commands/find.command");
|
|
10
|
-
const destroy_command_1 = require("./commands/destroy.command");
|
|
11
|
-
const update_command_1 = require("./commands/update.command");
|
|
12
|
-
class Repository extends strict_typed_events_1.AsyncEventEmitter {
|
|
13
|
-
constructor(entityDef, executor, schema) {
|
|
14
|
-
super();
|
|
15
|
-
this._executor = executor;
|
|
16
|
-
this._entity = entityDef;
|
|
17
|
-
this._schema = schema;
|
|
18
|
-
}
|
|
19
|
-
get entity() {
|
|
20
|
-
return this._entity;
|
|
21
|
-
}
|
|
22
|
-
get type() {
|
|
23
|
-
return this._entity.ctor;
|
|
24
|
-
}
|
|
25
|
-
create(values, options) {
|
|
26
|
-
return this._execute(async (connection) => {
|
|
27
|
-
return this._create(values, { ...options, connection });
|
|
28
|
-
}, options);
|
|
29
|
-
}
|
|
30
|
-
createOnly(values, options) {
|
|
31
|
-
return this._execute(async (connection) => {
|
|
32
|
-
return this._createOnly(values, { ...options, connection });
|
|
33
|
-
}, options);
|
|
34
|
-
}
|
|
35
|
-
exists(keyValue, options) {
|
|
36
|
-
return this._execute(async (connection) => {
|
|
37
|
-
return this._exists(keyValue, { ...options, connection });
|
|
38
|
-
}, options);
|
|
39
|
-
}
|
|
40
|
-
count(options) {
|
|
41
|
-
return this._execute(async (connection) => {
|
|
42
|
-
return this._count({ ...options, connection });
|
|
43
|
-
}, options);
|
|
44
|
-
}
|
|
45
|
-
findAll(options) {
|
|
46
|
-
return this._execute(async (connection) => {
|
|
47
|
-
return this._findAll({ ...options, connection });
|
|
48
|
-
}, options);
|
|
49
|
-
}
|
|
50
|
-
findOne(options) {
|
|
51
|
-
return this._execute(async (connection) => {
|
|
52
|
-
return this._findOne({ ...options, connection });
|
|
53
|
-
}, options);
|
|
54
|
-
}
|
|
55
|
-
findByPk(keyValue, options) {
|
|
56
|
-
return this._execute(async (connection) => {
|
|
57
|
-
return this._findByPk(keyValue, { ...options, connection });
|
|
58
|
-
}, options);
|
|
59
|
-
}
|
|
60
|
-
destroy(keyValue, options) {
|
|
61
|
-
return this._execute(async (connection) => {
|
|
62
|
-
return this._destroy(keyValue, { ...options, connection });
|
|
63
|
-
}, options);
|
|
64
|
-
}
|
|
65
|
-
destroyAll(options) {
|
|
66
|
-
return this._execute(async (connection) => {
|
|
67
|
-
return this._destroyAll({ ...options, connection });
|
|
68
|
-
}, options);
|
|
69
|
-
}
|
|
70
|
-
update(keyValue, values, options) {
|
|
71
|
-
return this._execute(async (connection) => {
|
|
72
|
-
const opts = { ...options, connection };
|
|
73
|
-
const keyValues = await this._update(keyValue, values, opts);
|
|
74
|
-
if (keyValues)
|
|
75
|
-
return this._findByPk(keyValues, opts);
|
|
76
|
-
}, options);
|
|
77
|
-
}
|
|
78
|
-
updateOnly(keyValue, values, options) {
|
|
79
|
-
return this._execute(async (connection) => {
|
|
80
|
-
return !!(await this._update(keyValue, values, { ...options, connection }));
|
|
81
|
-
}, options);
|
|
82
|
-
}
|
|
83
|
-
updateAll(values, options) {
|
|
84
|
-
return this._execute(async (connection) => {
|
|
85
|
-
return this._updateAll(values, { ...options, connection });
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
async _execute(fn, opts) {
|
|
89
|
-
let connection = opts?.connection;
|
|
90
|
-
if (!connection && this._executor instanceof SqbConnection_1.SqbConnection)
|
|
91
|
-
connection = this._executor;
|
|
92
|
-
if (connection) {
|
|
93
|
-
if (this._schema)
|
|
94
|
-
await connection.setSchema(this._schema);
|
|
95
|
-
return fn(connection);
|
|
96
|
-
}
|
|
97
|
-
return this._executor.acquire(async (conn) => {
|
|
98
|
-
if (this._schema)
|
|
99
|
-
await conn.setSchema(this._schema);
|
|
100
|
-
await this.emitAsync({ event: 'acquire', serial: true }, conn);
|
|
101
|
-
return fn(conn);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
async _create(values, options) {
|
|
105
|
-
const keyValues = await create_command_1.CreateCommand.execute({
|
|
106
|
-
...options,
|
|
107
|
-
entity: this._entity,
|
|
108
|
-
values,
|
|
109
|
-
returning: true
|
|
110
|
-
});
|
|
111
|
-
const result = keyValues && (await this.findByPk(keyValues, options));
|
|
112
|
-
if (!result)
|
|
113
|
-
throw new Error('Unable to insert new row');
|
|
114
|
-
return result;
|
|
115
|
-
}
|
|
116
|
-
async _createOnly(values, options) {
|
|
117
|
-
await create_command_1.CreateCommand.execute({
|
|
118
|
-
...options,
|
|
119
|
-
entity: this._entity,
|
|
120
|
-
values,
|
|
121
|
-
returning: false
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
async _exists(keyValue, options) {
|
|
125
|
-
const filter = [(0, extract_keyvalues_1.extractKeyValues)(this._entity, keyValue, true)];
|
|
126
|
-
if (options && options.filter) {
|
|
127
|
-
if (Array.isArray(options.filter))
|
|
128
|
-
filter.push(...options.filter);
|
|
129
|
-
else
|
|
130
|
-
filter.push(options.filter);
|
|
131
|
-
}
|
|
132
|
-
return !!(await count_command_1.CountCommand.execute({
|
|
133
|
-
...options,
|
|
134
|
-
filter,
|
|
135
|
-
entity: this._entity
|
|
136
|
-
}));
|
|
137
|
-
}
|
|
138
|
-
async _count(options) {
|
|
139
|
-
return count_command_1.CountCommand.execute({
|
|
140
|
-
...options,
|
|
141
|
-
entity: this._entity
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
async _findAll(options) {
|
|
145
|
-
return await find_command_1.FindCommand.execute({
|
|
146
|
-
...options,
|
|
147
|
-
entity: this._entity,
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
async _findOne(options) {
|
|
151
|
-
const rows = await find_command_1.FindCommand.execute({
|
|
152
|
-
...options,
|
|
153
|
-
entity: this._entity,
|
|
154
|
-
limit: 1
|
|
155
|
-
});
|
|
156
|
-
return rows && rows[0];
|
|
157
|
-
}
|
|
158
|
-
async _findByPk(keyValue, options) {
|
|
159
|
-
const filter = [(0, extract_keyvalues_1.extractKeyValues)(this._entity, keyValue, true)];
|
|
160
|
-
if (options && options.filter) {
|
|
161
|
-
if (Array.isArray(options.filter))
|
|
162
|
-
filter.push(...options.filter);
|
|
163
|
-
else
|
|
164
|
-
filter.push(options.filter);
|
|
165
|
-
}
|
|
166
|
-
return await this._findOne({ ...options, filter, offset: 0 });
|
|
167
|
-
}
|
|
168
|
-
async _destroy(keyValue, options) {
|
|
169
|
-
const filter = [(0, extract_keyvalues_1.extractKeyValues)(this._entity, keyValue, true)];
|
|
170
|
-
if (options && options.filter) {
|
|
171
|
-
if (Array.isArray(options.filter))
|
|
172
|
-
filter.push(...options.filter);
|
|
173
|
-
else
|
|
174
|
-
filter.push(options.filter);
|
|
175
|
-
}
|
|
176
|
-
return !!(await destroy_command_1.DestroyCommand.execute({
|
|
177
|
-
...options,
|
|
178
|
-
filter,
|
|
179
|
-
entity: this._entity,
|
|
180
|
-
}));
|
|
181
|
-
}
|
|
182
|
-
async _destroyAll(options) {
|
|
183
|
-
return destroy_command_1.DestroyCommand.execute({
|
|
184
|
-
...options,
|
|
185
|
-
entity: this._entity,
|
|
186
|
-
filter: options?.filter,
|
|
187
|
-
params: options?.params
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
async _update(keyValue, values, options) {
|
|
191
|
-
const keyValues = (0, extract_keyvalues_1.extractKeyValues)(this._entity, keyValue, true);
|
|
192
|
-
const filter = [keyValues];
|
|
193
|
-
if (options.filter) {
|
|
194
|
-
if (Array.isArray(options.filter))
|
|
195
|
-
filter.push(...options.filter);
|
|
196
|
-
else
|
|
197
|
-
filter.push(options.filter);
|
|
198
|
-
}
|
|
199
|
-
const updateValues = { ...values };
|
|
200
|
-
Object.keys(keyValues).forEach(k => delete updateValues[k]);
|
|
201
|
-
const rowsAffected = await update_command_1.UpdateCommand.execute({
|
|
202
|
-
...options,
|
|
203
|
-
entity: this._entity,
|
|
204
|
-
values: updateValues,
|
|
205
|
-
filter
|
|
206
|
-
});
|
|
207
|
-
return rowsAffected ? keyValues : undefined;
|
|
208
|
-
}
|
|
209
|
-
async _updateAll(values, options) {
|
|
210
|
-
return await update_command_1.UpdateCommand.execute({
|
|
211
|
-
...options,
|
|
212
|
-
entity: this._entity,
|
|
213
|
-
values
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
exports.Repository = Repository;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Type } from 'ts-gems';
|
|
2
|
-
export declare function mixinEntities<A, B, C, D, E, F>(derived: Type, classARef: Type<A>, classBRef: Type<B>, classCRef: Type<C>, classDRef: Type<D>, classERef: Type<E>, classFRef: Type<F>): Type<A & B & C & D & E & F>;
|
|
3
|
-
export declare function mixinEntities<A, B, C, D, E>(derived: Type, classARef: Type<A>, classBRef: Type<B>, classCRef: Type<C>, classDRef: Type<D>, classERef: Type<E>): Type<A & B & C & D & E>;
|
|
4
|
-
export declare function mixinEntities<A, B, C, D>(derived: Type, classARef: Type<A>, classBRef: Type<B>, classCRef: Type<C>, classDRef: Type<D>): Type<A & B & C & D>;
|
|
5
|
-
export declare function mixinEntities<A, B, C>(derived: Type, classARef: Type<A>, classBRef: Type<B>, classCRef: Type<C>): Type<A & B & C>;
|
|
6
|
-
export declare function mixinEntities<A, B>(derived: Type, classARef: Type<A>, classBRef: Type<B>): Type<A & B>;
|
|
7
|
-
export declare function mixinEntities<A, B>(derived: Type, classARef: Type<A>, classBRef: Type<B>): Type<A & B>;
|
|
8
|
-
export declare function pickEntityInto<T, K extends keyof T>(derived: Type, classRef: Type<T>, keys: readonly K[]): Type<Pick<T, typeof keys[number]>>;
|
|
9
|
-
export declare function omitEntityInto<T, K extends keyof T>(derived: Type, classRef: Type<T>, keys: readonly K[]): Type<Omit<T, typeof keys[number]>>;
|
|
10
|
-
export declare function UnionEntity<A, B>(classARef: Type<A>, classBRef: Type<B>): Type<A & B>;
|
|
11
|
-
export declare function PickEntity<T, K extends keyof T>(classRef: Type<T>, keys: readonly K[]): Type<Pick<T, typeof keys[number]>>;
|
|
12
|
-
export declare function OmitEntity<T, K extends keyof T>(classRef: Type<T>, keys: readonly K[]): Type<Omit<T, typeof keys[number]>>;
|