@entity-access/entity-access 1.0.307 → 1.0.309
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/common/symbols/symbols.d.ts +1 -0
- package/dist/common/symbols/symbols.d.ts.map +1 -1
- package/dist/common/symbols/symbols.js +1 -0
- package/dist/common/symbols/symbols.js.map +1 -1
- package/dist/drivers/base/BaseDriver.d.ts +6 -0
- package/dist/drivers/base/BaseDriver.d.ts.map +1 -1
- package/dist/drivers/base/BaseDriver.js +25 -3
- package/dist/drivers/base/BaseDriver.js.map +1 -1
- package/dist/drivers/postgres/PostgreSqlDriver.js +6 -0
- package/dist/drivers/postgres/PostgreSqlDriver.js.map +1 -1
- package/dist/drivers/sql-server/SqlServerDriver.d.ts.map +1 -1
- package/dist/drivers/sql-server/SqlServerDriver.js +12 -5
- package/dist/drivers/sql-server/SqlServerDriver.js.map +1 -1
- package/dist/model/EntityContext.d.ts.map +1 -1
- package/dist/model/EntityContext.js +4 -0
- package/dist/model/EntityContext.js.map +1 -1
- package/dist/model/EntitySource.d.ts.map +1 -1
- package/dist/model/EntitySource.js +11 -1
- package/dist/model/EntitySource.js.map +1 -1
- package/dist/tests/db-tests/transaction-save-point/transaction-save-point.d.ts +3 -0
- package/dist/tests/db-tests/transaction-save-point/transaction-save-point.d.ts.map +1 -0
- package/dist/tests/db-tests/transaction-save-point/transaction-save-point.js +58 -0
- package/dist/tests/db-tests/transaction-save-point/transaction-save-point.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/common/symbols/symbols.ts +1 -0
- package/src/drivers/base/BaseDriver.ts +34 -3
- package/src/drivers/postgres/PostgreSqlDriver.ts +7 -0
- package/src/drivers/sql-server/SqlServerDriver.ts +13 -6
- package/src/model/EntityContext.ts +4 -0
- package/src/model/EntitySource.ts +11 -1
- package/src/tests/db-tests/transaction-save-point/transaction-save-point.ts +48 -0
|
@@ -2,7 +2,7 @@ import type EntityContext from "./EntityContext.js";
|
|
|
2
2
|
import type EntityType from "../entity-query/EntityType.js";
|
|
3
3
|
import type { IBaseQuery, IEntityQuery, IFilterExpression } from "./IFilterWithParameter.js";
|
|
4
4
|
import EntityQuery from "./EntityQuery.js";
|
|
5
|
-
import { contextSymbol, modelSymbol } from "../common/symbols/symbols.js";
|
|
5
|
+
import { contextSymbol, modelSymbol, traceSymbol } from "../common/symbols/symbols.js";
|
|
6
6
|
import { Expression, ExpressionAs, Identifier, InsertStatement, TableLiteral } from "../query/ast/Expressions.js";
|
|
7
7
|
import { DirectSaveType } from "../drivers/base/BaseDriver.js";
|
|
8
8
|
import IdentityService from "./identity/IdentityService.js";
|
|
@@ -140,6 +140,12 @@ export class EntitySource<T = any> {
|
|
|
140
140
|
if (!expression) {
|
|
141
141
|
return changes as any;
|
|
142
142
|
}
|
|
143
|
+
const tx = this.context.connection.currentTransaction;
|
|
144
|
+
let tid: string;
|
|
145
|
+
if (tx) {
|
|
146
|
+
tid = `txp_${Date.now()}`;
|
|
147
|
+
await tx.save(tid);
|
|
148
|
+
}
|
|
143
149
|
try {
|
|
144
150
|
const { text, values } = driver.compiler.compileExpression(null, expression);
|
|
145
151
|
const r = await this.context.connection.executeQuery({ text, values });
|
|
@@ -156,6 +162,9 @@ export class EntitySource<T = any> {
|
|
|
156
162
|
return returnEntity;
|
|
157
163
|
} catch (error) {
|
|
158
164
|
if (retry > 0) {
|
|
165
|
+
if (tid) {
|
|
166
|
+
await tx.rollbackTo(tid);
|
|
167
|
+
}
|
|
159
168
|
await sleep(300);
|
|
160
169
|
return await this.saveDirect({ keys, mode, changes, updateAfterSelect } as any, retry -1);
|
|
161
170
|
}
|
|
@@ -233,6 +242,7 @@ export class EntitySource<T = any> {
|
|
|
233
242
|
selectStatement.model = model;
|
|
234
243
|
return new EntityQuery<T>({
|
|
235
244
|
context,
|
|
245
|
+
trace: context[traceSymbol],
|
|
236
246
|
type: model,
|
|
237
247
|
selectStatement
|
|
238
248
|
}) as any as IEntityQuery<T>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import { Sql } from "../../../index.js";
|
|
3
|
+
import { TestConfig } from "../../TestConfig.js";
|
|
4
|
+
import { createContext } from "../../model/createContext.js";
|
|
5
|
+
import { traceSymbol } from "../../../common/symbols/symbols.js";
|
|
6
|
+
import { ShoppingContext } from "../../model/ShoppingContext.js";
|
|
7
|
+
|
|
8
|
+
export default async function(this: TestConfig) {
|
|
9
|
+
|
|
10
|
+
if (!this.db) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const context = await createContext(this.driver);
|
|
15
|
+
|
|
16
|
+
context[traceSymbol] = console.log;
|
|
17
|
+
|
|
18
|
+
await testSavePoint(context);
|
|
19
|
+
|
|
20
|
+
// SQL SERVER doesn't worry about failed transactions
|
|
21
|
+
// await failSavePoint(context);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function testSavePoint(context: ShoppingContext) {
|
|
25
|
+
await using tx = await context.connection.createTransaction();
|
|
26
|
+
await tx.save("t1");
|
|
27
|
+
|
|
28
|
+
await assert.rejects(async () => {
|
|
29
|
+
const rx = await context.connection.executeQuery("SELECT ADSFDFDFDS FROM A1");
|
|
30
|
+
console.log(rx);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
await tx.rollbackTo("t1");
|
|
34
|
+
const result = await context.connection.executeQuery("SELECT 1 as v1");
|
|
35
|
+
assert.strictEqual(1, result.rows[0].v1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function failSavePoint(context: ShoppingContext) {
|
|
39
|
+
await using tx = await context.connection.createTransaction();
|
|
40
|
+
|
|
41
|
+
await assert.rejects(async () => {
|
|
42
|
+
const rx = await context.connection.executeQuery("SELECT ADSFDFDFDS FROM A1");
|
|
43
|
+
console.log(rx);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
await assert.rejects(async () => await context.connection.executeQuery("SELECT 1 as v1"));
|
|
47
|
+
}
|
|
48
|
+
|