@iamkirbki/database-handler-core 4.3.1 → 4.4.1
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 +17 -0
- package/dist/abstract/Controller.d.ts.map +1 -0
- package/dist/abstract/Controller.js +47 -0
- package/dist/abstract/Model.d.ts +33 -19
- package/dist/abstract/Model.d.ts.map +1 -1
- package/dist/abstract/Model.js +176 -121
- package/dist/abstract/SchemaTableBuilder.d.ts +1 -1
- package/dist/abstract/SchemaTableBuilder.d.ts.map +1 -1
- package/dist/abstract/model/ModelRelation.d.ts +23 -0
- package/dist/abstract/model/ModelRelation.d.ts.map +1 -0
- package/dist/abstract/model/ModelRelation.js +130 -0
- package/dist/base/Query.d.ts +6 -4
- package/dist/base/Query.d.ts.map +1 -1
- package/dist/base/Query.js +62 -21
- package/dist/base/Record.d.ts.map +1 -1
- package/dist/base/Record.js +7 -5
- package/dist/base/Table.d.ts +5 -4
- package/dist/base/Table.d.ts.map +1 -1
- package/dist/base/Table.js +56 -31
- package/dist/helpers/Errors/AdapterErrors/AdapterNotFoundError.d.ts +4 -0
- package/dist/helpers/Errors/AdapterErrors/AdapterNotFoundError.d.ts.map +1 -0
- package/dist/helpers/Errors/AdapterErrors/AdapterNotFoundError.js +6 -0
- package/dist/helpers/Errors/AdapterErrors/ConnectionFailedError.d.ts +4 -0
- package/dist/helpers/Errors/AdapterErrors/ConnectionFailedError.d.ts.map +1 -0
- package/dist/helpers/Errors/AdapterErrors/ConnectionFailedError.js +6 -0
- package/dist/helpers/Errors/AdapterErrors/NoDefaultAdapterError.d.ts +4 -0
- package/dist/helpers/Errors/AdapterErrors/NoDefaultAdapterError.d.ts.map +1 -0
- package/dist/helpers/Errors/AdapterErrors/NoDefaultAdapterError.js +6 -0
- package/dist/helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.d.ts +4 -0
- package/dist/helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.d.ts.map +1 -0
- package/dist/helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.js +6 -0
- package/dist/helpers/Errors/ExpressionErrors/UnknownExpressionTypeError.d.ts +4 -0
- package/dist/helpers/Errors/ExpressionErrors/UnknownExpressionTypeError.d.ts.map +1 -0
- package/dist/helpers/Errors/ExpressionErrors/UnknownExpressionTypeError.js +6 -0
- package/dist/helpers/Errors/ExpressionErrors/UnsupportedQueryPhaseError.d.ts +4 -0
- package/dist/helpers/Errors/ExpressionErrors/UnsupportedQueryPhaseError.d.ts.map +1 -0
- package/dist/helpers/Errors/ExpressionErrors/UnsupportedQueryPhaseError.js +6 -0
- package/dist/helpers/Errors/QueryErrors/UnexpectedEmptyQueryError.d.ts +4 -0
- package/dist/helpers/Errors/QueryErrors/UnexpectedEmptyQueryError.d.ts.map +1 -0
- package/dist/helpers/Errors/QueryErrors/UnexpectedEmptyQueryError.js +6 -0
- package/dist/helpers/Errors/TableErrors/UnknownTableError.d.ts +4 -0
- package/dist/helpers/Errors/TableErrors/UnknownTableError.d.ts.map +1 -0
- package/dist/helpers/Errors/TableErrors/UnknownTableError.js +6 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseDeleteQueryBuilder.d.ts +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseDeleteQueryBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseDeleteQueryBuilder.js +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseInsertQueryBuilder.d.ts +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseInsertQueryBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseInsertQueryBuilder.js +11 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.d.ts +11 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.js +27 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseUpdateQueryBuilder.d.ts +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseUpdateQueryBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseUpdateQueryBuilder.js +1 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.d.ts +9 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.js +102 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/SpatialDistanceExpression.d.ts +8 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/SpatialDistanceExpression.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/SpatialDistanceExpression.js +63 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/TextRelevanceExpression.d.ts +8 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/TextRelevanceExpression.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/TextRelevanceExpression.js +49 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.d.ts +19 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.js +60 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.d.ts +9 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.js +27 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/JoinDecorator.d.ts +15 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/JoinDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/JoinDecorator.js +74 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/LimitDecorator.d.ts +10 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/LimitDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/LimitDecorator.js +29 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.d.ts +9 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.js +27 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/QueryDecorator.d.ts +8 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/QueryDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/QueryDecorator.js +5 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/ValuesDecorator.d.ts +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/ValuesDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/ValuesDecorator.js +17 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/WhereDecorator.d.ts +9 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/WhereDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/WhereDecorator.js +29 -0
- package/dist/helpers/QueryBuilders/QueryExpressionBuilder.d.ts +54 -0
- package/dist/helpers/QueryBuilders/QueryExpressionBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryExpressionBuilder.js +102 -0
- package/dist/helpers/QueryBuilders/QueryStatementBuilder.d.ts +16 -0
- package/dist/helpers/QueryBuilders/QueryStatementBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryStatementBuilder.js +169 -0
- package/dist/helpers/QueryBuilders/SqlRenderer.d.ts +15 -0
- package/dist/helpers/QueryBuilders/SqlRenderer.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/SqlRenderer.js +79 -0
- package/dist/helpers/QueryBuilders/oldQueryStatementBuilder.d.ts +160 -0
- package/dist/helpers/QueryBuilders/oldQueryStatementBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/oldQueryStatementBuilder.js +217 -0
- package/dist/interfaces/IExpressionBuilder.d.ts +7 -0
- package/dist/interfaces/IExpressionBuilder.d.ts.map +1 -0
- package/dist/interfaces/IExpressionBuilder.js +1 -0
- package/dist/interfaces/IQueryBuilder.d.ts +5 -0
- package/dist/interfaces/IQueryBuilder.d.ts.map +1 -0
- package/dist/interfaces/IQueryBuilder.js +1 -0
- package/dist/runtime/Container.d.ts +1 -0
- package/dist/runtime/Container.d.ts.map +1 -1
- package/dist/runtime/Container.js +5 -2
- package/dist/runtime/QueryCache.d.ts +12 -0
- package/dist/runtime/QueryCache.d.ts.map +1 -0
- package/dist/runtime/QueryCache.js +26 -0
- package/dist/runtime/Repository.d.ts +6 -4
- package/dist/runtime/Repository.d.ts.map +1 -1
- package/dist/runtime/Repository.js +95 -60
- package/dist/types/expressions.d.ts +154 -0
- package/dist/types/expressions.d.ts.map +1 -0
- package/dist/types/expressions.js +6 -0
- package/dist/types/factories.d.ts +3 -2
- package/dist/types/factories.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/model.d.ts +8 -8
- package/dist/types/model.d.ts.map +1 -1
- package/dist/types/query.d.ts +56 -2
- package/dist/types/query.d.ts.map +1 -1
- package/package.json +11 -3
- package/dist/helpers/QueryStatementBuilder.d.ts +0 -305
- package/dist/helpers/QueryStatementBuilder.d.ts.map +0 -1
- package/dist/helpers/QueryStatementBuilder.js +0 -416
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Model from './Model.js';
|
|
2
|
+
import { columnType } from '../types/index.js';
|
|
3
|
+
export default abstract class Controller<Type extends columnType> {
|
|
4
|
+
abstract index(): Promise<Model<Type>[]>;
|
|
5
|
+
abstract show(value: string | number): Promise<Model<Type>>;
|
|
6
|
+
abstract edit(value: string | number): Promise<Model<Type>>;
|
|
7
|
+
abstract update(id: string | number, newValues: Type): Promise<Model<Type>>;
|
|
8
|
+
abstract create(data: Type): Promise<Model<Type>>;
|
|
9
|
+
abstract delete(id: string | number): Promise<boolean>;
|
|
10
|
+
static index<StaticType extends columnType>(this: new () => Controller<StaticType>): Promise<Model<StaticType>[]>;
|
|
11
|
+
static show<StaticType extends columnType>(this: new () => Controller<StaticType>, value: string | number): Promise<Model<StaticType>>;
|
|
12
|
+
static edit<StaticType extends columnType>(this: new () => Controller<StaticType>, value: string | number): Promise<Model<StaticType>>;
|
|
13
|
+
static update<StaticType extends columnType>(this: new () => Controller<StaticType>, id: string | number, newValues: StaticType): Promise<Model<StaticType>>;
|
|
14
|
+
static create<StaticType extends columnType>(this: new () => Controller<StaticType>, data: StaticType): Promise<Model<StaticType>>;
|
|
15
|
+
static delete<StaticType extends columnType>(this: new () => Controller<StaticType>, id: string | number): Promise<boolean>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=Controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Controller.d.ts","sourceRoot":"","sources":["../../src/abstract/Controller.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,UAAU,CAAC,IAAI,SAAS,UAAU;IAC9D,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;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EACtC,EAAE,EAAE,MAAM,GAAG,MAAM,GAClB,OAAO,CAAC,OAAO,CAAC;CAIpB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export default class Controller {
|
|
11
|
+
static index() {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
const instance = new this();
|
|
14
|
+
return yield instance.index();
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
static show(value) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const instance = new this();
|
|
20
|
+
return yield instance.show(value);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
static edit(value) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const instance = new this();
|
|
26
|
+
return yield instance.edit(value);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
static update(id, newValues) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const instance = new this();
|
|
32
|
+
return yield instance.update(id, newValues);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
static create(data) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const instance = new this();
|
|
38
|
+
return yield instance.create(data);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
static delete(id) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const instance = new this();
|
|
44
|
+
return yield instance.delete(id);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
package/dist/abstract/Model.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import Repository from
|
|
2
|
-
import
|
|
1
|
+
import Repository from '../runtime/Repository.js';
|
|
2
|
+
import ModelRelations from '../abstract/model/ModelRelation.js';
|
|
3
|
+
import { columnType, QueryWhereCondition, QueryValues, ModelConfig, SpatialPoint, SpatialPointColumns, NestedJsonAggregateDefinition, QueryLayers } from '../types/index.js';
|
|
3
4
|
/** Abstract Model class for ORM-style database interactions */
|
|
4
|
-
export default abstract class Model<ModelType extends columnType> {
|
|
5
|
+
export default abstract class Model<ModelType extends columnType> extends ModelRelations<ModelType> {
|
|
5
6
|
private _repository?;
|
|
6
7
|
protected get repository(): Repository<ModelType, Model<ModelType>>;
|
|
8
|
+
protected get self(): Model<ModelType>;
|
|
7
9
|
protected configuration: ModelConfig;
|
|
8
10
|
get Configuration(): ModelConfig;
|
|
9
11
|
protected originalAttributes: Partial<ModelType>;
|
|
10
12
|
protected attributes: Partial<ModelType>;
|
|
11
13
|
protected exists: boolean;
|
|
12
14
|
protected dirty: boolean;
|
|
13
|
-
protected
|
|
14
|
-
protected queryOptions: ExtraQueryParameters;
|
|
15
|
+
protected queryLayers: QueryLayers;
|
|
15
16
|
get primaryKeyColumn(): string;
|
|
16
17
|
get primaryKey(): QueryValues | undefined;
|
|
17
18
|
get values(): Partial<ModelType> | ModelType;
|
|
@@ -22,6 +23,7 @@ export default abstract class Model<ModelType extends columnType> {
|
|
|
22
23
|
static orderBy<ParamterModelType extends Model<columnType>>(this: new () => ParamterModelType, column: string, direction?: 'ASC' | 'DESC'): ParamterModelType;
|
|
23
24
|
orderBy(column: string, direction?: 'ASC' | 'DESC'): this;
|
|
24
25
|
static where<ParamterModelType extends Model<columnType>>(this: new () => ParamterModelType, conditions: QueryWhereCondition): ParamterModelType;
|
|
26
|
+
private normalizeConditions;
|
|
25
27
|
where(conditions: QueryWhereCondition): this;
|
|
26
28
|
static whereId<ParamterModelType extends Model<columnType>>(this: new () => ParamterModelType, id: QueryValues): ParamterModelType;
|
|
27
29
|
whereId(id: QueryValues): this;
|
|
@@ -38,20 +40,32 @@ export default abstract class Model<ModelType extends columnType> {
|
|
|
38
40
|
set(attributes: Partial<ModelType>): this;
|
|
39
41
|
save(): Promise<this>;
|
|
40
42
|
update(attributes: Partial<ModelType>): Promise<this>;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
near(params: {
|
|
44
|
+
referencePoint: SpatialPoint;
|
|
45
|
+
targetColumns: SpatialPointColumns;
|
|
46
|
+
maxDistance: number;
|
|
47
|
+
unit: 'km' | 'miles';
|
|
48
|
+
orderByDistance: 'ASC' | 'DESC';
|
|
49
|
+
alias?: string;
|
|
50
|
+
}): this;
|
|
51
|
+
isTextRelevant(params: {
|
|
52
|
+
targetColumns: string[];
|
|
53
|
+
searchTerm: string;
|
|
54
|
+
minimumRelevance?: number;
|
|
55
|
+
alias?: string;
|
|
56
|
+
orderByRelevance?: 'ASC' | 'DESC';
|
|
57
|
+
}): this;
|
|
58
|
+
JsonAggregate(params: {
|
|
59
|
+
table: string;
|
|
60
|
+
columns: string[];
|
|
61
|
+
groupByColumns?: string[];
|
|
62
|
+
alias?: string;
|
|
63
|
+
nested?: NestedJsonAggregateDefinition<string>[];
|
|
64
|
+
having?: QueryWhereCondition;
|
|
65
|
+
}): this;
|
|
66
|
+
toSql(): Promise<string>;
|
|
67
|
+
private collectSelectAliases;
|
|
68
|
+
private collectTables;
|
|
55
69
|
toJSON(): Partial<ModelType> | ModelType;
|
|
56
70
|
toObject(): Partial<ModelType> | ModelType;
|
|
57
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../../src/abstract/Model.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,6BAA6B,CAAC;AACrD,OAAO,
|
|
1
|
+
{"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../../src/abstract/Model.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,6BAA6B,CAAC;AACrD,OAAO,cAAc,MAAM,uCAAuC,CAAC;AACnE,OAAO,EACH,UAAU,EACV,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,YAAY,EACZ,mBAAmB,EAKnB,6BAA6B,EAE7B,WAAW,EACd,MAAM,sBAAsB,CAAC;AAE9B,+DAA+D;AAC/D,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,KAAK,CAC/B,SAAS,SAAS,UAAU,CAC9B,SAAQ,cAAc,CAAC,SAAS,CAAC;IAC/B,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;IAC9C,SAAS,CAAC,MAAM,EAAE,OAAO,CAAS;IAClC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAS;IACjC,SAAS,CAAC,WAAW,EAAE,WAAW,CAQhC;IAEF,IAAW,gBAAgB,IAAI,MAAM,CAEpC;IAED,IAAW,UAAU,IAAI,WAAW,GAAG,SAAS,CAE/C;IAED,IAAW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AG,MAAM,CAAC;QAChC,KAAK,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,IAAI;IAiCD,cAAc,CAAC,MAAM,EAAE;QAC1B,aAAa,EAAE,MAAM,EAAE,CAAC;QACxB,UAAU,EAAE,MAAM,CAAC;QACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,gBAAgB,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;KACrC,GAAG,IAAI;IA0CD,aAAa,CAAC,MAAM,EAAE;QACzB,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;QAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,6BAA6B,CAAC,MAAM,CAAC,EAAE,CAAC;QACjD,MAAM,CAAC,EAAE,mBAAmB,CAAC;KAChC,GAAG,IAAI;IAgDK,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAerC,OAAO,CAAC,oBAAoB;IAY5B,OAAO,CAAC,aAAa;IAad,MAAM,IAAI,OAAO,CAAC,SAAS,CAAC,GAAG,SAAS;IAIxC,QAAQ,IAAI,OAAO,CAAC,SAAS,CAAC,GAAG,SAAS;CAGpD"}
|
package/dist/abstract/Model.js
CHANGED
|
@@ -7,10 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import Repository from
|
|
10
|
+
import Repository from '../runtime/Repository.js';
|
|
11
|
+
import ModelRelations from '../abstract/model/ModelRelation.js';
|
|
12
|
+
import { QueryEvaluationPhase, } from '../types/index.js';
|
|
11
13
|
/** Abstract Model class for ORM-style database interactions */
|
|
12
|
-
export default class Model {
|
|
14
|
+
export default class Model extends ModelRelations {
|
|
13
15
|
constructor() {
|
|
16
|
+
super(...arguments);
|
|
14
17
|
this.configuration = {
|
|
15
18
|
table: '', // Must be set by subclass
|
|
16
19
|
primaryKey: 'id',
|
|
@@ -25,9 +28,13 @@ export default class Model {
|
|
|
25
28
|
this.attributes = {};
|
|
26
29
|
this.exists = false;
|
|
27
30
|
this.dirty = false;
|
|
28
|
-
this.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
this.queryLayers = {
|
|
32
|
+
base: {
|
|
33
|
+
from: this.Configuration.table,
|
|
34
|
+
},
|
|
35
|
+
pretty: {},
|
|
36
|
+
final: {}
|
|
37
|
+
};
|
|
31
38
|
}
|
|
32
39
|
get repository() {
|
|
33
40
|
if (!this._repository) {
|
|
@@ -35,6 +42,9 @@ export default class Model {
|
|
|
35
42
|
}
|
|
36
43
|
return this._repository;
|
|
37
44
|
}
|
|
45
|
+
get self() {
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
38
48
|
get Configuration() {
|
|
39
49
|
return this.configuration;
|
|
40
50
|
}
|
|
@@ -52,7 +62,10 @@ export default class Model {
|
|
|
52
62
|
return instance.limit(value);
|
|
53
63
|
}
|
|
54
64
|
limit(value) {
|
|
55
|
-
|
|
65
|
+
var _a;
|
|
66
|
+
var _b;
|
|
67
|
+
(_a = (_b = this.queryLayers).final) !== null && _a !== void 0 ? _a : (_b.final = {});
|
|
68
|
+
this.queryLayers.final.limit = value;
|
|
56
69
|
return this;
|
|
57
70
|
}
|
|
58
71
|
static offset(value) {
|
|
@@ -60,10 +73,11 @@ export default class Model {
|
|
|
60
73
|
return instance.offset(value);
|
|
61
74
|
}
|
|
62
75
|
offset(value) {
|
|
63
|
-
|
|
64
|
-
|
|
76
|
+
var _a;
|
|
77
|
+
if (!((_a = this.queryLayers.final) === null || _a === void 0 ? void 0 : _a.limit)) {
|
|
78
|
+
throw new Error('Offset cannot be set without a limit.');
|
|
65
79
|
}
|
|
66
|
-
this.
|
|
80
|
+
this.queryLayers.final.offset = value;
|
|
67
81
|
return this;
|
|
68
82
|
}
|
|
69
83
|
static orderBy(column, direction = 'ASC') {
|
|
@@ -71,15 +85,36 @@ export default class Model {
|
|
|
71
85
|
return instance.orderBy(column, direction);
|
|
72
86
|
}
|
|
73
87
|
orderBy(column, direction = 'ASC') {
|
|
74
|
-
|
|
88
|
+
var _a, _b;
|
|
89
|
+
var _c, _d;
|
|
90
|
+
(_a = (_c = this.queryLayers).final) !== null && _a !== void 0 ? _a : (_c.final = {});
|
|
91
|
+
(_b = (_d = this.queryLayers.final).orderBy) !== null && _b !== void 0 ? _b : (_d.orderBy = []);
|
|
92
|
+
this.queryLayers.final.orderBy.push({ column, direction });
|
|
75
93
|
return this;
|
|
76
94
|
}
|
|
77
95
|
static where(conditions) {
|
|
78
96
|
const instance = new this();
|
|
79
97
|
return instance.where(conditions);
|
|
80
98
|
}
|
|
99
|
+
normalizeConditions(conditions) {
|
|
100
|
+
if (Array.isArray(conditions)) {
|
|
101
|
+
return conditions;
|
|
102
|
+
}
|
|
103
|
+
return Object.entries(conditions).map(([column, value]) => ({
|
|
104
|
+
column,
|
|
105
|
+
operator: '=',
|
|
106
|
+
value,
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
81
109
|
where(conditions) {
|
|
82
|
-
|
|
110
|
+
const normalized = this.normalizeConditions(conditions);
|
|
111
|
+
if (!this.queryLayers.base.where) {
|
|
112
|
+
this.queryLayers.base.where = normalized;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
const existing = this.normalizeConditions(this.queryLayers.base.where);
|
|
116
|
+
this.queryLayers.base.where = [...existing, ...normalized];
|
|
117
|
+
}
|
|
83
118
|
return this;
|
|
84
119
|
}
|
|
85
120
|
static whereId(id) {
|
|
@@ -87,7 +122,7 @@ export default class Model {
|
|
|
87
122
|
return instance.whereId(id);
|
|
88
123
|
}
|
|
89
124
|
whereId(id) {
|
|
90
|
-
this.
|
|
125
|
+
this.queryLayers.base.where = [{ column: this.primaryKeyColumn, operator: '=', value: id }];
|
|
91
126
|
return this;
|
|
92
127
|
}
|
|
93
128
|
static find(primaryKeyValue) {
|
|
@@ -95,22 +130,22 @@ export default class Model {
|
|
|
95
130
|
return instance.find(primaryKeyValue);
|
|
96
131
|
}
|
|
97
132
|
find(primaryKeyValue) {
|
|
98
|
-
this.
|
|
133
|
+
this.queryLayers.base.where = [{ column: this.primaryKeyColumn, operator: '=', value: primaryKeyValue }];
|
|
99
134
|
return this;
|
|
100
135
|
}
|
|
101
136
|
static findOrFail(primaryKeyValue) {
|
|
102
137
|
return __awaiter(this, void 0, void 0, function* () {
|
|
103
138
|
const instance = new this();
|
|
104
|
-
return yield instance.findOrFail(primaryKeyValue);
|
|
139
|
+
return (yield instance.findOrFail(primaryKeyValue));
|
|
105
140
|
});
|
|
106
141
|
}
|
|
107
142
|
findOrFail(primaryKeyValue) {
|
|
108
143
|
return __awaiter(this, void 0, void 0, function* () {
|
|
109
144
|
var _a;
|
|
110
145
|
if (primaryKeyValue) {
|
|
111
|
-
this.
|
|
146
|
+
this.queryLayers.base.where = [{ column: this.primaryKeyColumn, operator: '=', value: primaryKeyValue }];
|
|
112
147
|
}
|
|
113
|
-
const query = this.
|
|
148
|
+
const query = this.queryLayers;
|
|
114
149
|
const record = yield ((_a = this.repository) === null || _a === void 0 ? void 0 : _a.first(query, this));
|
|
115
150
|
if (!record) {
|
|
116
151
|
throw new Error(`Record with primary key ${primaryKeyValue} not found.`);
|
|
@@ -130,7 +165,10 @@ export default class Model {
|
|
|
130
165
|
first(primaryKeyValue) {
|
|
131
166
|
return __awaiter(this, void 0, void 0, function* () {
|
|
132
167
|
var _a;
|
|
133
|
-
|
|
168
|
+
if (primaryKeyValue !== undefined) {
|
|
169
|
+
this.queryLayers.base.where = [{ column: this.primaryKeyColumn, operator: '=', value: primaryKeyValue }, ...this.normalizeConditions(this.queryLayers.base.where || [])];
|
|
170
|
+
}
|
|
171
|
+
const attributes = (yield ((_a = this.repository) === null || _a === void 0 ? void 0 : _a.first(Object.assign(Object.assign({}, this.queryLayers), { base: Object.assign(Object.assign({}, this.queryLayers.base), { from: this.Configuration.table, where: this.normalizeConditions(this.queryLayers.base.where || []) }) }), this)));
|
|
134
172
|
if (attributes) {
|
|
135
173
|
this.attributes = attributes;
|
|
136
174
|
this.originalAttributes = Object.assign({}, attributes);
|
|
@@ -141,8 +179,8 @@ export default class Model {
|
|
|
141
179
|
}
|
|
142
180
|
get() {
|
|
143
181
|
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
-
const records = yield this.repository.get(this.
|
|
145
|
-
return records.map(record => {
|
|
182
|
+
const records = yield this.repository.get(Object.assign(Object.assign({}, this.queryLayers), { base: Object.assign(Object.assign({}, this.queryLayers.base), { from: this.Configuration.table }) }), this);
|
|
183
|
+
return records.map((record) => {
|
|
146
184
|
const instance = new this.constructor();
|
|
147
185
|
instance.set(record);
|
|
148
186
|
instance.exists = true;
|
|
@@ -158,8 +196,8 @@ export default class Model {
|
|
|
158
196
|
}
|
|
159
197
|
all() {
|
|
160
198
|
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
-
const records = yield this.repository.all(this, this.
|
|
162
|
-
return records.map(record => {
|
|
199
|
+
const records = yield this.repository.all(this, Object.assign(Object.assign({}, this.queryLayers), { base: Object.assign(Object.assign({}, this.queryLayers.base), { from: this.Configuration.table }) }));
|
|
200
|
+
return records.map((record) => {
|
|
163
201
|
const instance = new this.constructor();
|
|
164
202
|
instance.set(record);
|
|
165
203
|
instance.exists = true;
|
|
@@ -193,11 +231,8 @@ export default class Model {
|
|
|
193
231
|
update(attributes) {
|
|
194
232
|
return __awaiter(this, void 0, void 0, function* () {
|
|
195
233
|
var _a;
|
|
196
|
-
if (!this.exists) {
|
|
197
|
-
throw new Error("Cannot update a model that does not exist in the database.");
|
|
198
|
-
}
|
|
199
234
|
if (this.primaryKey === undefined) {
|
|
200
|
-
throw new Error(
|
|
235
|
+
throw new Error('Primary key value is undefined. Cannot update record without a valid primary key.');
|
|
201
236
|
}
|
|
202
237
|
const newRecord = yield ((_a = this.repository) === null || _a === void 0 ? void 0 : _a.update({ [this.primaryKeyColumn]: this.primaryKey }, attributes));
|
|
203
238
|
if (newRecord) {
|
|
@@ -207,115 +242,135 @@ export default class Model {
|
|
|
207
242
|
return this;
|
|
208
243
|
});
|
|
209
244
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
hasMany(model, foreignKey = `${this.Configuration.table}_${this.Configuration.primaryKey}`, localKey = this.Configuration.primaryKey) {
|
|
240
|
-
this.relations.push({
|
|
241
|
-
type: 'hasMany',
|
|
242
|
-
model: model,
|
|
243
|
-
foreignKey: foreignKey,
|
|
244
|
-
localKey: localKey,
|
|
245
|
-
});
|
|
246
|
-
return this;
|
|
247
|
-
}
|
|
248
|
-
hasOne(model, foreignKey = `${model.Configuration.primaryKey}`, localKey = `${model.Configuration.table}_${model.Configuration.primaryKey}`) {
|
|
249
|
-
this.relations.push({
|
|
250
|
-
type: 'hasOne',
|
|
251
|
-
model: model,
|
|
252
|
-
foreignKey: foreignKey,
|
|
253
|
-
localKey: localKey,
|
|
254
|
-
});
|
|
245
|
+
near(params) {
|
|
246
|
+
var _a;
|
|
247
|
+
var _b;
|
|
248
|
+
const { referencePoint, targetColumns, maxDistance, unit, orderByDistance, alias = 'distance' } = params;
|
|
249
|
+
const valueClauseKeywords = [`${alias}_lat`, `${alias}_lon`];
|
|
250
|
+
const expression = {
|
|
251
|
+
type: 'spatialDistance',
|
|
252
|
+
requirements: {
|
|
253
|
+
phase: QueryEvaluationPhase.PROJECTION,
|
|
254
|
+
cardinality: 'row',
|
|
255
|
+
requiresAlias: true,
|
|
256
|
+
requiresSelectWrapping: true,
|
|
257
|
+
},
|
|
258
|
+
parameters: {
|
|
259
|
+
referencePoint: referencePoint,
|
|
260
|
+
targetColumns: targetColumns,
|
|
261
|
+
alias: alias,
|
|
262
|
+
maxDistance: maxDistance,
|
|
263
|
+
orderByDistance: orderByDistance,
|
|
264
|
+
valueClauseKeywords: valueClauseKeywords,
|
|
265
|
+
unit: unit,
|
|
266
|
+
where: {
|
|
267
|
+
[valueClauseKeywords[0]]: referencePoint.lat,
|
|
268
|
+
[valueClauseKeywords[1]]: referencePoint.lon,
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
};
|
|
272
|
+
(_a = (_b = this.queryLayers.base).expressions) !== null && _a !== void 0 ? _a : (_b.expressions = []);
|
|
273
|
+
this.queryLayers.base.expressions.push(expression);
|
|
255
274
|
return this;
|
|
256
275
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
276
|
+
isTextRelevant(params) {
|
|
277
|
+
var _a, _b, _c, _d;
|
|
278
|
+
var _e, _f, _g, _h;
|
|
279
|
+
const { targetColumns, searchTerm, minimumRelevance, alias = 'relevance', orderByRelevance = "ASC" } = params;
|
|
280
|
+
const valueClauseKeyword = `${alias}_searchTerm`;
|
|
281
|
+
const expression = {
|
|
282
|
+
type: 'textRelevance',
|
|
283
|
+
requirements: {
|
|
284
|
+
phase: QueryEvaluationPhase.PROJECTION,
|
|
285
|
+
cardinality: 'row',
|
|
286
|
+
requiresAlias: true,
|
|
287
|
+
requiresSelectWrapping: true,
|
|
288
|
+
},
|
|
289
|
+
parameters: {
|
|
290
|
+
targetColumns: targetColumns,
|
|
291
|
+
searchTerm: searchTerm,
|
|
292
|
+
alias: alias,
|
|
293
|
+
minimumRelevance: minimumRelevance,
|
|
294
|
+
orderByRelevance: orderByRelevance,
|
|
295
|
+
valueClauseKeywords: [valueClauseKeyword],
|
|
296
|
+
where: {
|
|
297
|
+
[valueClauseKeyword]: searchTerm,
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
};
|
|
301
|
+
(_a = (_e = this.queryLayers.base).expressions) !== null && _a !== void 0 ? _a : (_e.expressions = []);
|
|
302
|
+
this.queryLayers.base.expressions.push(expression);
|
|
303
|
+
(_b = (_f = this.queryLayers).pretty) !== null && _b !== void 0 ? _b : (_f.pretty = {});
|
|
304
|
+
(_c = (_g = this.queryLayers.pretty).where) !== null && _c !== void 0 ? _c : (_g.where = []);
|
|
305
|
+
this.queryLayers.pretty.where.push({
|
|
306
|
+
column: alias,
|
|
307
|
+
operator: '>=',
|
|
308
|
+
value: minimumRelevance || 1,
|
|
263
309
|
});
|
|
310
|
+
(_d = (_h = this.queryLayers.pretty).select) !== null && _d !== void 0 ? _d : (_h.select = []);
|
|
311
|
+
this.queryLayers.pretty.select.push(alias);
|
|
264
312
|
return this;
|
|
265
313
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
314
|
+
JsonAggregate(params) {
|
|
315
|
+
var _a, _b, _c, _d, _e;
|
|
316
|
+
var _f, _g, _h, _j, _k;
|
|
317
|
+
const { table, columns, groupByColumns = [], alias = table, nested, having, } = params;
|
|
318
|
+
const expression = {
|
|
319
|
+
type: 'jsonAggregate',
|
|
320
|
+
requirements: {
|
|
321
|
+
phase: QueryEvaluationPhase.PROJECTION,
|
|
322
|
+
cardinality: 'row',
|
|
323
|
+
requiresAlias: true,
|
|
324
|
+
requiresSelectWrapping: true,
|
|
325
|
+
},
|
|
326
|
+
parameters: {
|
|
327
|
+
columns: columns,
|
|
328
|
+
table: table,
|
|
329
|
+
groupByColumns: groupByColumns,
|
|
330
|
+
alias: alias,
|
|
331
|
+
nested: nested,
|
|
332
|
+
having: having,
|
|
333
|
+
},
|
|
334
|
+
};
|
|
335
|
+
(_a = (_f = this.queryLayers.base).expressionsSelect) !== null && _a !== void 0 ? _a : (_f.expressionsSelect = []);
|
|
336
|
+
const selectAliases = this.collectSelectAliases({
|
|
337
|
+
table,
|
|
338
|
+
columns,
|
|
339
|
+
nested: nested || [],
|
|
281
340
|
});
|
|
341
|
+
this.queryLayers.base.expressionsSelect.push(...selectAliases);
|
|
342
|
+
(_b = (_g = this.queryLayers).pretty) !== null && _b !== void 0 ? _b : (_g.pretty = {});
|
|
343
|
+
(_c = (_h = this.queryLayers.pretty).expressions) !== null && _c !== void 0 ? _c : (_h.expressions = []);
|
|
344
|
+
this.queryLayers.pretty.expressions.push(expression);
|
|
345
|
+
(_d = (_j = this.queryLayers).final) !== null && _d !== void 0 ? _d : (_j.final = {});
|
|
346
|
+
(_e = (_k = this.queryLayers.final).blacklistTables) !== null && _e !== void 0 ? _e : (_k.blacklistTables = []);
|
|
347
|
+
this.queryLayers.final.blacklistTables.push(...Array.from(new Set(this.collectTables({ table, nested: nested || [] }))));
|
|
282
348
|
return this;
|
|
283
349
|
}
|
|
284
|
-
|
|
350
|
+
toSql() {
|
|
285
351
|
return __awaiter(this, void 0, void 0, function* () {
|
|
286
|
-
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
const normalizedScopes = this.normalizeQueryScopes(queryScopes, tableName);
|
|
290
|
-
this.joinedEntities.push({
|
|
291
|
-
relation: relation,
|
|
292
|
-
queryScopes: normalizedScopes
|
|
293
|
-
});
|
|
294
|
-
return this;
|
|
352
|
+
var _a;
|
|
353
|
+
const sql = yield ((_a = this.repository) === null || _a === void 0 ? void 0 : _a.toSql(Object.assign(Object.assign({}, this.queryLayers), { base: Object.assign(Object.assign({}, this.queryLayers.base), { from: this.Configuration.table }) }), this));
|
|
354
|
+
return sql === null || sql === void 0 ? void 0 : sql.replace(/\s+/g, ' ').replace(/\n/g, '');
|
|
295
355
|
});
|
|
296
356
|
}
|
|
297
|
-
|
|
298
|
-
const
|
|
299
|
-
if (
|
|
300
|
-
|
|
357
|
+
collectSelectAliases(def) {
|
|
358
|
+
const columnAliases = def.columns.map(col => `${def.table}.${col} AS ${def.table}_${col}`);
|
|
359
|
+
if (def.nested) {
|
|
360
|
+
for (const child of def.nested) {
|
|
361
|
+
columnAliases.push(...this.collectSelectAliases(child));
|
|
362
|
+
}
|
|
301
363
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
364
|
+
return columnAliases;
|
|
365
|
+
}
|
|
366
|
+
collectTables(def) {
|
|
367
|
+
const result = [def.table];
|
|
368
|
+
if (def.nested) {
|
|
369
|
+
for (const child of def.nested) {
|
|
370
|
+
result.push(...this.collectTables(child));
|
|
371
|
+
}
|
|
310
372
|
}
|
|
311
|
-
|
|
312
|
-
'column' in queryScopes &&
|
|
313
|
-
'operator' in queryScopes &&
|
|
314
|
-
'value' in queryScopes;
|
|
315
|
-
const scopesArray = isSingleParameter
|
|
316
|
-
? [queryScopes]
|
|
317
|
-
: this.repository.ConvertParamsToArray(queryScopes);
|
|
318
|
-
return scopesArray.map(scope => (Object.assign(Object.assign({}, scope), { column: `${tableName}.${scope.column}` })));
|
|
373
|
+
return result;
|
|
319
374
|
}
|
|
320
375
|
toJSON() {
|
|
321
376
|
return this.attributes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaTableBuilder.d.ts","sourceRoot":"","sources":["../../src/abstract/SchemaTableBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"SchemaTableBuilder.d.ts","sourceRoot":"","sources":["../../src/abstract/SchemaTableBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE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AC,IAAI,EAAE,MAAM,GAAG,IAAI;IACjC,QAAQ,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IACtC,QAAQ,CAAC,UAAU,IAAI,IAAI;IAE3B,QAAQ,CAAC,WAAW,IAAI,IAAI;IAC5B,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CACtC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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 default abstract class ModelRelations<Type extends columnType, Self extends Model<Type> = Model<Type>> {
|
|
5
|
+
protected joinedEntities: joinedEntity[];
|
|
6
|
+
protected relations: relation[];
|
|
7
|
+
abstract get Configuration(): ModelConfig;
|
|
8
|
+
protected abstract get repository(): Repository<Type, Self>;
|
|
9
|
+
protected abstract get self(): Self;
|
|
10
|
+
get JoinedEntities(): joinedEntity[];
|
|
11
|
+
get Relations(): relation[];
|
|
12
|
+
insertRecordIntoPivotTable(otherTable: string, foreignKey: string): Promise<void>;
|
|
13
|
+
protected ManyToMany<modelType extends Model<columnType>>(model: modelType, pivotTable?: string, localKey?: string, foreignKey?: string, pivotForeignKey?: string, pivotLocalKey?: string): Promise<this>;
|
|
14
|
+
protected hasMany<modelType extends Model<columnType>>(model: modelType, foreignKey?: string, localKey?: string): this;
|
|
15
|
+
protected hasOne<modelType extends Model<columnType>>(model: modelType, foreignKey?: string, localKey?: string): this;
|
|
16
|
+
protected belongsTo<modelType extends Model<columnType>>(model: modelType, foreignKey?: string, localKey?: string): this;
|
|
17
|
+
static with<ParameterModelType extends Model<columnType>>(this: new () => ParameterModelType, relation: string, queryScopes?: QueryWhereCondition): ParameterModelType;
|
|
18
|
+
with(relation: string, queryScopes?: QueryWhereCondition): this;
|
|
19
|
+
asyncWith(relation: string, queryScopes?: QueryWhereCondition): Promise<this>;
|
|
20
|
+
callRelationMethod(relation: string): void | Promise<void>;
|
|
21
|
+
private normalizeQueryScopes;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=ModelRelation.d.ts.map
|