@cheetah.js/orm 0.1.108 → 0.1.113

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/README.md CHANGED
@@ -375,6 +375,19 @@ const user = await User.findOne({
375
375
  });
376
376
  ```
377
377
 
378
+ #### Transactions
379
+ ```typescript
380
+ import { Orm } from '@cheetah.js/orm';
381
+
382
+ const orm = Orm.getInstance();
383
+
384
+ await orm.transaction(async (tx) => {
385
+ await tx`INSERT INTO users (name) VALUES (${ 'Jane Doe' })`;
386
+ await tx`UPDATE accounts SET balance = balance - 100 WHERE user_id = ${ 1 }`;
387
+ });
388
+ ```
389
+ The `transaction` method leverages the active driver implementation, ensuring consistent transactional semantics across supported databases.
390
+
378
391
  #### List of supported operators
379
392
  | Operator |Name | Description |
380
393
  | ------ | ---- |--------------------------------------------------------------------------------------------|
package/dist/orm.d.ts CHANGED
@@ -16,4 +16,5 @@ export declare class Orm<T extends DriverInterface = DriverInterface> {
16
16
  createQueryBuilder<Model>(model: new () => Model): SqlBuilder<Model>;
17
17
  connect(): Promise<void>;
18
18
  disconnect(): Promise<void>;
19
+ transaction<ResultType>(operation: (tx: unknown) => Promise<ResultType>): Promise<ResultType>;
19
20
  }
package/dist/orm.js CHANGED
@@ -43,6 +43,12 @@ let Orm = Orm_1 = class Orm {
43
43
  disconnect() {
44
44
  return this.driverInstance.disconnect();
45
45
  }
46
+ async transaction(operation) {
47
+ if (!this.driverInstance) {
48
+ throw new Error('Driver instance not initialized');
49
+ }
50
+ return this.driverInstance.transaction(operation);
51
+ }
46
52
  };
47
53
  exports.Orm = Orm;
48
54
  exports.Orm = Orm = Orm_1 = __decorate([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cheetah.js/orm",
3
- "version": "0.1.108",
3
+ "version": "0.1.113",
4
4
  "description": "A simple ORM for Cheetah.js",
5
5
  "type": "commonjs",
6
6
  "main": "dist/index.js",
@@ -55,5 +55,5 @@
55
55
  "bun",
56
56
  "value-object"
57
57
  ],
58
- "gitHead": "54cacece32a1142372b06e8727e0e696c2fc5686"
58
+ "gitHead": "439b0bb37b4f7b81d2aebf4171ba27792062d762"
59
59
  }