@travetto/model-sql 3.1.3 → 3.1.4
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/package.json +3 -3
- package/src/service.ts +17 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-sql",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.4",
|
|
4
4
|
"description": "SQL backing for the travetto model module, with real-time modeling support for SQL schemas.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sql",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@travetto/config": "^3.1.2",
|
|
31
31
|
"@travetto/context": "^3.1.1",
|
|
32
|
-
"@travetto/model": "^3.1.
|
|
33
|
-
"@travetto/model-query": "^3.1.
|
|
32
|
+
"@travetto/model": "^3.1.6",
|
|
33
|
+
"@travetto/model-query": "^3.1.4"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"@travetto/command": "^3.1.1",
|
package/src/service.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { AsyncContext } from '@travetto/context';
|
|
|
10
10
|
import { Injectable } from '@travetto/di';
|
|
11
11
|
import {
|
|
12
12
|
ModelQuery, ModelQueryCrudSupport, ModelQueryFacetSupport, ModelQuerySupport,
|
|
13
|
-
PageableModelQuery, ValidStringFields, WhereClauseRaw,
|
|
13
|
+
PageableModelQuery, ValidStringFields, WhereClause, WhereClauseRaw,
|
|
14
14
|
} from '@travetto/model-query';
|
|
15
15
|
|
|
16
16
|
import { ModelQueryUtil } from '@travetto/model-query/src/internal/service/query';
|
|
@@ -94,8 +94,10 @@ export class SQLModelService implements
|
|
|
94
94
|
return this.#dialect.executeSQL<T>(sql);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
async #deleteRaw<T extends ModelType>(cls: Class<T>, id: string, checkExpiry = true): Promise<void> {
|
|
98
|
-
|
|
97
|
+
async #deleteRaw<T extends ModelType>(cls: Class<T>, id: string, where?: WhereClauseRaw<T>, checkExpiry = true): Promise<void> {
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
99
|
+
((where ??= {}) as WhereClauseRaw<ModelType>).id = id;
|
|
100
|
+
|
|
99
101
|
const count = await this.#dialect.deleteAndGetCount<ModelType>(cls, {
|
|
100
102
|
where: ModelQueryUtil.getWhereClause(cls, where, checkExpiry)
|
|
101
103
|
});
|
|
@@ -162,7 +164,7 @@ export class SQLModelService implements
|
|
|
162
164
|
|
|
163
165
|
@Transactional()
|
|
164
166
|
async update<T extends ModelType>(cls: Class<T>, item: T): Promise<T> {
|
|
165
|
-
await this.#deleteRaw(cls, item.id, true);
|
|
167
|
+
await this.#deleteRaw(cls, item.id, {}, true);
|
|
166
168
|
return await this.create(cls, item);
|
|
167
169
|
}
|
|
168
170
|
|
|
@@ -170,7 +172,7 @@ export class SQLModelService implements
|
|
|
170
172
|
async upsert<T extends ModelType>(cls: Class<T>, item: OptionalId<T>): Promise<T> {
|
|
171
173
|
try {
|
|
172
174
|
if (item.id) {
|
|
173
|
-
await this.#deleteRaw(cls, item.id, false);
|
|
175
|
+
await this.#deleteRaw(cls, item.id, {}, false);
|
|
174
176
|
}
|
|
175
177
|
} catch (err) {
|
|
176
178
|
if (!(err instanceof NotFoundError)) {
|
|
@@ -206,7 +208,7 @@ export class SQLModelService implements
|
|
|
206
208
|
|
|
207
209
|
@Transactional()
|
|
208
210
|
async delete<T extends ModelType>(cls: Class<T>, id: string): Promise<void> {
|
|
209
|
-
await this.#deleteRaw(cls, id, false);
|
|
211
|
+
await this.#deleteRaw(cls, id, {}, false);
|
|
210
212
|
}
|
|
211
213
|
|
|
212
214
|
@Transactional()
|
|
@@ -268,6 +270,15 @@ export class SQLModelService implements
|
|
|
268
270
|
return +records[0].total;
|
|
269
271
|
}
|
|
270
272
|
|
|
273
|
+
@Connected()
|
|
274
|
+
@Transactional()
|
|
275
|
+
async updateOneWithQuery<T extends ModelType>(cls: Class<T>, item: T, query: ModelQuery<T>): Promise<T> {
|
|
276
|
+
query = ModelQueryUtil.getQueryWithId(cls, item, query);
|
|
277
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
278
|
+
await this.#deleteRaw(cls, item.id, query.where as WhereClause<T>, true);
|
|
279
|
+
return await this.create(cls, item);
|
|
280
|
+
}
|
|
281
|
+
|
|
271
282
|
@Connected()
|
|
272
283
|
@Transactional()
|
|
273
284
|
async updateByQuery<T extends ModelType>(cls: Class<T>, query: ModelQuery<T>, data: Partial<T>): Promise<number> {
|