@spinajs/orm 1.2.75 → 1.2.81
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/lib/builders.d.ts +131 -32
- package/lib/builders.js +320 -101
- package/lib/builders.js.map +1 -1
- package/lib/dehydrators.d.ts +7 -0
- package/lib/dehydrators.js +31 -0
- package/lib/dehydrators.js.map +1 -0
- package/lib/driver.d.ts +5 -1
- package/lib/driver.js +11 -0
- package/lib/driver.js.map +1 -1
- package/lib/enums.d.ts +4 -1
- package/lib/enums.js +19 -17
- package/lib/enums.js.map +1 -1
- package/lib/index.d.ts +3 -0
- package/lib/index.js +8 -1
- package/lib/index.js.map +1 -1
- package/lib/interfaces.d.ts +70 -16
- package/lib/interfaces.js +50 -7
- package/lib/interfaces.js.map +1 -1
- package/lib/model.d.ts +72 -8
- package/lib/model.js +304 -79
- package/lib/model.js.map +1 -1
- package/lib/orm.js +27 -4
- package/lib/orm.js.map +1 -1
- package/lib/relations.d.ts +1 -1
- package/lib/relations.js +34 -11
- package/lib/relations.js.map +1 -1
- package/lib/statements.d.ts +3 -3
- package/lib/statements.js +24 -1
- package/lib/statements.js.map +1 -1
- package/package.json +8 -8
package/lib/interfaces.js
CHANGED
|
@@ -6,7 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.SetValueConverter = exports.DatetimeValueConverter = exports.ValueConverter = exports.GroupByQueryCompiler = exports.OrderByQueryCompiler = exports.ColumnQueryCompiler = exports.TableExistsCompiler = exports.TableQueryCompiler = exports.OnDuplicateQueryCompiler = exports.InsertQueryCompiler = exports.UpdateQueryCompiler = exports.DeleteQueryCompiler = exports.ForeignKeyQueryCompiler = exports.IndexQueryCompiler = exports.JoinQueryCompiler = exports.SelectQueryCompiler = exports.RecursiveQueryCompiler = exports.OrmMigration = exports.RelationType = exports.MigrationTransactionMode = exports.ReferentialAction = exports.InsertBehaviour = exports.QueryContext = void 0;
|
|
9
|
+
exports.TableAliasCompiler = exports.SetValueConverter = exports.DatetimeValueConverter = exports.ValueConverter = exports.GroupByQueryCompiler = exports.OrderByQueryCompiler = exports.AlterColumnQueryCompiler = exports.ColumnQueryCompiler = exports.TableExistsCompiler = exports.AlterTableQueryCompiler = exports.TableCloneQueryCompiler = exports.TruncateTableQueryCompiler = exports.TableQueryCompiler = exports.OnDuplicateQueryCompiler = exports.InsertQueryCompiler = exports.UpdateQueryCompiler = exports.DeleteQueryCompiler = exports.ForeignKeyQueryCompiler = exports.LimitQueryCompiler = exports.IndexQueryCompiler = exports.JoinQueryCompiler = exports.SelectQueryCompiler = exports.RecursiveQueryCompiler = exports.OrmMigration = exports.RelationType = exports.MigrationTransactionMode = exports.ReferentialAction = exports.InsertBehaviour = exports.ColumnAlterationType = exports.QueryContext = void 0;
|
|
10
10
|
const di_1 = require("@spinajs/di");
|
|
11
11
|
const exceptions_1 = require("@spinajs/exceptions");
|
|
12
12
|
var QueryContext;
|
|
@@ -18,20 +18,27 @@ var QueryContext;
|
|
|
18
18
|
QueryContext[QueryContext["Schema"] = 4] = "Schema";
|
|
19
19
|
QueryContext[QueryContext["Transaction"] = 5] = "Transaction";
|
|
20
20
|
})(QueryContext = exports.QueryContext || (exports.QueryContext = {}));
|
|
21
|
+
var ColumnAlterationType;
|
|
22
|
+
(function (ColumnAlterationType) {
|
|
23
|
+
ColumnAlterationType[ColumnAlterationType["Add"] = 0] = "Add";
|
|
24
|
+
ColumnAlterationType[ColumnAlterationType["Modify"] = 1] = "Modify";
|
|
25
|
+
ColumnAlterationType[ColumnAlterationType["Rename"] = 2] = "Rename";
|
|
26
|
+
})(ColumnAlterationType = exports.ColumnAlterationType || (exports.ColumnAlterationType = {}));
|
|
21
27
|
var InsertBehaviour;
|
|
22
28
|
(function (InsertBehaviour) {
|
|
23
29
|
/**
|
|
24
|
-
*
|
|
30
|
+
* Ignores if primary key exists in db
|
|
25
31
|
*/
|
|
26
|
-
InsertBehaviour[InsertBehaviour["
|
|
32
|
+
InsertBehaviour[InsertBehaviour["InsertOrIgnore"] = 0] = "InsertOrIgnore";
|
|
27
33
|
/**
|
|
28
|
-
*
|
|
34
|
+
* Updates entry if pk exists
|
|
29
35
|
*/
|
|
30
|
-
InsertBehaviour[InsertBehaviour["
|
|
36
|
+
InsertBehaviour[InsertBehaviour["InsertOrUpdate"] = 1] = "InsertOrUpdate";
|
|
31
37
|
/**
|
|
32
|
-
*
|
|
38
|
+
* Replaces entry if pk exists
|
|
33
39
|
*/
|
|
34
|
-
InsertBehaviour[InsertBehaviour["
|
|
40
|
+
InsertBehaviour[InsertBehaviour["InsertOrReplace"] = 2] = "InsertOrReplace";
|
|
41
|
+
InsertBehaviour[InsertBehaviour["None"] = 3] = "None";
|
|
35
42
|
})(InsertBehaviour = exports.InsertBehaviour || (exports.InsertBehaviour = {}));
|
|
36
43
|
/**
|
|
37
44
|
* Foreign key referential actions
|
|
@@ -98,6 +105,12 @@ IndexQueryCompiler = __decorate([
|
|
|
98
105
|
(0, di_1.NewInstance)()
|
|
99
106
|
], IndexQueryCompiler);
|
|
100
107
|
exports.IndexQueryCompiler = IndexQueryCompiler;
|
|
108
|
+
let LimitQueryCompiler = class LimitQueryCompiler {
|
|
109
|
+
};
|
|
110
|
+
LimitQueryCompiler = __decorate([
|
|
111
|
+
(0, di_1.NewInstance)()
|
|
112
|
+
], LimitQueryCompiler);
|
|
113
|
+
exports.LimitQueryCompiler = LimitQueryCompiler;
|
|
101
114
|
let ForeignKeyQueryCompiler = class ForeignKeyQueryCompiler {
|
|
102
115
|
};
|
|
103
116
|
ForeignKeyQueryCompiler = __decorate([
|
|
@@ -134,6 +147,24 @@ TableQueryCompiler = __decorate([
|
|
|
134
147
|
(0, di_1.NewInstance)()
|
|
135
148
|
], TableQueryCompiler);
|
|
136
149
|
exports.TableQueryCompiler = TableQueryCompiler;
|
|
150
|
+
let TruncateTableQueryCompiler = class TruncateTableQueryCompiler {
|
|
151
|
+
};
|
|
152
|
+
TruncateTableQueryCompiler = __decorate([
|
|
153
|
+
(0, di_1.NewInstance)()
|
|
154
|
+
], TruncateTableQueryCompiler);
|
|
155
|
+
exports.TruncateTableQueryCompiler = TruncateTableQueryCompiler;
|
|
156
|
+
let TableCloneQueryCompiler = class TableCloneQueryCompiler {
|
|
157
|
+
};
|
|
158
|
+
TableCloneQueryCompiler = __decorate([
|
|
159
|
+
(0, di_1.NewInstance)()
|
|
160
|
+
], TableCloneQueryCompiler);
|
|
161
|
+
exports.TableCloneQueryCompiler = TableCloneQueryCompiler;
|
|
162
|
+
let AlterTableQueryCompiler = class AlterTableQueryCompiler {
|
|
163
|
+
};
|
|
164
|
+
AlterTableQueryCompiler = __decorate([
|
|
165
|
+
(0, di_1.NewInstance)()
|
|
166
|
+
], AlterTableQueryCompiler);
|
|
167
|
+
exports.AlterTableQueryCompiler = AlterTableQueryCompiler;
|
|
137
168
|
let TableExistsCompiler = class TableExistsCompiler {
|
|
138
169
|
};
|
|
139
170
|
TableExistsCompiler = __decorate([
|
|
@@ -146,6 +177,12 @@ ColumnQueryCompiler = __decorate([
|
|
|
146
177
|
(0, di_1.NewInstance)()
|
|
147
178
|
], ColumnQueryCompiler);
|
|
148
179
|
exports.ColumnQueryCompiler = ColumnQueryCompiler;
|
|
180
|
+
let AlterColumnQueryCompiler = class AlterColumnQueryCompiler {
|
|
181
|
+
};
|
|
182
|
+
AlterColumnQueryCompiler = __decorate([
|
|
183
|
+
(0, di_1.NewInstance)()
|
|
184
|
+
], AlterColumnQueryCompiler);
|
|
185
|
+
exports.AlterColumnQueryCompiler = AlterColumnQueryCompiler;
|
|
149
186
|
let OrderByQueryCompiler = class OrderByQueryCompiler {
|
|
150
187
|
};
|
|
151
188
|
OrderByQueryCompiler = __decorate([
|
|
@@ -189,4 +226,10 @@ exports.DatetimeValueConverter = DatetimeValueConverter;
|
|
|
189
226
|
class SetValueConverter extends ValueConverter {
|
|
190
227
|
}
|
|
191
228
|
exports.SetValueConverter = SetValueConverter;
|
|
229
|
+
let TableAliasCompiler = class TableAliasCompiler {
|
|
230
|
+
};
|
|
231
|
+
TableAliasCompiler = __decorate([
|
|
232
|
+
(0, di_1.Singleton)()
|
|
233
|
+
], TableAliasCompiler);
|
|
234
|
+
exports.TableAliasCompiler = TableAliasCompiler;
|
|
192
235
|
//# sourceMappingURL=interfaces.js.map
|
package/lib/interfaces.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";;;;;;;;;AAOA,oCAA8E;AAE9E,oDAA2D;AAE3D,IAAY,YAOX;AAPD,WAAY,YAAY;IACtB,mDAAM,CAAA;IACN,mDAAM,CAAA;IACN,mDAAM,CAAA;IACN,mDAAM,CAAA;IACN,mDAAM,CAAA;IACN,6DAAW,CAAA;AACb,CAAC,EAPW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAOvB;AAED,IAAY,oBAIX;AAJD,WAAY,oBAAoB;IAC9B,6DAAG,CAAA;IACH,mEAAM,CAAA;IACN,mEAAM,CAAA;AACR,CAAC,EAJW,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAI/B;AAED,IAAY,eAiBX;AAjBD,WAAY,eAAe;IACzB;;OAEG;IACH,yEAAc,CAAA;IAEd;;OAEG;IACH,yEAAc,CAAA;IAEd;;OAEG;IACH,2EAAe,CAAA;IAEf,qDAAI,CAAA;AACN,CAAC,EAjBW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAiB1B;AAED;;GAEG;AACH,IAAY,iBAMX;AAND,WAAY,iBAAiB;IAC3B,wCAAmB,CAAA;IACnB,yCAAoB,CAAA;IACpB,0CAAqB,CAAA;I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-1,14 +1,22 @@
|
|
|
1
|
-
import { IModelDescrtiptor, InsertBehaviour } from './interfaces';
|
|
1
|
+
import { IModelDescrtiptor, InsertBehaviour, IUpdateResult, IWhereBuilder } from './interfaces';
|
|
2
2
|
import { WhereFunction } from './types';
|
|
3
3
|
import { RawQuery, UpdateQueryBuilder, SelectQueryBuilder, InsertQueryBuilder } from './builders';
|
|
4
|
-
import {
|
|
4
|
+
import { Op } from './enums';
|
|
5
|
+
import { IContainer } from '@spinajs/di';
|
|
6
|
+
import { WrapStatement } from './statements';
|
|
5
7
|
export declare function extractModelDescriptor(targetOrForward: any): IModelDescrtiptor;
|
|
6
8
|
export declare class ModelBase {
|
|
9
|
+
private _descriptor;
|
|
10
|
+
private _container;
|
|
7
11
|
/**
|
|
8
12
|
* Gets descriptor for this model. It contains information about relations, orm driver, connection properties,
|
|
9
13
|
* db table attached, column information and others.
|
|
10
14
|
*/
|
|
11
15
|
get ModelDescriptor(): IModelDescrtiptor;
|
|
16
|
+
/**
|
|
17
|
+
* Gets di container associated with this model ( via connection object eg. different drivers have their own implementation of things)
|
|
18
|
+
*/
|
|
19
|
+
get Container(): IContainer;
|
|
12
20
|
get PrimaryKeyName(): string;
|
|
13
21
|
get PrimaryKeyValue(): any;
|
|
14
22
|
set PrimaryKeyValue(newVal: any);
|
|
@@ -21,7 +29,7 @@ export declare class ModelBase {
|
|
|
21
29
|
*
|
|
22
30
|
* @param _data - data to insert
|
|
23
31
|
*/
|
|
24
|
-
static insert<T extends typeof ModelBase>(this: T, _data: InstanceType<T> | Partial<InstanceType<T>> | Array<InstanceType<T>> | Array<Partial<InstanceType<T
|
|
32
|
+
static insert<T extends typeof ModelBase>(this: T, _data: InstanceType<T> | Partial<InstanceType<T>> | Array<InstanceType<T>> | Array<Partial<InstanceType<T>>>, _insertBehaviour?: InsertBehaviour): InsertQueryBuilder;
|
|
25
33
|
/**
|
|
26
34
|
* Search entities in db
|
|
27
35
|
*
|
|
@@ -29,7 +37,13 @@ export declare class ModelBase {
|
|
|
29
37
|
* @param operator - boolean operator
|
|
30
38
|
* @param value - value to compare
|
|
31
39
|
*/
|
|
32
|
-
static where<T extends typeof ModelBase>(this: T,
|
|
40
|
+
static where<T extends typeof ModelBase>(this: T, val: boolean): SelectQueryBuilder<Array<InstanceType<T>>>;
|
|
41
|
+
static where<T extends typeof ModelBase>(this: T, val: {}): SelectQueryBuilder<Array<InstanceType<T>>>;
|
|
42
|
+
static where<T extends typeof ModelBase>(this: T, func: WhereFunction): SelectQueryBuilder<Array<InstanceType<T>>>;
|
|
43
|
+
static where<T extends typeof ModelBase>(this: T, column: string, operator: Op, value: any): SelectQueryBuilder<Array<InstanceType<T>>>;
|
|
44
|
+
static where<T extends typeof ModelBase>(this: T, column: string, value: any): SelectQueryBuilder<Array<InstanceType<T>>>;
|
|
45
|
+
static where<T extends typeof ModelBase>(this: T, statement: WrapStatement): SelectQueryBuilder<Array<InstanceType<T>>>;
|
|
46
|
+
static where<T extends typeof ModelBase>(this: T, column: string | boolean | WhereFunction | RawQuery | {}, operator?: Op | any, value?: any): SelectQueryBuilder<Array<InstanceType<T>>>;
|
|
33
47
|
/**
|
|
34
48
|
* Updates single or multiple records at once with provided value based on condition
|
|
35
49
|
*
|
|
@@ -40,6 +54,30 @@ export declare class ModelBase {
|
|
|
40
54
|
* Tries to find all models with given primary keys
|
|
41
55
|
*/
|
|
42
56
|
static find<T extends typeof ModelBase>(this: T, _pks: any[]): Promise<Array<InstanceType<T>>>;
|
|
57
|
+
/**
|
|
58
|
+
* Tries to get first result from db
|
|
59
|
+
*
|
|
60
|
+
* Orders by Primary key, if pk not exists then by unique constraints and lastly by CreateAt if no unique columns exists.
|
|
61
|
+
*/
|
|
62
|
+
static first<T extends typeof ModelBase>(this: T, callback?: (builder: IWhereBuilder) => void): Promise<number>;
|
|
63
|
+
/**
|
|
64
|
+
* Tries to get first result from db
|
|
65
|
+
*
|
|
66
|
+
* Orders by Primary key, if pk not exists then by unique constraints and lastly by CreateAt if no unique columns exists.
|
|
67
|
+
*/
|
|
68
|
+
static last<T extends typeof ModelBase>(this: T, callback?: (builder: IWhereBuilder) => void): Promise<InstanceType<T>>;
|
|
69
|
+
/**
|
|
70
|
+
* Tries to get newest result from db. It throws if model dont have CreatedAt decorated property
|
|
71
|
+
*/
|
|
72
|
+
static newest<T extends typeof ModelBase>(this: T, callback?: (builder: IWhereBuilder) => void): Promise<InstanceType<T>>;
|
|
73
|
+
/**
|
|
74
|
+
* Tries to get oldest result from db. It throws if model dont have CreatedAt decorated property
|
|
75
|
+
*/
|
|
76
|
+
static oldest<T extends typeof ModelBase>(this: T, callback?: (builder: IWhereBuilder) => void): Promise<InstanceType<T>>;
|
|
77
|
+
/**
|
|
78
|
+
* Returns total count of entries in db for this model
|
|
79
|
+
*/
|
|
80
|
+
static count<T extends typeof ModelBase>(this: T, callback?: (builder: IWhereBuilder) => void): Promise<InstanceType<T>>;
|
|
43
81
|
/**
|
|
44
82
|
* Tries to find all models in db. If not all exists, throws exception
|
|
45
83
|
*/
|
|
@@ -92,6 +130,13 @@ export declare class ModelBase {
|
|
|
92
130
|
* @param data - data to fill
|
|
93
131
|
*/
|
|
94
132
|
hydrate(data: Partial<this>): void;
|
|
133
|
+
/**
|
|
134
|
+
*
|
|
135
|
+
* Attachess model to proper relation an sets foreign key
|
|
136
|
+
*
|
|
137
|
+
* @param data - model to attach
|
|
138
|
+
*/
|
|
139
|
+
attach(data: ModelBase): void;
|
|
95
140
|
/**
|
|
96
141
|
* Extracts all data from model. It takes only properties that exists in DB
|
|
97
142
|
*/
|
|
@@ -100,16 +145,30 @@ export declare class ModelBase {
|
|
|
100
145
|
* deletes enitt from db. If model have SoftDelete decorator, model is marked as deleted
|
|
101
146
|
*/
|
|
102
147
|
destroy(): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* If model can be in achived state - sets archived at date and saves it to db
|
|
150
|
+
*/
|
|
151
|
+
archive(): Promise<void>;
|
|
103
152
|
update(): Promise<void>;
|
|
104
153
|
/**
|
|
105
154
|
* Save all changes to db. It creates new entry id db or updates existing one if
|
|
106
155
|
* primary key exists
|
|
107
156
|
*/
|
|
108
|
-
insert(insertBehaviour?: InsertBehaviour): Promise<
|
|
157
|
+
insert(insertBehaviour?: InsertBehaviour): Promise<IUpdateResult>;
|
|
109
158
|
/**
|
|
110
159
|
* Gets model data from database and returns as fresh instance.
|
|
160
|
+
*
|
|
161
|
+
* If primary key is not fetched, tries to load by columns with unique constraint.
|
|
162
|
+
* If there is no unique columns or primary key, throws error
|
|
111
163
|
*/
|
|
112
164
|
fresh(): Promise<this>;
|
|
165
|
+
/**
|
|
166
|
+
* Refresh model from database.
|
|
167
|
+
*
|
|
168
|
+
* If no primary key is set, tries to fetch data base on columns
|
|
169
|
+
* with unique constraints. If none exists, throws exception
|
|
170
|
+
*/
|
|
171
|
+
refresh(): Promise<void>;
|
|
113
172
|
/**
|
|
114
173
|
* sets default values for model. values are taken from DB default column prop
|
|
115
174
|
*/
|
|
@@ -117,13 +176,13 @@ export declare class ModelBase {
|
|
|
117
176
|
}
|
|
118
177
|
export declare const MODEL_STATIC_MIXINS: {
|
|
119
178
|
query(): SelectQueryBuilder;
|
|
120
|
-
where(column: string | boolean | WhereFunction | RawQuery | {}, operator?:
|
|
179
|
+
where(column: string | boolean | WhereFunction | RawQuery | {}, operator?: Op | any, value?: any): SelectQueryBuilder;
|
|
121
180
|
update<T extends typeof ModelBase>(data: Partial<InstanceType<T>>): UpdateQueryBuilder;
|
|
122
|
-
all(page
|
|
181
|
+
all(page?: number, perPage?: number): SelectQueryBuilder<unknown>;
|
|
123
182
|
/**
|
|
124
183
|
* Try to insert new value
|
|
125
184
|
*/
|
|
126
|
-
insert<T_1 extends typeof ModelBase>(this: T_1, data: InstanceType<T_1> | Partial<InstanceType<T_1>> | InstanceType<T_1>[] | Partial<InstanceType<T_1>>[]):
|
|
185
|
+
insert<T_1 extends typeof ModelBase>(this: T_1, data: InstanceType<T_1> | Partial<InstanceType<T_1>> | InstanceType<T_1>[] | Partial<InstanceType<T_1>>[], insertBehaviour?: InsertBehaviour): Promise<IUpdateResult>;
|
|
127
186
|
find<T_2 extends typeof ModelBase>(this: T_2, pks: any[]): Promise<InstanceType<T_2>[]>;
|
|
128
187
|
findOrFail<T_3 extends typeof ModelBase>(this: T_3, pks: any[]): Promise<InstanceType<T_3>[]>;
|
|
129
188
|
get<T_4 extends typeof ModelBase>(this: T_4, pk: any): Promise<InstanceType<T_4>>;
|
|
@@ -132,4 +191,9 @@ export declare const MODEL_STATIC_MIXINS: {
|
|
|
132
191
|
create<T_6 extends typeof ModelBase>(this: T_6, data: Partial<InstanceType<T_6>>): Promise<InstanceType<T_6>>;
|
|
133
192
|
getOrCreate<T_7 extends typeof ModelBase>(this: T_7, pk: any, data: Partial<InstanceType<T_7>>): Promise<InstanceType<T_7>>;
|
|
134
193
|
getOrNew<T_8 extends typeof ModelBase>(this: T_8, pk: any, data?: Partial<InstanceType<T_8>>): Promise<InstanceType<T_8>>;
|
|
194
|
+
first<T_9 extends typeof ModelBase>(this: T_9, callback?: (builder: IWhereBuilder) => void): Promise<InstanceType<T_9>>;
|
|
195
|
+
last<T_10 extends typeof ModelBase>(this: T_10, callback?: (builder: IWhereBuilder) => void): Promise<InstanceType<T_10>>;
|
|
196
|
+
newest<T_11 extends typeof ModelBase>(this: T_11, callback?: (builder: IWhereBuilder) => void): Promise<InstanceType<T_11>>;
|
|
197
|
+
oldest<T_12 extends typeof ModelBase>(this: T_12, callback?: (builder: IWhereBuilder) => void): Promise<InstanceType<T_12>>;
|
|
198
|
+
count<T_13 extends typeof ModelBase>(this: T_13, callback?: (builder: IWhereBuilder) => void): Promise<number>;
|
|
135
199
|
};
|