@spinajs/orm 2.0.180 → 2.0.182

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 (97) hide show
  1. package/lib/cjs/builders.d.ts +643 -643
  2. package/lib/cjs/builders.js +1602 -1602
  3. package/lib/cjs/builders.js.map +1 -1
  4. package/lib/cjs/converters.d.ts +34 -34
  5. package/lib/cjs/converters.js +104 -104
  6. package/lib/cjs/decorators.d.ts +152 -152
  7. package/lib/cjs/decorators.js +449 -449
  8. package/lib/cjs/dehydrators.d.ts +10 -10
  9. package/lib/cjs/dehydrators.js +47 -47
  10. package/lib/cjs/driver.d.ts +82 -82
  11. package/lib/cjs/driver.js +102 -102
  12. package/lib/cjs/driver.js.map +1 -1
  13. package/lib/cjs/enums.d.ts +116 -116
  14. package/lib/cjs/enums.js +126 -126
  15. package/lib/cjs/enums.js.map +1 -1
  16. package/lib/cjs/exceptions.d.ts +6 -6
  17. package/lib/cjs/exceptions.js +10 -10
  18. package/lib/cjs/hydrators.d.ts +19 -19
  19. package/lib/cjs/hydrators.js +132 -132
  20. package/lib/cjs/hydrators.js.map +1 -1
  21. package/lib/cjs/index.d.ts +17 -17
  22. package/lib/cjs/index.js +33 -33
  23. package/lib/cjs/interfaces.d.ts +921 -919
  24. package/lib/cjs/interfaces.d.ts.map +1 -1
  25. package/lib/cjs/interfaces.js +279 -279
  26. package/lib/cjs/interfaces.js.map +1 -1
  27. package/lib/cjs/middlewares.d.ts +62 -62
  28. package/lib/cjs/middlewares.js +258 -258
  29. package/lib/cjs/model.d.ts +288 -284
  30. package/lib/cjs/model.d.ts.map +1 -1
  31. package/lib/cjs/model.js +826 -810
  32. package/lib/cjs/model.js.map +1 -1
  33. package/lib/cjs/orm.d.ts +61 -61
  34. package/lib/cjs/orm.js +333 -333
  35. package/lib/cjs/orm.js.map +1 -1
  36. package/lib/cjs/relation-objects.d.ts +108 -108
  37. package/lib/cjs/relation-objects.js +221 -221
  38. package/lib/cjs/relations.d.ts +61 -61
  39. package/lib/cjs/relations.js +194 -194
  40. package/lib/cjs/relations.js.map +1 -1
  41. package/lib/cjs/statements.d.ts +143 -143
  42. package/lib/cjs/statements.js +309 -309
  43. package/lib/cjs/statements.js.map +1 -1
  44. package/lib/cjs/types.d.ts +32 -32
  45. package/lib/cjs/types.js +2 -2
  46. package/lib/cjs/wrappers.d.ts +5 -5
  47. package/lib/cjs/wrappers.js +12 -12
  48. package/lib/mjs/builders.d.ts +643 -643
  49. package/lib/mjs/builders.js +1594 -1594
  50. package/lib/mjs/builders.js.map +1 -1
  51. package/lib/mjs/converters.d.ts +34 -34
  52. package/lib/mjs/converters.js +96 -96
  53. package/lib/mjs/decorators.d.ts +152 -152
  54. package/lib/mjs/decorators.js +422 -422
  55. package/lib/mjs/dehydrators.d.ts +10 -10
  56. package/lib/mjs/dehydrators.js +41 -41
  57. package/lib/mjs/driver.d.ts +82 -82
  58. package/lib/mjs/driver.js +98 -98
  59. package/lib/mjs/driver.js.map +1 -1
  60. package/lib/mjs/enums.d.ts +116 -116
  61. package/lib/mjs/enums.js +123 -123
  62. package/lib/mjs/enums.js.map +1 -1
  63. package/lib/mjs/exceptions.d.ts +6 -6
  64. package/lib/mjs/exceptions.js +6 -6
  65. package/lib/mjs/hydrators.d.ts +19 -19
  66. package/lib/mjs/hydrators.js +128 -128
  67. package/lib/mjs/hydrators.js.map +1 -1
  68. package/lib/mjs/index.d.ts +17 -17
  69. package/lib/mjs/index.js +17 -17
  70. package/lib/mjs/interfaces.d.ts +921 -919
  71. package/lib/mjs/interfaces.d.ts.map +1 -1
  72. package/lib/mjs/interfaces.js +267 -267
  73. package/lib/mjs/interfaces.js.map +1 -1
  74. package/lib/mjs/middlewares.d.ts +62 -62
  75. package/lib/mjs/middlewares.js +249 -249
  76. package/lib/mjs/model.d.ts +288 -284
  77. package/lib/mjs/model.d.ts.map +1 -1
  78. package/lib/mjs/model.js +816 -800
  79. package/lib/mjs/model.js.map +1 -1
  80. package/lib/mjs/orm.d.ts +61 -61
  81. package/lib/mjs/orm.js +326 -326
  82. package/lib/mjs/orm.js.map +1 -1
  83. package/lib/mjs/relation-objects.d.ts +108 -108
  84. package/lib/mjs/relation-objects.js +211 -211
  85. package/lib/mjs/relations.d.ts +61 -61
  86. package/lib/mjs/relations.js +191 -191
  87. package/lib/mjs/relations.js.map +1 -1
  88. package/lib/mjs/statements.d.ts +143 -143
  89. package/lib/mjs/statements.js +301 -301
  90. package/lib/mjs/statements.js.map +1 -1
  91. package/lib/mjs/types.d.ts +32 -32
  92. package/lib/mjs/types.js +1 -1
  93. package/lib/mjs/wrappers.d.ts +5 -5
  94. package/lib/mjs/wrappers.js +9 -9
  95. package/lib/tsconfig.cjs.tsbuildinfo +1 -1
  96. package/lib/tsconfig.mjs.tsbuildinfo +1 -1
  97. package/package.json +5 -5
