@opra/sqb 1.0.7 → 1.0.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.
|
@@ -7,7 +7,6 @@ const connect_1 = require("@sqb/connect");
|
|
|
7
7
|
const valgen_1 = require("valgen");
|
|
8
8
|
const sqb_adapter_js_1 = require("./sqb-adapter.js");
|
|
9
9
|
const sqb_service_base_js_1 = require("./sqb-service-base.js");
|
|
10
|
-
const transactionKey = Symbol.for('transaction');
|
|
11
10
|
/**
|
|
12
11
|
* @class SqbEntityService
|
|
13
12
|
* @template T - The data type class type of the resource
|
|
@@ -75,54 +74,6 @@ class SqbEntityService extends sqb_service_base_js_1.SqbServiceBase {
|
|
|
75
74
|
}
|
|
76
75
|
return super.for(context, overwriteProperties, overwriteContext);
|
|
77
76
|
}
|
|
78
|
-
/**
|
|
79
|
-
* Executes the provided function within a transaction.
|
|
80
|
-
*
|
|
81
|
-
* @param callback - The function to be executed within the transaction.
|
|
82
|
-
*/
|
|
83
|
-
async withTransaction(callback) {
|
|
84
|
-
const ctx = this.context;
|
|
85
|
-
let closeSessionOnFinish = false;
|
|
86
|
-
let connection = ctx[transactionKey];
|
|
87
|
-
if (!connection) {
|
|
88
|
-
/** Determine the SqbClient or SqbConnection instance */
|
|
89
|
-
const db = await this.getConnection();
|
|
90
|
-
if (db instanceof connect_1.SqbConnection) {
|
|
91
|
-
connection = db;
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
/** Acquire a connection. New connection should be at the end */
|
|
95
|
-
connection = await db.acquire({ autoCommit: false });
|
|
96
|
-
closeSessionOnFinish = true;
|
|
97
|
-
}
|
|
98
|
-
/** Store transaction connection in current context */
|
|
99
|
-
ctx[transactionKey] = connection;
|
|
100
|
-
}
|
|
101
|
-
const oldInTransaction = connection.inTransaction;
|
|
102
|
-
connection.retain();
|
|
103
|
-
try {
|
|
104
|
-
if (!oldInTransaction)
|
|
105
|
-
await connection.startTransaction();
|
|
106
|
-
const out = await callback(connection, this);
|
|
107
|
-
if (!oldInTransaction && connection.inTransaction)
|
|
108
|
-
await connection.commit();
|
|
109
|
-
return out;
|
|
110
|
-
}
|
|
111
|
-
catch (e) {
|
|
112
|
-
if (!oldInTransaction && connection.inTransaction)
|
|
113
|
-
await connection.rollback();
|
|
114
|
-
throw e;
|
|
115
|
-
}
|
|
116
|
-
finally {
|
|
117
|
-
delete ctx[transactionKey];
|
|
118
|
-
/** Release connection */
|
|
119
|
-
if (closeSessionOnFinish) {
|
|
120
|
-
await connection.close();
|
|
121
|
-
}
|
|
122
|
-
else
|
|
123
|
-
connection.release();
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
77
|
/**
|
|
127
78
|
* Retrieves the resource name.
|
|
128
79
|
*
|
|
@@ -512,23 +463,6 @@ class SqbEntityService extends sqb_service_base_js_1.SqbServiceBase {
|
|
|
512
463
|
options.filter = sqb_adapter_js_1.SQBAdapter.parseFilter(options.filter);
|
|
513
464
|
return await repo.updateMany(data, options);
|
|
514
465
|
}
|
|
515
|
-
/**
|
|
516
|
-
* Retrieves the database connection.
|
|
517
|
-
*
|
|
518
|
-
* @protected
|
|
519
|
-
*
|
|
520
|
-
* @throws {Error} If the context or database is not set.
|
|
521
|
-
*/
|
|
522
|
-
getConnection() {
|
|
523
|
-
const ctx = this.context;
|
|
524
|
-
let db = ctx[transactionKey];
|
|
525
|
-
if (db)
|
|
526
|
-
return db;
|
|
527
|
-
db = typeof this.db === 'function' ? this.db(this) : this.db;
|
|
528
|
-
if (db)
|
|
529
|
-
return db;
|
|
530
|
-
throw new Error(`Database not set!`);
|
|
531
|
-
}
|
|
532
466
|
/**
|
|
533
467
|
* Retrieves the common filter used for querying documents.
|
|
534
468
|
* This method is mostly used for security issues like securing multi-tenant applications.
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { InternalServerError } from '@opra/common';
|
|
2
2
|
import { op } from '@sqb/builder';
|
|
3
|
-
import { EntityMetadata
|
|
3
|
+
import { EntityMetadata } from '@sqb/connect';
|
|
4
4
|
import { isNotNullish } from 'valgen';
|
|
5
5
|
import { SQBAdapter } from './sqb-adapter.js';
|
|
6
6
|
import { SqbServiceBase } from './sqb-service-base.js';
|
|
7
|
-
const transactionKey = Symbol.for('transaction');
|
|
8
7
|
/**
|
|
9
8
|
* @class SqbEntityService
|
|
10
9
|
* @template T - The data type class type of the resource
|
|
@@ -72,54 +71,6 @@ export class SqbEntityService extends SqbServiceBase {
|
|
|
72
71
|
}
|
|
73
72
|
return super.for(context, overwriteProperties, overwriteContext);
|
|
74
73
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Executes the provided function within a transaction.
|
|
77
|
-
*
|
|
78
|
-
* @param callback - The function to be executed within the transaction.
|
|
79
|
-
*/
|
|
80
|
-
async withTransaction(callback) {
|
|
81
|
-
const ctx = this.context;
|
|
82
|
-
let closeSessionOnFinish = false;
|
|
83
|
-
let connection = ctx[transactionKey];
|
|
84
|
-
if (!connection) {
|
|
85
|
-
/** Determine the SqbClient or SqbConnection instance */
|
|
86
|
-
const db = await this.getConnection();
|
|
87
|
-
if (db instanceof SqbConnection) {
|
|
88
|
-
connection = db;
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
/** Acquire a connection. New connection should be at the end */
|
|
92
|
-
connection = await db.acquire({ autoCommit: false });
|
|
93
|
-
closeSessionOnFinish = true;
|
|
94
|
-
}
|
|
95
|
-
/** Store transaction connection in current context */
|
|
96
|
-
ctx[transactionKey] = connection;
|
|
97
|
-
}
|
|
98
|
-
const oldInTransaction = connection.inTransaction;
|
|
99
|
-
connection.retain();
|
|
100
|
-
try {
|
|
101
|
-
if (!oldInTransaction)
|
|
102
|
-
await connection.startTransaction();
|
|
103
|
-
const out = await callback(connection, this);
|
|
104
|
-
if (!oldInTransaction && connection.inTransaction)
|
|
105
|
-
await connection.commit();
|
|
106
|
-
return out;
|
|
107
|
-
}
|
|
108
|
-
catch (e) {
|
|
109
|
-
if (!oldInTransaction && connection.inTransaction)
|
|
110
|
-
await connection.rollback();
|
|
111
|
-
throw e;
|
|
112
|
-
}
|
|
113
|
-
finally {
|
|
114
|
-
delete ctx[transactionKey];
|
|
115
|
-
/** Release connection */
|
|
116
|
-
if (closeSessionOnFinish) {
|
|
117
|
-
await connection.close();
|
|
118
|
-
}
|
|
119
|
-
else
|
|
120
|
-
connection.release();
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
74
|
/**
|
|
124
75
|
* Retrieves the resource name.
|
|
125
76
|
*
|
|
@@ -509,23 +460,6 @@ export class SqbEntityService extends SqbServiceBase {
|
|
|
509
460
|
options.filter = SQBAdapter.parseFilter(options.filter);
|
|
510
461
|
return await repo.updateMany(data, options);
|
|
511
462
|
}
|
|
512
|
-
/**
|
|
513
|
-
* Retrieves the database connection.
|
|
514
|
-
*
|
|
515
|
-
* @protected
|
|
516
|
-
*
|
|
517
|
-
* @throws {Error} If the context or database is not set.
|
|
518
|
-
*/
|
|
519
|
-
getConnection() {
|
|
520
|
-
const ctx = this.context;
|
|
521
|
-
let db = ctx[transactionKey];
|
|
522
|
-
if (db)
|
|
523
|
-
return db;
|
|
524
|
-
db = typeof this.db === 'function' ? this.db(this) : this.db;
|
|
525
|
-
if (db)
|
|
526
|
-
return db;
|
|
527
|
-
throw new Error(`Database not set!`);
|
|
528
|
-
}
|
|
529
463
|
/**
|
|
530
464
|
* Retrieves the common filter used for querying documents.
|
|
531
465
|
* This method is mostly used for security issues like securing multi-tenant applications.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/sqb",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Opra SQB adapter package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"valgen": "^5.10.0"
|
|
11
11
|
},
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"@opra/core": "^1.0.
|
|
14
|
-
"@opra/http": "^1.0.
|
|
13
|
+
"@opra/core": "^1.0.8",
|
|
14
|
+
"@opra/http": "^1.0.8",
|
|
15
15
|
"@sqb/connect": ">= 4.19.1"
|
|
16
16
|
},
|
|
17
17
|
"type": "module",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ComplexType } from '@opra/common';
|
|
2
2
|
import { ExecutionContext, ServiceBase } from '@opra/core';
|
|
3
|
-
import { EntityMetadata, Repository
|
|
3
|
+
import { EntityMetadata, Repository } from '@sqb/connect';
|
|
4
4
|
import type { Nullish, PartialDTO, PatchDTO, RequiredSome, StrictOmit, Type } from 'ts-gems';
|
|
5
5
|
import { type IsObject } from 'valgen';
|
|
6
6
|
import { SQBAdapter } from './sqb-adapter.js';
|
|
@@ -205,12 +205,6 @@ export declare class SqbEntityService<T extends object = object> extends SqbServ
|
|
|
205
205
|
*/
|
|
206
206
|
get entityMetadata(): EntityMetadata;
|
|
207
207
|
for<C extends ExecutionContext, P extends Partial<this>>(context: C | ServiceBase, overwriteProperties?: Nullish<P>, overwriteContext?: Partial<C>): this & Required<P>;
|
|
208
|
-
/**
|
|
209
|
-
* Executes the provided function within a transaction.
|
|
210
|
-
*
|
|
211
|
-
* @param callback - The function to be executed within the transaction.
|
|
212
|
-
*/
|
|
213
|
-
withTransaction(callback: (connection: SqbConnection, _this: this) => any): Promise<any>;
|
|
214
208
|
/**
|
|
215
209
|
* Retrieves the resource name.
|
|
216
210
|
*
|
|
@@ -428,14 +422,6 @@ export declare class SqbEntityService<T extends object = object> extends SqbServ
|
|
|
428
422
|
* @protected
|
|
429
423
|
*/
|
|
430
424
|
protected _dbUpdateMany(data: PatchDTO<T>, options?: Repository.UpdateManyOptions): Promise<number>;
|
|
431
|
-
/**
|
|
432
|
-
* Retrieves the database connection.
|
|
433
|
-
*
|
|
434
|
-
* @protected
|
|
435
|
-
*
|
|
436
|
-
* @throws {Error} If the context or database is not set.
|
|
437
|
-
*/
|
|
438
|
-
getConnection(): SqbConnection | SqbClient | Promise<SqbConnection | SqbClient>;
|
|
439
425
|
/**
|
|
440
426
|
* Retrieves the common filter used for querying documents.
|
|
441
427
|
* This method is mostly used for security issues like securing multi-tenant applications.
|