@sqb/connect 4.0.9 → 4.0.13

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.
Files changed (89) hide show
  1. package/dist/client/Adapter.d.ts +57 -0
  2. package/dist/client/Adapter.js +2 -0
  3. package/dist/client/Cursor.d.ts +116 -0
  4. package/dist/client/Cursor.js +250 -0
  5. package/dist/client/CursorStream.d.ts +29 -0
  6. package/dist/client/CursorStream.js +98 -0
  7. package/dist/client/FieldInfoMap.d.ts +10 -0
  8. package/dist/client/FieldInfoMap.js +33 -0
  9. package/dist/client/SqbClient.d.ts +70 -0
  10. package/dist/client/SqbClient.js +165 -0
  11. package/dist/client/SqbConnection.d.ts +74 -0
  12. package/dist/client/SqbConnection.js +272 -0
  13. package/dist/client/extensions.d.ts +4 -0
  14. package/dist/client/extensions.js +14 -0
  15. package/dist/client/helpers.d.ts +9 -0
  16. package/dist/client/helpers.js +133 -0
  17. package/dist/client/types.d.ts +189 -0
  18. package/dist/client/types.js +5 -0
  19. package/dist/index.d.ts +28 -0
  20. package/dist/index.js +37 -0
  21. package/dist/orm/base-entity.class.d.ts +16 -0
  22. package/dist/orm/base-entity.class.js +56 -0
  23. package/dist/orm/commands/command.helper.d.ts +14 -0
  24. package/dist/orm/commands/command.helper.js +140 -0
  25. package/dist/orm/commands/count.command.d.ts +11 -0
  26. package/dist/orm/commands/count.command.js +30 -0
  27. package/dist/orm/commands/create.command.d.ts +20 -0
  28. package/dist/orm/commands/create.command.js +83 -0
  29. package/dist/orm/commands/destroy.command.d.ts +11 -0
  30. package/dist/orm/commands/destroy.command.js +30 -0
  31. package/dist/orm/commands/find.command.d.ts +44 -0
  32. package/dist/orm/commands/find.command.js +308 -0
  33. package/dist/orm/commands/row-converter.d.ts +55 -0
  34. package/dist/orm/commands/row-converter.js +187 -0
  35. package/dist/orm/commands/update.command.d.ts +22 -0
  36. package/dist/orm/commands/update.command.js +82 -0
  37. package/dist/orm/decorators/column.decorator.d.ts +4 -0
  38. package/dist/orm/decorators/column.decorator.js +14 -0
  39. package/dist/orm/decorators/embedded.decorator.d.ts +2 -0
  40. package/dist/orm/decorators/embedded.decorator.js +17 -0
  41. package/dist/orm/decorators/entity.decorator.d.ts +6 -0
  42. package/dist/orm/decorators/entity.decorator.js +23 -0
  43. package/dist/orm/decorators/events.decorator.d.ts +6 -0
  44. package/dist/orm/decorators/events.decorator.js +76 -0
  45. package/dist/orm/decorators/foreignkey.decorator.d.ts +2 -0
  46. package/dist/orm/decorators/foreignkey.decorator.js +13 -0
  47. package/dist/orm/decorators/index.decorator.d.ts +3 -0
  48. package/dist/orm/decorators/index.decorator.js +22 -0
  49. package/dist/orm/decorators/link.decorator.d.ts +23 -0
  50. package/dist/orm/decorators/link.decorator.js +88 -0
  51. package/dist/orm/decorators/primarykey.decorator.d.ts +3 -0
  52. package/dist/orm/decorators/primarykey.decorator.js +23 -0
  53. package/dist/orm/decorators/transform.decorator.d.ts +3 -0
  54. package/dist/orm/decorators/transform.decorator.js +24 -0
  55. package/dist/orm/model/abstract-entityelement.d.ts +8 -0
  56. package/dist/orm/model/abstract-entityelement.js +10 -0
  57. package/dist/orm/model/association-node.d.ts +9 -0
  58. package/dist/orm/model/association-node.js +25 -0
  59. package/dist/orm/model/association.d.ts +28 -0
  60. package/dist/orm/model/association.js +129 -0
  61. package/dist/orm/model/entity-association-element.d.ts +9 -0
  62. package/dist/orm/model/entity-association-element.js +13 -0
  63. package/dist/orm/model/entity-column-element.d.ts +68 -0
  64. package/dist/orm/model/entity-column-element.js +27 -0
  65. package/dist/orm/model/entity-model.d.ts +59 -0
  66. package/dist/orm/model/entity-model.js +295 -0
  67. package/dist/orm/model/entity-object-element.d.ts +12 -0
  68. package/dist/orm/model/entity-object-element.js +24 -0
  69. package/dist/orm/model/index-meta.d.ts +9 -0
  70. package/dist/orm/model/index-meta.js +16 -0
  71. package/dist/orm/model/link-chain.d.ts +15 -0
  72. package/dist/orm/model/link-chain.js +50 -0
  73. package/dist/orm/orm.const.d.ts +2 -0
  74. package/dist/orm/orm.const.js +5 -0
  75. package/dist/orm/orm.type.d.ts +112 -0
  76. package/dist/orm/orm.type.js +2 -0
  77. package/dist/orm/repository.class.d.ts +125 -0
  78. package/dist/orm/repository.class.js +217 -0
  79. package/dist/orm/util/entity-mapping.d.ts +12 -0
  80. package/dist/orm/util/entity-mapping.js +154 -0
  81. package/dist/orm/util/extract-keyvalues.d.ts +2 -0
  82. package/dist/orm/util/extract-keyvalues.js +60 -0
  83. package/dist/orm/util/orm.helper.d.ts +14 -0
  84. package/dist/orm/util/orm.helper.js +39 -0
  85. package/dist/orm/util/serialize-element.d.ts +2 -0
  86. package/dist/orm/util/serialize-element.js +43 -0
  87. package/dist/types.d.ts +2 -0
  88. package/dist/types.js +2 -0
  89. package/package.json +3 -3