@@ -1,212 +1,212 @@
1
- /* eslint-disable prettier/prettier */
2
- import { InsertBehaviour } from './interfaces.js';
3
- import { DI, isConstructor } from '@spinajs/di';
4
- import { SelectQueryBuilder } from './builders.js';
5
- import { createQuery, extractModelDescriptor, ModelBase } from './model.js';
6
- import { Orm } from './orm.js';
7
- import _ from 'lodash';
8
- /**
9
- * Iterable list of populated relation entities
10
- *
11
- * It allows to add / remove objects to relation
12
- */
13
- export class Relation extends Array {
14
- constructor(owner, Model, Relation, objects) {
15
- super();
16
- this.owner = owner;
17
- this.Model = Model;
18
- this.Relation = Relation;
19
- this.Populated = false;
20
- if (objects) {
21
- this.push(...objects);
22
- }
23
- this.TargetModelDescriptor = extractModelDescriptor(Model);
24
- this.Orm = DI.get(Orm);
25
- if (this.TargetModelDescriptor) {
26
- this.Driver = this.Orm.Connections.get(this.TargetModelDescriptor.Connection);
27
- }
28
- this.IsModelAForwardRef = !isConstructor(this.Model);
29
- }
30
- /**
31
- * Delete all objects from relation
32
- */
33
- async clear() {
34
- await this.remove(this);
35
- }
36
- empty() {
37
- this.length = 0;
38
- }
39
- /**
40
- * Populates this relation ( loads all data related to owner of this relation)
41
- */
42
- async populate(callback) {
43
- const query = this.Relation.TargetModel.where(this.Relation.ForeignKey, this.owner.PrimaryKeyValue);
44
- if (callback) {
45
- callback.apply(query);
46
- }
47
- const result = await query;
48
- if (result) {
49
- this.length = 0;
50
- this.push(...result);
51
- }
52
- this.Populated = true;
53
- }
54
- }
55
- export class SingleRelation {
56
- constructor(_owner, model, Relation, object) {
57
- this._owner = _owner;
58
- this.model = model;
59
- this.Relation = Relation;
60
- this.Populated = false;
61
- this.TargetModelDescriptor = extractModelDescriptor(model);
62
- this.Orm = DI.get(Orm);
63
- this.Value = object;
64
- }
65
- async set(obj) {
66
- this.Value = obj;
67
- await this._owner.update();
68
- }
69
- attach(obj) {
70
- this.Value = obj;
71
- }
72
- detach() {
73
- this.Value = null;
74
- }
75
- async remove() {
76
- this.Value = null;
77
- await this.Value.destroy();
78
- await this._owner.update();
79
- }
80
- async populate(callback) {
81
- /**
82
- * Do little cheat - we construct query that loads initial model with given relation.
83
- * Then we only assign relation property.
84
- *
85
- * TODO: create only relation query without loading its owner.
86
- */
87
- const query = createQuery(this.Relation.TargetModel, (SelectQueryBuilder)).query;
88
- const desc = extractModelDescriptor(this.Relation.TargetModel);
89
- query.where({ [desc.PrimaryKey]: this._owner[this.Relation.ForeignKey] });
90
- if (callback) {
91
- callback.apply(query);
92
- }
93
- const result = await query.firstOrFail();
94
- if (result) {
95
- this.Value = result;
96
- }
97
- this.Populated = true;
98
- }
99
- }
100
- export class ManyToManyRelationList extends Relation {
101
- intersection(_obj, _callback) {
102
- throw new Error('Method not implemented.');
103
- }
104
- union(_obj, _mode) {
105
- throw new Error('Method not implemented.');
106
- }
107
- diff(_obj, _callback) {
108
- throw new Error('Method not implemented.');
109
- }
110
- set(_obj, _callback) {
111
- throw new Error('Method not implemented.');
112
- }
113
- async remove(obj) {
114
- const self = this;
115
- const data = (Array.isArray(obj) ? obj : [obj]).map((d) => d.PrimaryKeyValue);
116
- const jmodelDescriptor = extractModelDescriptor(this.Relation.JunctionModel);
117
- const query = this.Driver.del()
118
- .from(jmodelDescriptor.TableName)
119
- .where(function () {
120
- this.whereIn(self.Relation.JunctionModelTargetModelFKey_Name, data);
121
- this.andWhere(self.Relation.JunctionModelSourceModelFKey_Name, self.owner.PrimaryKeyValue);
122
- });
123
- if (this.Driver.Options.Database) {
124
- query.database(this.Driver.Options.Database);
125
- }
126
- await query;
127
- _.remove(this, (o) => data.indexOf(o.PrimaryKeyValue) !== -1);
128
- }
129
- async add(obj, mode) {
130
- const data = Array.isArray(obj) ? obj : [obj];
131
- const relEntities = data.map((d) => {
132
- const relEntity = new this.Relation.JunctionModel();
133
- relEntity[this.Relation.JunctionModelSourceModelFKey_Name] = this.owner.PrimaryKeyValue;
134
- relEntity[this.Relation.JunctionModelTargetModelFKey_Name] = d.PrimaryKeyValue;
135
- return relEntity;
136
- });
137
- for (const m of relEntities) {
138
- await m.insert(mode);
139
- }
140
- this.push(...data);
141
- }
142
- }
143
- export class OneToManyRelationList extends Relation {
144
- async deleteRelationData(data) {
145
- if (data.length === 0) {
146
- return;
147
- }
148
- const self = this;
149
- const query = this.Driver.del()
150
- .from(this.TargetModelDescriptor.TableName)
151
- .andWhere(function () {
152
- this.whereNotIn(self.Relation.PrimaryKey, data.filter((x) => x.PrimaryKeyValue).map((x) => x.PrimaryKeyValue));
153
- this.where(self.Relation.ForeignKey, self.owner.PrimaryKeyValue);
154
- });
155
- if (this.Driver.Options.Database) {
156
- query.database(this.Driver.Options.Database);
157
- }
158
- await query;
159
- this.empty();
160
- }
161
- async diff(dataset, callback) {
162
- // calculate difference between this data in relation and dataset ( objects from this relation)
163
- const result = callback ? _.differenceWith(dataset, [...this], callback) : _.differenceBy(dataset, [...this], this.TargetModelDescriptor.PrimaryKey);
164
- // calculate difference between dataset and data in this relation ( objects from dataset )
165
- const result2 = callback ? _.differenceWith([...this], dataset, callback) : _.differenceBy([...this], dataset, this.TargetModelDescriptor.PrimaryKey);
166
- // combine difference from two sets
167
- const finalDiff = [...result, ...result2];
168
- await this.deleteRelationData(finalDiff);
169
- await this.add(finalDiff, InsertBehaviour.InsertOrUpdate);
170
- }
171
- async set(obj) {
172
- await this.deleteRelationData(obj);
173
- await this.add(obj, InsertBehaviour.InsertOrUpdate);
174
- }
175
- async intersection(obj, callback) {
176
- const result = callback ? _.intersectionWith(obj, [...this], callback) : _.intersectionBy(obj, [...this], this.TargetModelDescriptor.PrimaryKey);
177
- await this.deleteRelationData(result);
178
- await this.add(result, InsertBehaviour.InsertOrUpdate);
179
- }
180
- async union(obj, mode) {
181
- await this.add(obj, mode ?? InsertBehaviour.InsertOrIgnore);
182
- }
183
- async remove(obj) {
184
- const data = (Array.isArray(obj) ? obj : [obj]).map((d) => d.PrimaryKeyValue);
185
- const query = this.Driver.del().whereIn(this.Relation.ForeignKey, data).setTable(this.TargetModelDescriptor.TableName);
186
- if (this.Driver.Options.Database) {
187
- query.database(this.Driver.Options.Database);
188
- }
189
- await query;
190
- _.remove(this, (o) => data.indexOf(o.PrimaryKeyValue) !== -1);
191
- }
192
- async add(obj, mode) {
193
- const data = Array.isArray(obj) ? obj : [obj];
194
- const tInsert = data.map((x) => {
195
- if (x instanceof ModelBase) {
196
- return x;
197
- }
198
- if (this.IsModelAForwardRef) {
199
- new (this.Model())(x);
200
- }
201
- return new this.Model(x);
202
- });
203
- data.forEach((d) => {
204
- d[this.Relation.ForeignKey] = this.owner.PrimaryKeyValue;
205
- });
206
- for (const m of tInsert) {
207
- await m.insertOrUpdate(mode);
208
- }
209
- this.push(...tInsert);
210
- }
211
- }
1
+ /* eslint-disable prettier/prettier */
2
+ import { InsertBehaviour } from './interfaces.js';
3
+ import { DI, isConstructor } from '@spinajs/di';
4
+ import { SelectQueryBuilder } from './builders.js';
5
+ import { createQuery, extractModelDescriptor, ModelBase } from './model.js';
6
+ import { Orm } from './orm.js';
7
+ import _ from 'lodash';
8
+ /**
9
+ * Iterable list of populated relation entities
10
+ *
11
+ * It allows to add / remove objects to relation
12
+ */
13
+ export class Relation extends Array {
14
+ constructor(owner, Model, Relation, objects) {
15
+ super();
16
+ this.owner = owner;
17
+ this.Model = Model;
18
+ this.Relation = Relation;
19
+ this.Populated = false;
20
+ if (objects) {
21
+ this.push(...objects);
22
+ }
23
+ this.TargetModelDescriptor = extractModelDescriptor(Model);
24
+ this.Orm = DI.get(Orm);
25
+ if (this.TargetModelDescriptor) {
26
+ this.Driver = this.Orm.Connections.get(this.TargetModelDescriptor.Connection);
27
+ }
28
+ this.IsModelAForwardRef = !isConstructor(this.Model);
29
+ }
30
+ /**
31
+ * Delete all objects from relation
32
+ */
33
+ async clear() {
34
+ await this.remove(this);
35
+ }
36
+ empty() {
37
+ this.length = 0;
38
+ }
39
+ /**
40
+ * Populates this relation ( loads all data related to owner of this relation)
41
+ */
42
+ async populate(callback) {
43
+ const query = this.Relation.TargetModel.where(this.Relation.ForeignKey, this.owner.PrimaryKeyValue);
44
+ if (callback) {
45
+ callback.apply(query);
46
+ }
47
+ const result = await query;
48
+ if (result) {
49
+ this.length = 0;
50
+ this.push(...result);
51
+ }
52
+ this.Populated = true;
53
+ }
54
+ }
55
+ export class SingleRelation {
56
+ constructor(_owner, model, Relation, object) {
57
+ this._owner = _owner;
58
+ this.model = model;
59
+ this.Relation = Relation;
60
+ this.Populated = false;
61
+ this.TargetModelDescriptor = extractModelDescriptor(model);
62
+ this.Orm = DI.get(Orm);
63
+ this.Value = object;
64
+ }
65
+ async set(obj) {
66
+ this.Value = obj;
67
+ await this._owner.update();
68
+ }
69
+ attach(obj) {
70
+ this.Value = obj;
71
+ }
72
+ detach() {
73
+ this.Value = null;
74
+ }
75
+ async remove() {
76
+ this.Value = null;
77
+ await this.Value.destroy();
78
+ await this._owner.update();
79
+ }
80
+ async populate(callback) {
81
+ /**
82
+ * Do little cheat - we construct query that loads initial model with given relation.
83
+ * Then we only assign relation property.
84
+ *
85
+ * TODO: create only relation query without loading its owner.
86
+ */
87
+ const query = createQuery(this.Relation.TargetModel, (SelectQueryBuilder)).query;
88
+ const desc = extractModelDescriptor(this.Relation.TargetModel);
89
+ query.where({ [desc.PrimaryKey]: this._owner[this.Relation.ForeignKey] });
90
+ if (callback) {
91
+ callback.apply(query);
92
+ }
93
+ const result = await query.firstOrFail();
94
+ if (result) {
95
+ this.Value = result;
96
+ }
97
+ this.Populated = true;
98
+ }
99
+ }
100
+ export class ManyToManyRelationList extends Relation {
101
+ intersection(_obj, _callback) {
102
+ throw new Error('Method not implemented.');
103
+ }
104
+ union(_obj, _mode) {
105
+ throw new Error('Method not implemented.');
106
+ }
107
+ diff(_obj, _callback) {
108
+ throw new Error('Method not implemented.');
109
+ }
110
+ set(_obj, _callback) {
111
+ throw new Error('Method not implemented.');
112
+ }
113
+ async remove(obj) {
114
+ const self = this;
115
+ const data = (Array.isArray(obj) ? obj : [obj]).map((d) => d.PrimaryKeyValue);
116
+ const jmodelDescriptor = extractModelDescriptor(this.Relation.JunctionModel);
117
+ const query = this.Driver.del()
118
+ .from(jmodelDescriptor.TableName)
119
+ .where(function () {
120
+ this.whereIn(self.Relation.JunctionModelTargetModelFKey_Name, data);
121
+ this.andWhere(self.Relation.JunctionModelSourceModelFKey_Name, self.owner.PrimaryKeyValue);
122
+ });
123
+ if (this.Driver.Options.Database) {
124
+ query.database(this.Driver.Options.Database);
125
+ }
126
+ await query;
127
+ _.remove(this, (o) => data.indexOf(o.PrimaryKeyValue) !== -1);
128
+ }
129
+ async add(obj, mode) {
130
+ const data = Array.isArray(obj) ? obj : [obj];
131
+ const relEntities = data.map((d) => {
132
+ const relEntity = new this.Relation.JunctionModel();
133
+ relEntity[this.Relation.JunctionModelSourceModelFKey_Name] = this.owner.PrimaryKeyValue;
134
+ relEntity[this.Relation.JunctionModelTargetModelFKey_Name] = d.PrimaryKeyValue;
135
+ return relEntity;
136
+ });
137
+ for (const m of relEntities) {
138
+ await m.insert(mode);
139
+ }
140
+ this.push(...data);
141
+ }
142
+ }
143
+ export class OneToManyRelationList extends Relation {
144
+ async deleteRelationData(data) {
145
+ if (data.length === 0) {
146
+ return;
147
+ }
148
+ const self = this;
149
+ const query = this.Driver.del()
150
+ .from(this.TargetModelDescriptor.TableName)
151
+ .andWhere(function () {
152
+ this.whereNotIn(self.Relation.PrimaryKey, data.filter((x) => x.PrimaryKeyValue).map((x) => x.PrimaryKeyValue));
153
+ this.where(self.Relation.ForeignKey, self.owner.PrimaryKeyValue);
154
+ });
155
+ if (this.Driver.Options.Database) {
156
+ query.database(this.Driver.Options.Database);
157
+ }
158
+ await query;
159
+ this.empty();
160
+ }
161
+ async diff(dataset, callback) {
162
+ // calculate difference between this data in relation and dataset ( objects from this relation)
163
+ const result = callback ? _.differenceWith(dataset, [...this], callback) : _.differenceBy(dataset, [...this], this.TargetModelDescriptor.PrimaryKey);
164
+ // calculate difference between dataset and data in this relation ( objects from dataset )
165
+ const result2 = callback ? _.differenceWith([...this], dataset, callback) : _.differenceBy([...this], dataset, this.TargetModelDescriptor.PrimaryKey);
166
+ // combine difference from two sets
167
+ const finalDiff = [...result, ...result2];
168
+ await this.deleteRelationData(finalDiff);
169
+ await this.add(finalDiff, InsertBehaviour.InsertOrUpdate);
170
+ }
171
+ async set(obj) {
172
+ await this.deleteRelationData(obj);
173
+ await this.add(obj, InsertBehaviour.InsertOrUpdate);
174
+ }
175
+ async intersection(obj, callback) {
176
+ const result = callback ? _.intersectionWith(obj, [...this], callback) : _.intersectionBy(obj, [...this], this.TargetModelDescriptor.PrimaryKey);
177
+ await this.deleteRelationData(result);
178
+ await this.add(result, InsertBehaviour.InsertOrUpdate);
179
+ }
180
+ async union(obj, mode) {
181
+ await this.add(obj, mode ?? InsertBehaviour.InsertOrIgnore);
182
+ }
183
+ async remove(obj) {
184
+ const data = (Array.isArray(obj) ? obj : [obj]).map((d) => d.PrimaryKeyValue);
185
+ const query = this.Driver.del().whereIn(this.Relation.ForeignKey, data).setTable(this.TargetModelDescriptor.TableName);
186
+ if (this.Driver.Options.Database) {
187
+ query.database(this.Driver.Options.Database);
188
+ }
189
+ await query;
190
+ _.remove(this, (o) => data.indexOf(o.PrimaryKeyValue) !== -1);
191
+ }
192
+ async add(obj, mode) {
193
+ const data = Array.isArray(obj) ? obj : [obj];
194
+ const tInsert = data.map((x) => {
195
+ if (x instanceof ModelBase) {
196
+ return x;
197
+ }
198
+ if (this.IsModelAForwardRef) {
199
+ new (this.Model())(x);
200
+ }
201
+ return new this.Model(x);
202
+ });
203
+ data.forEach((d) => {
204
+ d[this.Relation.ForeignKey] = this.owner.PrimaryKeyValue;
205
+ });
206
+ for (const m of tInsert) {
207
+ await m.insertOrUpdate(mode);
208
+ }
209
+ this.push(...tInsert);
210
+ }
211
+ }
212
212
  //# sourceMappingURL=relation-objects.js.map
