@iamkirbki/database-handler-core 4.4.6 → 4.4.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/dist/abstract/Controller.d.ts +2 -2
- package/dist/abstract/Controller.d.ts.map +1 -1
- package/dist/abstract/Controller.js +1 -1
- package/dist/abstract/Model.d.ts +10 -9
- package/dist/abstract/Model.d.ts.map +1 -1
- package/dist/abstract/Model.js +92 -70
- package/dist/abstract/SchemaTableBuilder.d.ts +1 -1
- package/dist/abstract/SchemaTableBuilder.d.ts.map +1 -1
- package/dist/abstract/SchemaTableBuilder.js +8 -8
- package/dist/abstract/model/ModelRelation.d.ts +5 -4
- package/dist/abstract/model/ModelRelation.d.ts.map +1 -1
- package/dist/abstract/model/ModelRelation.js +35 -27
- package/dist/base/Query.d.ts +4 -8
- package/dist/base/Query.d.ts.map +1 -1
- package/dist/base/Query.js +91 -73
- package/dist/base/Record.d.ts +5 -4
- package/dist/base/Record.d.ts.map +1 -1
- package/dist/base/Record.js +44 -23
- package/dist/base/Table.d.ts +17 -14
- package/dist/base/Table.d.ts.map +1 -1
- package/dist/base/Table.js +123 -89
- package/dist/factories/ModelFactory.d.ts +7 -0
- package/dist/factories/ModelFactory.d.ts.map +1 -0
- package/dist/factories/ModelFactory.js +6 -0
- package/dist/factories/QueryFactory.d.ts +7 -0
- package/dist/factories/QueryFactory.d.ts.map +1 -0
- package/dist/factories/QueryFactory.js +6 -0
- package/dist/factories/RecordFactory.d.ts +8 -0
- package/dist/factories/RecordFactory.d.ts.map +1 -0
- package/dist/factories/RecordFactory.js +6 -0
- package/dist/factories/TableFactory.d.ts +7 -0
- package/dist/factories/TableFactory.d.ts.map +1 -0
- package/dist/factories/TableFactory.js +6 -0
- package/dist/helpers/Errors/AdapterErrors/AdapterNotFoundError.d.ts +2 -1
- package/dist/helpers/Errors/AdapterErrors/AdapterNotFoundError.d.ts.map +1 -1
- package/dist/helpers/Errors/AdapterErrors/AdapterNotFoundError.js +3 -3
- package/dist/helpers/Errors/AdapterErrors/ConnectionFailedError.d.ts +2 -1
- package/dist/helpers/Errors/AdapterErrors/ConnectionFailedError.d.ts.map +1 -1
- package/dist/helpers/Errors/AdapterErrors/ConnectionFailedError.js +3 -3
- package/dist/helpers/Errors/AdapterErrors/NoDefaultAdapterError.d.ts +2 -1
- package/dist/helpers/Errors/AdapterErrors/NoDefaultAdapterError.d.ts.map +1 -1
- package/dist/helpers/Errors/AdapterErrors/NoDefaultAdapterError.js +3 -3
- package/dist/helpers/Errors/DatabaseHandlerError.d.ts +9 -0
- package/dist/helpers/Errors/DatabaseHandlerError.d.ts.map +1 -0
- package/dist/helpers/Errors/DatabaseHandlerError.js +10 -0
- package/dist/helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.d.ts +2 -1
- package/dist/helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.d.ts.map +1 -1
- package/dist/helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.js +5 -3
- package/dist/helpers/Errors/ExpressionErrors/UnknownExpressionTypeError.d.ts +2 -1
- package/dist/helpers/Errors/ExpressionErrors/UnknownExpressionTypeError.d.ts.map +1 -1
- package/dist/helpers/Errors/ExpressionErrors/UnknownExpressionTypeError.js +5 -3
- package/dist/helpers/Errors/ExpressionErrors/UnsupportedQueryPhaseError.d.ts +2 -1
- package/dist/helpers/Errors/ExpressionErrors/UnsupportedQueryPhaseError.d.ts.map +1 -1
- package/dist/helpers/Errors/ExpressionErrors/UnsupportedQueryPhaseError.js +3 -3
- package/dist/helpers/Errors/ModelErrors/InvalidOperationError.d.ts +5 -0
- package/dist/helpers/Errors/ModelErrors/InvalidOperationError.d.ts.map +1 -0
- package/dist/helpers/Errors/ModelErrors/InvalidOperationError.js +6 -0
- package/dist/helpers/Errors/ModelErrors/RecordNotFoundError.d.ts +6 -0
- package/dist/helpers/Errors/ModelErrors/RecordNotFoundError.d.ts.map +1 -0
- package/dist/helpers/Errors/ModelErrors/RecordNotFoundError.js +6 -0
- package/dist/helpers/Errors/ModelErrors/RelationError.d.ts +5 -0
- package/dist/helpers/Errors/ModelErrors/RelationError.d.ts.map +1 -0
- package/dist/helpers/Errors/ModelErrors/RelationError.js +6 -0
- package/dist/helpers/Errors/QueryErrors/InvalidWhereConditionError.d.ts +5 -0
- package/dist/helpers/Errors/QueryErrors/InvalidWhereConditionError.d.ts.map +1 -0
- package/dist/helpers/Errors/QueryErrors/InvalidWhereConditionError.js +6 -0
- package/dist/helpers/Errors/QueryErrors/QueryExecutionError.d.ts +5 -0
- package/dist/helpers/Errors/QueryErrors/QueryExecutionError.d.ts.map +1 -0
- package/dist/helpers/Errors/QueryErrors/QueryExecutionError.js +6 -0
- package/dist/helpers/Errors/QueryErrors/UnexpectedEmptyQueryError.d.ts +2 -1
- package/dist/helpers/Errors/QueryErrors/UnexpectedEmptyQueryError.d.ts.map +1 -1
- package/dist/helpers/Errors/QueryErrors/UnexpectedEmptyQueryError.js +3 -3
- package/dist/helpers/Errors/TableErrors/UnknownTableError.d.ts +3 -2
- package/dist/helpers/Errors/TableErrors/UnknownTableError.d.ts.map +1 -1
- package/dist/helpers/Errors/TableErrors/UnknownTableError.js +4 -4
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.d.ts +2 -2
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.js +1 -1
- package/dist/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.d.ts +3 -4
- package/dist/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.js +46 -44
- package/dist/helpers/QueryBuilders/ExpressionBuilders/SpatialDistanceExpression.d.ts +3 -4
- package/dist/helpers/QueryBuilders/ExpressionBuilders/SpatialDistanceExpression.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/ExpressionBuilders/SpatialDistanceExpression.js +34 -32
- package/dist/helpers/QueryBuilders/ExpressionBuilders/TextRelevanceExpression.d.ts +3 -4
- package/dist/helpers/QueryBuilders/ExpressionBuilders/TextRelevanceExpression.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/ExpressionBuilders/TextRelevanceExpression.js +9 -20
- package/dist/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.d.ts +4 -4
- package/dist/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.js +14 -17
- package/dist/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.d.ts +3 -3
- package/dist/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.js +2 -2
- package/dist/helpers/QueryBuilders/QueryDecorators/JoinDecorator.d.ts +4 -4
- package/dist/helpers/QueryBuilders/QueryDecorators/JoinDecorator.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/QueryDecorators/JoinDecorator.js +17 -14
- package/dist/helpers/QueryBuilders/QueryDecorators/LimitDecorator.d.ts +3 -3
- package/dist/helpers/QueryBuilders/QueryDecorators/LimitDecorator.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/QueryDecorators/LimitDecorator.js +2 -2
- package/dist/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.d.ts +3 -3
- package/dist/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.js +2 -2
- package/dist/helpers/QueryBuilders/QueryDecorators/QueryDecorator.d.ts +2 -2
- package/dist/helpers/QueryBuilders/QueryDecorators/QueryDecorator.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/QueryDecorators/QueryDecorator.js +1 -1
- package/dist/helpers/QueryBuilders/QueryDecorators/WhereDecorator.d.ts +5 -5
- package/dist/helpers/QueryBuilders/QueryDecorators/WhereDecorator.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/QueryDecorators/WhereDecorator.js +3 -4
- package/dist/helpers/QueryBuilders/QueryExpressionBuilder.d.ts +1 -3
- package/dist/helpers/QueryBuilders/QueryExpressionBuilder.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/QueryExpressionBuilder.js +4 -22
- package/dist/helpers/QueryBuilders/QueryStatementBuilder.d.ts +3 -4
- package/dist/helpers/QueryBuilders/QueryStatementBuilder.d.ts.map +1 -1
- package/dist/helpers/QueryBuilders/QueryStatementBuilder.js +59 -45
- package/dist/helpers/QueryBuilders/{SqlRenderer.d.ts → SqlGenerator.d.ts} +3 -3
- package/dist/helpers/QueryBuilders/SqlGenerator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/{SqlRenderer.js → SqlGenerator.js} +30 -19
- package/dist/helpers/QueryBuilders/{oldQueryStatementBuilder.d.ts → depricatedQueryStatementBuilder.d.ts} +19 -46
- package/dist/helpers/QueryBuilders/depricatedQueryStatementBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/{oldQueryStatementBuilder.js → depricatedQueryStatementBuilder.js} +31 -67
- package/dist/index.d.ts +13 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -7
- package/dist/interfaces/IController.d.ts +1 -1
- package/dist/interfaces/IController.d.ts.map +1 -1
- package/dist/interfaces/IDatabaseAdapter.d.ts +2 -2
- package/dist/interfaces/IDatabaseAdapter.d.ts.map +1 -1
- package/dist/interfaces/IExpressionBuilder.d.ts +1 -2
- package/dist/interfaces/IExpressionBuilder.d.ts.map +1 -1
- package/dist/interfaces/IFactory.d.ts +4 -0
- package/dist/interfaces/IFactory.d.ts.map +1 -0
- package/dist/interfaces/IFactory.js +1 -0
- package/dist/interfaces/IMigration.d.ts +4 -4
- package/dist/interfaces/IMigration.d.ts.map +1 -1
- package/dist/interfaces/IQueryBuilder.d.ts +1 -1
- package/dist/interfaces/IQueryBuilder.d.ts.map +1 -1
- package/dist/interfaces/ISchemaBuilder.d.ts +2 -2
- package/dist/interfaces/ISchemaBuilder.d.ts.map +1 -1
- package/dist/interfaces/IStatementAdapter.d.ts +1 -1
- package/dist/interfaces/IStatementAdapter.d.ts.map +1 -1
- package/dist/runtime/Container.d.ts +2 -3
- package/dist/runtime/Container.d.ts.map +1 -1
- package/dist/runtime/Container.js +3 -4
- package/dist/runtime/QueryCache.d.ts +1 -1
- package/dist/runtime/QueryCache.d.ts.map +1 -1
- package/dist/runtime/QueryCache.js +1 -1
- package/dist/runtime/Repository.d.ts +23 -12
- package/dist/runtime/Repository.d.ts.map +1 -1
- package/dist/runtime/Repository.js +324 -65
- package/dist/types/expressions.d.ts +12 -47
- package/dist/types/expressions.d.ts.map +1 -1
- package/dist/types/expressions.js +1 -6
- package/dist/types/factories.d.ts +5 -3
- package/dist/types/factories.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/model.d.ts +5 -23
- package/dist/types/model.d.ts.map +1 -1
- package/dist/types/query.d.ts +5 -4
- package/dist/types/query.d.ts.map +1 -1
- package/dist/types/record.d.ts +11 -0
- package/dist/types/record.d.ts.map +1 -0
- package/dist/types/record.js +1 -0
- package/dist/types/repository.d.ts +8 -0
- package/dist/types/repository.d.ts.map +1 -0
- package/dist/types/repository.js +1 -0
- package/dist/types/table.d.ts +9 -1
- package/dist/types/table.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/helpers/QueryBuilders/SqlRenderer.d.ts.map +0 -1
- package/dist/helpers/QueryBuilders/oldQueryStatementBuilder.d.ts.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Model from './Model.js';
|
|
1
|
+
import { Model } from './Model.js';
|
|
2
2
|
import { columnType } from '../types/index.js';
|
|
3
|
-
export
|
|
3
|
+
export declare abstract class Controller<Type extends columnType> {
|
|
4
4
|
abstract index(): Promise<Model<Type>[]>;
|
|
5
5
|
abstract show(value: string | number): Promise<Model<Type>>;
|
|
6
6
|
abstract edit(value: string | number): Promise<Model<Type>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Controller.d.ts","sourceRoot":"","sources":["../../src/abstract/Controller.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"Controller.d.ts","sourceRoot":"","sources":["../../src/abstract/Controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,8BAAsB,UAAU,CAAC,IAAI,SAAS,UAAU;IACtD,QAAQ,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;IACxC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3D,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3D,QAAQ,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,SAAS,EAAE,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3E,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjD,QAAQ,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;WAElC,KAAK,CAAC,UAAU,SAAS,UAAU,EACrD,IAAI,EAAE,UAAU,UAAU,CAAC,UAAU,CAAC,GACrC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;WAKX,IAAI,CAAC,UAAU,SAAS,UAAU,EACpD,IAAI,EAAE,UAAU,UAAU,CAAC,UAAU,CAAC,EACtC,KAAK,EAAE,MAAM,GAAG,MAAM,GACrB,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;WAKT,IAAI,CAAC,UAAU,SAAS,UAAU,EACpD,IAAI,EAAE,UAAU,UAAU,CAAC,UAAU,CAAC,EACtC,KAAK,EAAE,MAAM,GAAG,MAAM,GACrB,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;WAKT,MAAM,CAAC,UAAU,SAAS,UAAU,EACtD,IAAI,EAAE,UAAU,UAAU,CAAC,UAAU,CAAC,EACtC,EAAE,EAAE,MAAM,GAAG,MAAM,EACnB,SAAS,EAAE,UAAU,GACpB,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;WAKT,MAAM,CAAC,UAAU,SAAS,UAAU,EACtD,IAAI,EAAE,UAAU,UAAU,CAAC,UAAU,CAAC,EACtC,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;WAKT,MAAM,CAAC,UAAU,SAAS,UAAU,EACtD,IAAI,EAAE,UAAU,UAAU,CAAC,UAAU,CAAC,EACtC,EAAE,EAAE,MAAM,GAAG,MAAM,GAClB,OAAO,CAAC,OAAO,CAAC;CAIpB"}
|
package/dist/abstract/Model.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import Repository from '../runtime/Repository.js';
|
|
2
|
-
import ModelRelations from '../abstract/model/ModelRelation.js';
|
|
3
|
-
import { columnType,
|
|
1
|
+
import { Repository } from '../runtime/Repository.js';
|
|
2
|
+
import { ModelRelations } from '../abstract/model/ModelRelation.js';
|
|
3
|
+
import { columnType, QueryValues, ModelConfig, SpatialPoint, SpatialPointColumns, NestedJsonAggregateDefinition, QueryLayers, QueryWhereCondition } from '../types/index.js';
|
|
4
4
|
/** Abstract Model class for ORM-style database interactions */
|
|
5
|
-
export
|
|
5
|
+
export declare abstract class Model<ModelType extends columnType> extends ModelRelations<ModelType> {
|
|
6
6
|
private _repository?;
|
|
7
7
|
protected get repository(): Repository<ModelType, Model<ModelType>>;
|
|
8
8
|
protected get self(): Model<ModelType>;
|
|
@@ -23,10 +23,9 @@ export default abstract class Model<ModelType extends columnType> extends ModelR
|
|
|
23
23
|
static orderBy<ParamterModelType extends Model<columnType>>(this: new () => ParamterModelType, column: string, direction?: 'ASC' | 'DESC'): ParamterModelType;
|
|
24
24
|
orderBy(column: string, direction?: 'ASC' | 'DESC'): this;
|
|
25
25
|
static where<ParamterModelType extends Model<columnType>>(this: new () => ParamterModelType, conditions: QueryWhereCondition): ParamterModelType;
|
|
26
|
-
private normalizeConditions;
|
|
27
26
|
where(conditions: QueryWhereCondition): this;
|
|
28
|
-
static whereId<ParamterModelType extends Model<columnType>>(this: new () => ParamterModelType, id: QueryValues):
|
|
29
|
-
whereId(id: QueryValues):
|
|
27
|
+
static whereId<ParamterModelType extends Model<columnType>>(this: new () => ParamterModelType, id: QueryValues): ParamterModelType;
|
|
28
|
+
whereId(id: QueryValues): this;
|
|
30
29
|
static find<ParamterModelType extends Model<columnType>>(this: new () => ParamterModelType, primaryKeyValue: QueryValues): ParamterModelType;
|
|
31
30
|
find(primaryKeyValue: QueryValues): this;
|
|
32
31
|
static findOrFail<ParamterModelType extends Model<columnType>>(this: new () => ParamterModelType, primaryKeyValue: QueryValues): Promise<ParamterModelType>;
|
|
@@ -39,14 +38,16 @@ export default abstract class Model<ModelType extends columnType> extends ModelR
|
|
|
39
38
|
static set<ParamterModelType extends Model<columnType>>(this: new () => ParamterModelType, attributes: Partial<columnType>): ParamterModelType;
|
|
40
39
|
set(attributes: Partial<ModelType>): this;
|
|
41
40
|
save(): Promise<this>;
|
|
42
|
-
update(attributes
|
|
41
|
+
update(attributes?: Partial<ModelType>): Promise<this>;
|
|
43
42
|
near(params: {
|
|
44
43
|
referencePoint: SpatialPoint;
|
|
45
44
|
targetColumns: SpatialPointColumns;
|
|
46
|
-
maxDistance
|
|
45
|
+
maxDistance?: number;
|
|
46
|
+
minDistance?: number;
|
|
47
47
|
unit: 'km' | 'miles';
|
|
48
48
|
orderByDistance: 'ASC' | 'DESC';
|
|
49
49
|
alias?: string;
|
|
50
|
+
valueClauseKeywords: Record<'lon' | 'lat', string>;
|
|
50
51
|
}): this;
|
|
51
52
|
isTextRelevant(params: {
|
|
52
53
|
targetColumns: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../../src/abstract/Model.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../../src/abstract/Model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAGvE,OAAO,EACL,UAAU,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,mBAAmB,EAInB,6BAA6B,EAC7B,WAAW,EACX,mBAAmB,EAEpB,MAAM,sBAAsB,CAAC;AAE9B,+DAA+D;AAC/D,8BAAsB,KAAK,CACzB,SAAS,SAAS,UAAU,CAC5B,SAAQ,cAAc,CAAC,SAAS,CAAC;IACjC,OAAO,CAAC,WAAW,CAAC,CAA0C;IAE9D,SAAS,KAAK,UAAU,IAAI,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAUlE;IAED,SAAS,KAAK,IAAI,IAAI,KAAK,CAAC,SAAS,CAAC,CAErC;IAED,SAAS,CAAC,aAAa,EAAE,WAAW,CASlC;IAEF,IAAW,aAAa,IAAI,WAAW,CAEtC;IAED,SAAS,CAAC,kBAAkB,EAAE,OAAO,CAAC,SAAS,CAAC,CAAM;IACtD,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,SAAS,CAAC,CAAM;IAC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
-
import ModelRelations from '../abstract/model/ModelRelation.js';
|
|
3
|
-
import {
|
|
1
|
+
import { Repository } from '../runtime/Repository.js';
|
|
2
|
+
import { ModelRelations } from '../abstract/model/ModelRelation.js';
|
|
3
|
+
import { RecordNotFoundError } from '../helpers/Errors/ModelErrors/RecordNotFoundError.js';
|
|
4
|
+
import { InvalidOperationError } from '../helpers/Errors/ModelErrors/InvalidOperationError.js';
|
|
4
5
|
/** Abstract Model class for ORM-style database interactions */
|
|
5
|
-
export
|
|
6
|
+
export class Model extends ModelRelations {
|
|
6
7
|
constructor() {
|
|
7
8
|
super(...arguments);
|
|
8
9
|
this.configuration = {
|
|
@@ -24,7 +25,7 @@ export default class Model extends ModelRelations {
|
|
|
24
25
|
from: this.Configuration.table,
|
|
25
26
|
},
|
|
26
27
|
pretty: {},
|
|
27
|
-
final: {}
|
|
28
|
+
final: {},
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
31
|
get repository() {
|
|
@@ -66,7 +67,7 @@ export default class Model extends ModelRelations {
|
|
|
66
67
|
offset(value) {
|
|
67
68
|
var _a;
|
|
68
69
|
if (!((_a = this.queryLayers.final) === null || _a === void 0 ? void 0 : _a.limit)) {
|
|
69
|
-
throw new
|
|
70
|
+
throw new InvalidOperationError('Offset cannot be set without a limit.');
|
|
70
71
|
}
|
|
71
72
|
this.queryLayers.final.offset = value;
|
|
72
73
|
return this;
|
|
@@ -87,24 +88,19 @@ export default class Model extends ModelRelations {
|
|
|
87
88
|
const instance = new this();
|
|
88
89
|
return instance.where(conditions);
|
|
89
90
|
}
|
|
90
|
-
normalizeConditions(conditions) {
|
|
91
|
-
if (Array.isArray(conditions)) {
|
|
92
|
-
return conditions;
|
|
93
|
-
}
|
|
94
|
-
return Object.entries(conditions).map(([column, value]) => ({
|
|
95
|
-
column,
|
|
96
|
-
operator: '=',
|
|
97
|
-
value,
|
|
98
|
-
}));
|
|
99
|
-
}
|
|
100
91
|
where(conditions) {
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
92
|
+
const normalizedConditions = Array.isArray(conditions)
|
|
93
|
+
? conditions
|
|
94
|
+
: Object.entries(conditions).map(([key, value]) => ({
|
|
95
|
+
column: key,
|
|
96
|
+
operator: '=',
|
|
97
|
+
value,
|
|
98
|
+
}));
|
|
99
|
+
if (this.queryLayers.base.where) {
|
|
100
|
+
this.queryLayers.base.where.push(...normalizedConditions);
|
|
104
101
|
}
|
|
105
102
|
else {
|
|
106
|
-
|
|
107
|
-
this.queryLayers.base.where = [...existing, ...normalized];
|
|
103
|
+
this.queryLayers.base.where = normalizedConditions;
|
|
108
104
|
}
|
|
109
105
|
return this;
|
|
110
106
|
}
|
|
@@ -112,9 +108,14 @@ export default class Model extends ModelRelations {
|
|
|
112
108
|
const instance = new this();
|
|
113
109
|
return instance.whereId(id);
|
|
114
110
|
}
|
|
115
|
-
|
|
116
|
-
this.queryLayers.base.where = [
|
|
117
|
-
|
|
111
|
+
whereId(id) {
|
|
112
|
+
this.queryLayers.base.where = [
|
|
113
|
+
{
|
|
114
|
+
column: this.primaryKeyColumn,
|
|
115
|
+
operator: '=',
|
|
116
|
+
value: id,
|
|
117
|
+
},
|
|
118
|
+
];
|
|
118
119
|
return this;
|
|
119
120
|
}
|
|
120
121
|
static find(primaryKeyValue) {
|
|
@@ -122,23 +123,29 @@ export default class Model extends ModelRelations {
|
|
|
122
123
|
return instance.find(primaryKeyValue);
|
|
123
124
|
}
|
|
124
125
|
find(primaryKeyValue) {
|
|
125
|
-
this.queryLayers.base.where = [
|
|
126
|
+
this.queryLayers.base.where = [
|
|
127
|
+
{
|
|
128
|
+
column: this.primaryKeyColumn,
|
|
129
|
+
operator: '=',
|
|
130
|
+
value: primaryKeyValue,
|
|
131
|
+
},
|
|
132
|
+
];
|
|
126
133
|
return this;
|
|
127
134
|
}
|
|
128
135
|
static async findOrFail(primaryKeyValue) {
|
|
129
136
|
const instance = new this();
|
|
130
|
-
return
|
|
137
|
+
return await instance.findOrFail(primaryKeyValue);
|
|
131
138
|
}
|
|
132
139
|
async findOrFail(primaryKeyValue) {
|
|
133
140
|
var _a;
|
|
134
141
|
if (primaryKeyValue) {
|
|
135
|
-
this.
|
|
142
|
+
this.find(primaryKeyValue);
|
|
136
143
|
}
|
|
137
144
|
this.queryLayers.base.from = this.Configuration.table;
|
|
138
145
|
const query = this.queryLayers;
|
|
139
146
|
const record = await ((_a = this.repository) === null || _a === void 0 ? void 0 : _a.first(query, this));
|
|
140
147
|
if (!record) {
|
|
141
|
-
throw new
|
|
148
|
+
throw new RecordNotFoundError(primaryKeyValue, this.Configuration.table);
|
|
142
149
|
}
|
|
143
150
|
this.attributes = record;
|
|
144
151
|
this.originalAttributes = { ...this.attributes };
|
|
@@ -152,15 +159,15 @@ export default class Model extends ModelRelations {
|
|
|
152
159
|
async first(primaryKeyValue) {
|
|
153
160
|
var _a;
|
|
154
161
|
if (primaryKeyValue !== undefined) {
|
|
155
|
-
this.
|
|
162
|
+
this.find(primaryKeyValue);
|
|
156
163
|
}
|
|
157
164
|
const attributes = (await ((_a = this.repository) === null || _a === void 0 ? void 0 : _a.first({
|
|
158
165
|
...this.queryLayers,
|
|
159
166
|
base: {
|
|
160
167
|
...this.queryLayers.base,
|
|
161
168
|
from: this.Configuration.table,
|
|
162
|
-
where: this.
|
|
163
|
-
}
|
|
169
|
+
where: this.queryLayers.base.where,
|
|
170
|
+
},
|
|
164
171
|
}, this)));
|
|
165
172
|
if (attributes) {
|
|
166
173
|
this.attributes = attributes;
|
|
@@ -175,7 +182,7 @@ export default class Model extends ModelRelations {
|
|
|
175
182
|
base: {
|
|
176
183
|
...this.queryLayers.base,
|
|
177
184
|
from: this.Configuration.table,
|
|
178
|
-
}
|
|
185
|
+
},
|
|
179
186
|
}, this);
|
|
180
187
|
return records.map((record) => {
|
|
181
188
|
const instance = new this.constructor();
|
|
@@ -196,7 +203,7 @@ export default class Model extends ModelRelations {
|
|
|
196
203
|
base: {
|
|
197
204
|
...this.queryLayers.base,
|
|
198
205
|
from: this.Configuration.table,
|
|
199
|
-
}
|
|
206
|
+
},
|
|
200
207
|
});
|
|
201
208
|
return records.map((record) => {
|
|
202
209
|
const instance = new this.constructor();
|
|
@@ -229,43 +236,56 @@ export default class Model extends ModelRelations {
|
|
|
229
236
|
this.dirty = false;
|
|
230
237
|
return this;
|
|
231
238
|
}
|
|
232
|
-
async update(attributes) {
|
|
239
|
+
async update(attributes = {}) {
|
|
233
240
|
var _a;
|
|
234
241
|
if (this.primaryKey === undefined) {
|
|
235
|
-
throw new
|
|
242
|
+
throw new InvalidOperationError('Primary key value is undefined. Cannot update record without a valid primary key.');
|
|
236
243
|
}
|
|
237
|
-
|
|
244
|
+
if (Object.keys(attributes).length > 0) {
|
|
245
|
+
this.set(attributes);
|
|
246
|
+
}
|
|
247
|
+
const dirtyAttributes = {};
|
|
248
|
+
for (const key in this.attributes) {
|
|
249
|
+
if (this.attributes[key] !== this.originalAttributes[key]) {
|
|
250
|
+
dirtyAttributes[key] = this.attributes[key];
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const newRecord = await ((_a = this.repository) === null || _a === void 0 ? void 0 : _a.update({ [this.primaryKeyColumn]: this.primaryKey }, dirtyAttributes, this.Configuration.table));
|
|
238
254
|
if (newRecord) {
|
|
239
|
-
this.
|
|
255
|
+
this.attributes = { ...newRecord };
|
|
256
|
+
this.originalAttributes = { ...this.attributes };
|
|
240
257
|
this.exists = true;
|
|
258
|
+
this.dirty = false;
|
|
241
259
|
}
|
|
242
260
|
return this;
|
|
243
261
|
}
|
|
244
262
|
near(params) {
|
|
245
263
|
var _a;
|
|
246
264
|
var _b;
|
|
247
|
-
const { referencePoint, targetColumns, maxDistance, unit, orderByDistance, alias = 'distance' } = params;
|
|
248
|
-
const valueClauseKeywords = [`${alias}_lat`, `${alias}_lon`];
|
|
265
|
+
const { referencePoint, targetColumns, maxDistance, minDistance, unit, orderByDistance, alias = 'distance', valueClauseKeywords, } = params;
|
|
249
266
|
const expression = {
|
|
250
267
|
type: 'spatialDistance',
|
|
251
|
-
requirements: {
|
|
252
|
-
phase: QueryEvaluationPhase.PROJECTION,
|
|
253
|
-
cardinality: 'row',
|
|
254
|
-
requiresAlias: true,
|
|
255
|
-
requiresSelectWrapping: true,
|
|
256
|
-
},
|
|
257
268
|
parameters: {
|
|
258
269
|
referencePoint: referencePoint,
|
|
259
270
|
targetColumns: targetColumns,
|
|
260
271
|
alias: alias,
|
|
261
272
|
maxDistance: maxDistance,
|
|
273
|
+
minDistance: minDistance,
|
|
262
274
|
orderByDistance: orderByDistance,
|
|
263
275
|
valueClauseKeywords: valueClauseKeywords,
|
|
264
276
|
unit: unit,
|
|
265
|
-
where:
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
277
|
+
where: [
|
|
278
|
+
{
|
|
279
|
+
column: valueClauseKeywords.lat,
|
|
280
|
+
operator: '=',
|
|
281
|
+
value: referencePoint.lat,
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
column: valueClauseKeywords.lon,
|
|
285
|
+
operator: '=',
|
|
286
|
+
value: referencePoint.lon,
|
|
287
|
+
},
|
|
288
|
+
],
|
|
269
289
|
},
|
|
270
290
|
};
|
|
271
291
|
(_a = (_b = this.queryLayers.base).expressions) !== null && _a !== void 0 ? _a : (_b.expressions = []);
|
|
@@ -275,26 +295,26 @@ export default class Model extends ModelRelations {
|
|
|
275
295
|
isTextRelevant(params) {
|
|
276
296
|
var _a, _b, _c, _d;
|
|
277
297
|
var _e, _f, _g, _h;
|
|
278
|
-
const { targetColumns, searchTerm, minimumRelevance, alias = 'relevance', orderByRelevance =
|
|
279
|
-
const
|
|
298
|
+
const { targetColumns, searchTerm, minimumRelevance, alias = 'relevance', orderByRelevance = 'ASC', } = params;
|
|
299
|
+
const valueClauseKeywords = {
|
|
300
|
+
searchTerm: `${alias}_searchTerm`,
|
|
301
|
+
};
|
|
280
302
|
const expression = {
|
|
281
303
|
type: 'textRelevance',
|
|
282
|
-
requirements: {
|
|
283
|
-
phase: QueryEvaluationPhase.PROJECTION,
|
|
284
|
-
cardinality: 'row',
|
|
285
|
-
requiresAlias: true,
|
|
286
|
-
requiresSelectWrapping: true,
|
|
287
|
-
},
|
|
288
304
|
parameters: {
|
|
289
305
|
targetColumns: targetColumns,
|
|
290
306
|
searchTerm: searchTerm,
|
|
291
307
|
alias: alias,
|
|
292
308
|
minimumRelevance: minimumRelevance,
|
|
293
309
|
orderByRelevance: orderByRelevance,
|
|
294
|
-
valueClauseKeywords:
|
|
295
|
-
where:
|
|
296
|
-
|
|
297
|
-
|
|
310
|
+
valueClauseKeywords: valueClauseKeywords,
|
|
311
|
+
where: [
|
|
312
|
+
{
|
|
313
|
+
column: valueClauseKeywords.searchTerm,
|
|
314
|
+
operator: '=',
|
|
315
|
+
value: searchTerm,
|
|
316
|
+
},
|
|
317
|
+
],
|
|
298
318
|
},
|
|
299
319
|
};
|
|
300
320
|
(_a = (_e = this.queryLayers.base).expressions) !== null && _a !== void 0 ? _a : (_e.expressions = []);
|
|
@@ -316,19 +336,21 @@ export default class Model extends ModelRelations {
|
|
|
316
336
|
const { table, columns, groupByColumns = [], alias = table, nested, having, } = params;
|
|
317
337
|
const expression = {
|
|
318
338
|
type: 'jsonAggregate',
|
|
319
|
-
requirements: {
|
|
320
|
-
phase: QueryEvaluationPhase.PROJECTION,
|
|
321
|
-
cardinality: 'row',
|
|
322
|
-
requiresAlias: true,
|
|
323
|
-
requiresSelectWrapping: true,
|
|
324
|
-
},
|
|
325
339
|
parameters: {
|
|
326
340
|
columns: columns,
|
|
327
341
|
table: table,
|
|
328
342
|
groupByColumns: groupByColumns,
|
|
329
343
|
alias: alias,
|
|
330
344
|
nested: nested,
|
|
331
|
-
having: having
|
|
345
|
+
having: having
|
|
346
|
+
? Array.isArray(having)
|
|
347
|
+
? having
|
|
348
|
+
: Object.entries(having).map(([key, value]) => ({
|
|
349
|
+
column: key,
|
|
350
|
+
operator: '=',
|
|
351
|
+
value: value,
|
|
352
|
+
}))
|
|
353
|
+
: undefined,
|
|
332
354
|
},
|
|
333
355
|
};
|
|
334
356
|
(_a = (_f = this.queryLayers.base).expressionsSelect) !== null && _a !== void 0 ? _a : (_f.expressionsSelect = []);
|
|
@@ -353,12 +375,12 @@ export default class Model extends ModelRelations {
|
|
|
353
375
|
base: {
|
|
354
376
|
...this.queryLayers.base,
|
|
355
377
|
from: this.Configuration.table,
|
|
356
|
-
}
|
|
378
|
+
},
|
|
357
379
|
}, this));
|
|
358
380
|
return sql === null || sql === void 0 ? void 0 : sql.replace(/\s+/g, ' ').replace(/\n/g, '');
|
|
359
381
|
}
|
|
360
382
|
collectSelectAliases(def) {
|
|
361
|
-
const columnAliases = def.columns.map(col => `${def.table}.${col} AS ${def.table}_${col}`);
|
|
383
|
+
const columnAliases = def.columns.map((col) => `${def.table}.${col} AS ${def.table}_${col}`);
|
|
362
384
|
if (def.nested) {
|
|
363
385
|
for (const child of def.nested) {
|
|
364
386
|
columnAliases.push(...this.collectSelectAliases(child));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ColumnDefinition } from "../types/index.js";
|
|
2
|
-
export
|
|
2
|
+
export declare abstract class SchemaTableBuilder {
|
|
3
3
|
protected columns: ColumnDefinition[];
|
|
4
4
|
protected addColumn(data: ColumnDefinition): this;
|
|
5
5
|
abstract build(): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaTableBuilder.d.ts","sourceRoot":"","sources":["../../src/abstract/SchemaTableBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,
|
|
1
|
+
{"version":3,"file":"SchemaTableBuilder.d.ts","sourceRoot":"","sources":["../../src/abstract/SchemaTableBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,8BAAsB,kBAAkB;IACpC,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,CAAM;IAE3C,SAAS,C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QAAQ,CAAC,WAAW,IAAI,IAAI;IAC5B,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CACtC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export
|
|
1
|
+
export class SchemaTableBuilder {
|
|
2
2
|
constructor() {
|
|
3
3
|
this.columns = [];
|
|
4
4
|
}
|
|
5
5
|
addColumn(data) {
|
|
6
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
6
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
7
7
|
if (data.name) {
|
|
8
8
|
this.columns.push({
|
|
9
9
|
...data,
|
|
@@ -12,17 +12,17 @@ export default class SchemaTableBuilder {
|
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
14
14
|
const lastColumn = this.columns[this.columns.length - 1];
|
|
15
|
-
if ((_b = data.constraints) === null || _b === void 0 ? void 0 : _b.includes("NULLABLE")) {
|
|
16
|
-
lastColumn.constraints = (
|
|
15
|
+
if (((_b = data.constraints) === null || _b === void 0 ? void 0 : _b.includes("NULLABLE")) || ((_c = data.constraints) === null || _c === void 0 ? void 0 : _c.includes("NULL"))) {
|
|
16
|
+
lastColumn.constraints = (_e = (_d = lastColumn.constraints) === null || _d === void 0 ? void 0 : _d.filter(constraint => constraint !== "NOT NULL")) !== null && _e !== void 0 ? _e : [];
|
|
17
17
|
}
|
|
18
18
|
this.columns[this.columns.length - 1] = {
|
|
19
19
|
name: lastColumn.name,
|
|
20
|
-
datatype: (
|
|
20
|
+
datatype: (_f = lastColumn.datatype) !== null && _f !== void 0 ? _f : data.datatype,
|
|
21
21
|
constraints: [
|
|
22
|
-
...((
|
|
23
|
-
...((
|
|
22
|
+
...((_g = lastColumn.constraints) !== null && _g !== void 0 ? _g : []),
|
|
23
|
+
...((_h = data.constraints) !== null && _h !== void 0 ? _h : [])
|
|
24
24
|
],
|
|
25
|
-
autoincrement: (
|
|
25
|
+
autoincrement: (_k = (_j = lastColumn.autoincrement) !== null && _j !== void 0 ? _j : data.autoincrement) !== null && _k !== void 0 ? _k : false,
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
return this;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { columnType, joinedEntity, ModelConfig, QueryWhereCondition, relation } from
|
|
2
|
-
import Model from
|
|
3
|
-
import Repository from '../../runtime/Repository.js';
|
|
4
|
-
export
|
|
1
|
+
import { columnType, joinedEntity, ModelConfig, QueryWhereCondition, relation } from '../../types/index.js';
|
|
2
|
+
import { Model } from '../../abstract/Model.js';
|
|
3
|
+
import { Repository } from '../../runtime/Repository.js';
|
|
4
|
+
export declare abstract class ModelRelations<Type extends columnType, Self extends Model<Type> = Model<Type>> {
|
|
5
5
|
protected joinedEntities: joinedEntity[];
|
|
6
6
|
protected relations: relation[];
|
|
7
7
|
abstract get Configuration(): ModelConfig;
|
|
@@ -17,6 +17,7 @@ export default abstract class ModelRelations<Type extends columnType, Self exten
|
|
|
17
17
|
static with<ParameterModelType extends Model<columnType>>(this: new () => ParameterModelType, relation: string, queryScopes?: QueryWhereCondition): ParameterModelType;
|
|
18
18
|
with(relation: string, queryScopes?: QueryWhereCondition): this;
|
|
19
19
|
asyncWith(relation: string, queryScopes?: QueryWhereCondition): Promise<this>;
|
|
20
|
+
private finishWith;
|
|
20
21
|
callRelationMethod(relation: string): void | Promise<void>;
|
|
21
22
|
private normalizeQueryScopes;
|
|
22
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelRelation.d.ts","sourceRoot":"","sources":["../../../src/abstract/model/ModelRelation.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ModelRelation.d.ts","sourceRoot":"","sources":["../../../src/abstract/model/ModelRelation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,YAAY,EACZ,WAAW,EAEX,mBAAmB,EACnB,QAAQ,EACT,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EA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EAClD,KAAK,EAAE,SAAS,EAChB,UAAU,GAAE,MAA4C,EACxD,QAAQ,GAAE,MAAyE,EACnF,IAAI,GAAE,MAAmE,EACzE,IAAI,GAAE,MAA2B,GAChC,IAAI;IAYP,SAAS,CAAC,SAAS,CAAC,SAAS,SAAS,KAAK,CAAC,UAAU,CAAC,EACrD,KAAK,EAAE,SAAS,EAChB,UAAU,GAAE,MAAyE,EACrF,QAAQ,GAAE,MAAuC,EACjD,IAAI,GAAE,MAAmE,EACzE,IAAI,GAAE,MAA2B,GAChC,IAAI;WAYO,IAAI,CAAC,kBAAkB,SAAS,KAAK,CAAC,UAAU,CAAC,EAC7D,IAAI,EAAE,UAAU,kBAAkB,EAClC,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,mBAAmB,GAChC,kBAAkB;IAKd,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,mBAAmB,GAAG,IAAI;IAazD,SAAS,CACpB,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,mBAAmB,GAChC,OAAO,CAAC,IAAI,CAAC;IAMhB,OAAO,CAAC,UAAU;IAoBX,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAYjE,OAAO,CAAC,oBAAoB;CA6B7B"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { RelationError } from '../../helpers/Errors/ModelErrors/RelationError.js';
|
|
2
|
+
import { InvalidOperationError } from '../../helpers/Errors/ModelErrors/InvalidOperationError.js';
|
|
3
|
+
export class ModelRelations {
|
|
2
4
|
constructor() {
|
|
3
5
|
this.joinedEntities = [];
|
|
4
6
|
this.relations = [];
|
|
@@ -13,11 +15,13 @@ export default class ModelRelations {
|
|
|
13
15
|
await this.callRelationMethod(otherTable);
|
|
14
16
|
const relation = this.relations.pop();
|
|
15
17
|
if (!relation) {
|
|
16
|
-
throw new
|
|
18
|
+
throw new RelationError('pivot table insertion', 'Relation not found');
|
|
17
19
|
}
|
|
18
20
|
await this.repository.insertRecordIntoPivotTable(foreignKey, this.self, relation);
|
|
19
21
|
}
|
|
20
|
-
async ManyToMany(model, pivotTable = [this.Configuration.table, model.Configuration.table]
|
|
22
|
+
async ManyToMany(model, pivotTable = [this.Configuration.table, model.Configuration.table]
|
|
23
|
+
.sort()
|
|
24
|
+
.join('_'), localKey = this.Configuration.primaryKey, foreignKey = model.Configuration.primaryKey, pivotForeignKey = `${this.Configuration.table}_${localKey}`, pivotLocalKey = `${model.Configuration.table}_${foreignKey}`, path = pivotTable, name = path.split('.')[1]) {
|
|
21
25
|
const relation = await this.repository.getManyToManyRelation({
|
|
22
26
|
type: 'manyToMany',
|
|
23
27
|
model: model,
|
|
@@ -30,7 +34,7 @@ export default class ModelRelations {
|
|
|
30
34
|
pivotLocalKey: pivotLocalKey,
|
|
31
35
|
});
|
|
32
36
|
if (!relation) {
|
|
33
|
-
throw new
|
|
37
|
+
throw new RelationError(model.Configuration.table, 'Failed to create many-to-many relation');
|
|
34
38
|
}
|
|
35
39
|
this.relations.push(relation);
|
|
36
40
|
return this;
|
|
@@ -42,7 +46,7 @@ export default class ModelRelations {
|
|
|
42
46
|
foreignKey: foreignKey,
|
|
43
47
|
localKey: localKey,
|
|
44
48
|
path: path,
|
|
45
|
-
name: name
|
|
49
|
+
name: name,
|
|
46
50
|
});
|
|
47
51
|
return this;
|
|
48
52
|
}
|
|
@@ -53,7 +57,7 @@ export default class ModelRelations {
|
|
|
53
57
|
foreignKey: foreignKey,
|
|
54
58
|
localKey: localKey,
|
|
55
59
|
path: path,
|
|
56
|
-
name: name
|
|
60
|
+
name: name,
|
|
57
61
|
});
|
|
58
62
|
return this;
|
|
59
63
|
}
|
|
@@ -64,7 +68,7 @@ export default class ModelRelations {
|
|
|
64
68
|
foreignKey: foreignKey,
|
|
65
69
|
localKey: localKey,
|
|
66
70
|
path: path,
|
|
67
|
-
name: name
|
|
71
|
+
name: name,
|
|
68
72
|
});
|
|
69
73
|
return this;
|
|
70
74
|
}
|
|
@@ -73,39 +77,37 @@ export default class ModelRelations {
|
|
|
73
77
|
return instance.with(relation, queryScopes);
|
|
74
78
|
}
|
|
75
79
|
with(relation, queryScopes) {
|
|
76
|
-
const
|
|
80
|
+
const [relationName, alias] = relation.split(' as ').map((s) => s.trim());
|
|
81
|
+
const result = this.callRelationMethod(relationName);
|
|
77
82
|
if (result instanceof Promise) {
|
|
78
|
-
throw new
|
|
83
|
+
throw new InvalidOperationError(`Relation method '${relationName}' is asynchronous. Use asyncWith() instead of with().`);
|
|
79
84
|
}
|
|
80
|
-
|
|
81
|
-
const tableName = lastRelation.model.Configuration.table;
|
|
82
|
-
const normalizedScopes = this.normalizeQueryScopes(queryScopes, tableName);
|
|
83
|
-
this.joinedEntities.push({
|
|
84
|
-
relation: relation,
|
|
85
|
-
path: lastRelation.path,
|
|
86
|
-
queryScopes: normalizedScopes
|
|
87
|
-
});
|
|
88
|
-
return this;
|
|
85
|
+
return this.finishWith(alias, relationName, queryScopes);
|
|
89
86
|
}
|
|
90
87
|
async asyncWith(relation, queryScopes) {
|
|
91
|
-
|
|
88
|
+
const [relationName, alias] = relation.split(' as ').map((s) => s.trim());
|
|
89
|
+
await this.callRelationMethod(relationName);
|
|
90
|
+
return this.finishWith(alias, relationName, queryScopes);
|
|
91
|
+
}
|
|
92
|
+
finishWith(alias, relationName, queryScopes) {
|
|
92
93
|
const lastRelation = this.relations[this.relations.length - 1];
|
|
93
|
-
const tableName = lastRelation.model.Configuration.table;
|
|
94
|
+
const tableName = alias || lastRelation.model.Configuration.table;
|
|
94
95
|
const normalizedScopes = this.normalizeQueryScopes(queryScopes, tableName);
|
|
95
96
|
this.joinedEntities.push({
|
|
96
|
-
relation:
|
|
97
|
+
relation: relationName,
|
|
98
|
+
alias: alias,
|
|
97
99
|
path: lastRelation.path,
|
|
98
|
-
queryScopes: normalizedScopes
|
|
100
|
+
queryScopes: normalizedScopes,
|
|
99
101
|
});
|
|
100
102
|
return this;
|
|
101
103
|
}
|
|
102
104
|
callRelationMethod(relation) {
|
|
103
105
|
const method = Reflect.get(this, relation);
|
|
104
106
|
if (typeof method !== 'function') {
|
|
105
|
-
throw new
|
|
107
|
+
throw new RelationError(relation, 'Relation method does not exist');
|
|
106
108
|
}
|
|
107
109
|
const result = method.call(this);
|
|
108
|
-
//@TODO: check if method is not static
|
|
110
|
+
//@TODO: check if method is not static
|
|
109
111
|
// Only return promise if the method is actually async
|
|
110
112
|
return result instanceof Promise ? result : undefined;
|
|
111
113
|
}
|
|
@@ -119,10 +121,16 @@ export default class ModelRelations {
|
|
|
119
121
|
'value' in queryScopes;
|
|
120
122
|
const scopesArray = isSingleParameter
|
|
121
123
|
? [queryScopes]
|
|
122
|
-
:
|
|
123
|
-
|
|
124
|
+
: (Array.isArray(queryScopes)
|
|
125
|
+
? queryScopes
|
|
126
|
+
: Object.entries(queryScopes).map(([key, value]) => ({
|
|
127
|
+
column: key,
|
|
128
|
+
operator: '=',
|
|
129
|
+
value,
|
|
130
|
+
})));
|
|
131
|
+
return scopesArray.map((scope) => ({
|
|
124
132
|
...scope,
|
|
125
|
-
column: `${tableName}.${scope.column}
|
|
133
|
+
column: `${tableName}.${scope.column}`,
|
|
126
134
|
}));
|
|
127
135
|
}
|
|
128
136
|
}
|