@@ -0,0 +1,15 @@
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
+ }
@@ -0,0 +1,50 @@
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;
@@ -0,0 +1,2 @@
1
+ export declare const ENTITY_DEFINITION_KEY: unique symbol;
2
+ export declare const REPOSITORY_KEY: unique symbol;
@@ -0,0 +1,5 @@
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');
@@ -0,0 +1,112 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,125 @@
1
+ import { DeepPartial, Type } from 'ts-gems';
2
+ import { SqbClient } from '../client/SqbClient';
3
+ import { SqbConnection } from '../client/SqbConnection';
4
+ import { EntityModel } from './model/entity-model';
5
+ import { QueryRequest, TransactionFunction } from '../client/types';
6
+ import { InstanceValues } from '../types';
7
+ import { FieldInfoMap } from '../client/FieldInfoMap';
8
+ export declare namespace Repository {
9
+ type TransformRowFunction = (fields: FieldInfoMap, row: object, obj: object) => void;
10
+ interface CommandOptions {
11
+ connection?: SqbConnection;
12
+ }
13
+ interface CreateOptions extends CommandOptions {
14
+ elements?: string[];
15
+ include?: string[];
16
+ exclude?: string[];
17
+ }
18
+ interface CountOptions extends CommandOptions {
19
+ filter?: any;
20
+ params?: any;
21
+ }
22
+ interface ExistsOptions extends CommandOptions {
23
+ filter?: any;
24
+ params?: any;
25
+ }
26
+ interface DestroyOptions extends CommandOptions {
27
+ filter?: any;
28
+ params?: any;
29
+ }
30
+ interface FindOneOptions extends CommandOptions {
31
+ elements?: string[];
32
+ include?: string[];
33
+ exclude?: string[];
34
+ filter?: any;
35
+ params?: any;
36
+ sort?: string[];
37
+ offset?: number;
38
+ distinct?: boolean;
39
+ onTransformRow?: TransformRowFunction;
40
+ }
41
+ interface FindAllOptions extends FindOneOptions {
42
+ limit?: number;
43
+ maxEagerFetch?: number;
44
+ maxSubQueries?: number;
45
+ }
46
+ interface GetOptions extends CommandOptions {
47
+ elements?: string[];
48
+ include?: string[];
49
+ exclude?: string[];
50
+ filter?: any;
51
+ params?: any;
52
+ }
53
+ interface UpdateOptions extends CommandOptions {
54
+ elements?: string[];
55
+ include?: string[];
56
+ exclude?: string[];
57
+ filter?: any;
58
+ params?: any;
59
+ }
60
+ interface UpdateAllOptions extends CommandOptions {
61
+ filter?: any;
62
+ params?: any;
63
+ }
64
+ }
65
+ interface RepositoryEvents {
66
+ execute: (request: QueryRequest) => void;
67
+ error: (error: Error) => void;
68
+ acquire: (connection: SqbConnection) => Promise<void>;
69
+ }
70
+ declare const Repository_base: Type<import("strict-typed-events").TypedEventEmitter<any, RepositoryEvents, RepositoryEvents>>;
71
+ export declare class Repository<T> extends Repository_base {
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 {};
@@ -0,0 +1,217 @@
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 (0, strict_typed_events_1.TypedEventEmitterClass)(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.emitAsyncSerial('acquire', 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;
@@ -0,0 +1,12 @@
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]>>;