@@ -1,62 +1,62 @@
1
- import { IRelationDescriptor, IModelDescriptor, ForwardRefFunction, ISelectQueryBuilder } from './interfaces.js';
2
- import { Constructor, Container } from '@spinajs/di';
3
- import { ModelBase } from './model.js';
4
- import { Orm } from './orm.js';
5
- import { OrmDriver } from './driver.js';
6
- export interface IOrmRelation {
7
- /**
8
- * Executes relation, should be called only once.
9
- *
10
- * @param callback - optional callback to perform actions on relations eg. populate more, filter relational data etc.
11
- */
12
- execute(callback?: (this: ISelectQueryBuilder, relation: OrmRelation) => void): void;
13
- /**
14
- * Execute actions on relation query, does not initialize relation. Use it only AFTER execute was called.
15
- *
16
- * @param callback - execute callback to perform actions on relations eg. populate more, filter relational data etc.
17
- */
18
- executeOnQuery(callback: (this: ISelectQueryBuilder, relation: OrmRelation) => void): void;
19
- /**
20
- * Relation name
21
- */
22
- Name: string;
23
- }
24
- export declare abstract class OrmRelation implements IOrmRelation {
25
- protected _container: Container;
26
- protected _query: ISelectQueryBuilder;
27
- protected _description: IRelationDescriptor;
28
- parentRelation?: OrmRelation;
29
- protected _targetModel: Constructor<ModelBase> | ForwardRefFunction;
30
- protected _targetModelDescriptor: IModelDescriptor;
31
- protected _relationQuery: ISelectQueryBuilder;
32
- protected _separator: string;
33
- protected _driver: OrmDriver;
34
- Name: string;
35
- get Alias(): string;
36
- constructor(_container: Container, _query: ISelectQueryBuilder, _description: IRelationDescriptor, parentRelation?: OrmRelation);
37
- abstract execute(callback?: (this: ISelectQueryBuilder, relation: OrmRelation) => void): void;
38
- executeOnQuery(callback: (this: ISelectQueryBuilder<any>, relation: OrmRelation) => void): void;
39
- }
40
- export declare class BelongsToRelation extends OrmRelation {
41
- constructor(_container: Container, _query: ISelectQueryBuilder<any>, _description: IRelationDescriptor, _parentRelation?: OrmRelation);
42
- execute(callback: (this: ISelectQueryBuilder, relation: OrmRelation) => void): void;
43
- }
44
- export declare class BelongsToRecursiveRelation extends OrmRelation {
45
- constructor(_container: Container, _query: ISelectQueryBuilder<any>, _description: IRelationDescriptor, _parentRelation?: OrmRelation);
46
- execute(callback: (this: ISelectQueryBuilder, relation: OrmRelation) => void): void;
47
- }
48
- export declare class OneToManyRelation extends OrmRelation {
49
- constructor(_container: Container, _query: ISelectQueryBuilder<any>, _description: IRelationDescriptor, _parentRelation?: OrmRelation);
50
- execute(callback?: (this: ISelectQueryBuilder<any>, relation: OrmRelation) => void): void;
51
- }
52
- export declare class ManyToManyRelation extends OrmRelation {
53
- protected _orm: Orm;
54
- protected _joinModel: Constructor<ModelBase>;
55
- protected _joinModelDescriptor: IModelDescriptor;
56
- protected _joinQuery: ISelectQueryBuilder;
57
- get TableJoinQuery(): ISelectQueryBuilder<unknown>;
58
- get RelationQuery(): ISelectQueryBuilder<unknown>;
59
- constructor(_container: Container, _orm: Orm, _query: ISelectQueryBuilder<any>, _description: IRelationDescriptor, _parentRelation?: OrmRelation);
60
- execute(callback?: (this: ISelectQueryBuilder<any>, relation: OrmRelation) => void): void;
61
- }
1
+ import { IRelationDescriptor, IModelDescriptor, ForwardRefFunction, ISelectQueryBuilder } from './interfaces.js';
2
+ import { Constructor, Container } from '@spinajs/di';
3
+ import { ModelBase } from './model.js';
4
+ import { Orm } from './orm.js';
5
+ import { OrmDriver } from './driver.js';
6
+ export interface IOrmRelation {
7
+ /**
8
+ * Executes relation, should be called only once.
9
+ *
10
+ * @param callback - optional callback to perform actions on relations eg. populate more, filter relational data etc.
11
+ */
12
+ execute(callback?: (this: ISelectQueryBuilder, relation: OrmRelation) => void): void;
13
+ /**
14
+ * Execute actions on relation query, does not initialize relation. Use it only AFTER execute was called.
15
+ *
16
+ * @param callback - execute callback to perform actions on relations eg. populate more, filter relational data etc.
17
+ */
18
+ executeOnQuery(callback: (this: ISelectQueryBuilder, relation: OrmRelation) => void): void;
19
+ /**
20
+ * Relation name
21
+ */
22
+ Name: string;
23
+ }
24
+ export declare abstract class OrmRelation implements IOrmRelation {
25
+ protected _container: Container;
26
+ protected _query: ISelectQueryBuilder;
27
+ protected _description: IRelationDescriptor;
28
+ parentRelation?: OrmRelation;
29
+ protected _targetModel: Constructor<ModelBase> | ForwardRefFunction;
30
+ protected _targetModelDescriptor: IModelDescriptor;
31
+ protected _relationQuery: ISelectQueryBuilder;
32
+ protected _separator: string;
33
+ protected _driver: OrmDriver;
34
+ Name: string;
35
+ get Alias(): string;
36
+ constructor(_container: Container, _query: ISelectQueryBuilder, _description: IRelationDescriptor, parentRelation?: OrmRelation);
37
+ abstract execute(callback?: (this: ISelectQueryBuilder, relation: OrmRelation) => void): void;
38
+ executeOnQuery(callback: (this: ISelectQueryBuilder<any>, relation: OrmRelation) => void): void;
39
+ }
40
+ export declare class BelongsToRelation extends OrmRelation {
41
+ constructor(_container: Container, _query: ISelectQueryBuilder<any>, _description: IRelationDescriptor, _parentRelation?: OrmRelation);
42
+ execute(callback: (this: ISelectQueryBuilder, relation: OrmRelation) => void): void;
43
+ }
44
+ export declare class BelongsToRecursiveRelation extends OrmRelation {
45
+ constructor(_container: Container, _query: ISelectQueryBuilder<any>, _description: IRelationDescriptor, _parentRelation?: OrmRelation);
46
+ execute(callback: (this: ISelectQueryBuilder, relation: OrmRelation) => void): void;
47
+ }
48
+ export declare class OneToManyRelation extends OrmRelation {
49
+ constructor(_container: Container, _query: ISelectQueryBuilder<any>, _description: IRelationDescriptor, _parentRelation?: OrmRelation);
50
+ execute(callback?: (this: ISelectQueryBuilder<any>, relation: OrmRelation) => void): void;
51
+ }
52
+ export declare class ManyToManyRelation extends OrmRelation {
53
+ protected _orm: Orm;
54
+ protected _joinModel: Constructor<ModelBase>;
55
+ protected _joinModelDescriptor: IModelDescriptor;
56
+ protected _joinQuery: ISelectQueryBuilder;
57
+ get TableJoinQuery(): ISelectQueryBuilder<unknown>;
58
+ get RelationQuery(): ISelectQueryBuilder<unknown>;
59
+ constructor(_container: Container, _orm: Orm, _query: ISelectQueryBuilder<any>, _description: IRelationDescriptor, _parentRelation?: OrmRelation);
60
+ execute(callback?: (this: ISelectQueryBuilder<any>, relation: OrmRelation) => void): void;
61
+ }
62
62
  //# sourceMappingURL=relations.d.ts.map