@hemia/db-connector 0.0.12 → 0.0.14

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.
@@ -3085,27 +3085,12 @@ class DrizzlePostgresConnector extends DrizzleSqlConnector {
3085
3085
  return __awaiter(this, void 0, void 0, function* () {
3086
3086
  this.ensureConnected();
3087
3087
  try {
3088
- yield this.connection `BEGIN`;
3089
- const txMock = {
3090
- commit: () => __awaiter(this, void 0, void 0, function* () {
3091
- yield this.connection `COMMIT`;
3092
- }),
3093
- rollback: () => __awaiter(this, void 0, void 0, function* () {
3094
- yield this.connection `ROLLBACK`;
3095
- })
3096
- };
3097
- try {
3098
- const result = yield fn(txMock);
3099
- yield this.connection `COMMIT`;
3100
- return result;
3101
- }
3102
- catch (error) {
3103
- yield this.connection `ROLLBACK`;
3104
- throw error;
3105
- }
3088
+ return yield this.db.transaction((tx) => __awaiter(this, void 0, void 0, function* () {
3089
+ return yield fn(tx);
3090
+ }));
3106
3091
  }
3107
3092
  catch (error) {
3108
- console.error(error);
3093
+ console.error("Transaction Error:", error);
3109
3094
  throw this.createDatabaseError(error);
3110
3095
  }
3111
3096
  });
@@ -3083,27 +3083,12 @@ class DrizzlePostgresConnector extends DrizzleSqlConnector {
3083
3083
  return __awaiter(this, void 0, void 0, function* () {
3084
3084
  this.ensureConnected();
3085
3085
  try {
3086
- yield this.connection `BEGIN`;
3087
- const txMock = {
3088
- commit: () => __awaiter(this, void 0, void 0, function* () {
3089
- yield this.connection `COMMIT`;
3090
- }),
3091
- rollback: () => __awaiter(this, void 0, void 0, function* () {
3092
- yield this.connection `ROLLBACK`;
3093
- })
3094
- };
3095
- try {
3096
- const result = yield fn(txMock);
3097
- yield this.connection `COMMIT`;
3098
- return result;
3099
- }
3100
- catch (error) {
3101
- yield this.connection `ROLLBACK`;
3102
- throw error;
3103
- }
3086
+ return yield this.db.transaction((tx) => __awaiter(this, void 0, void 0, function* () {
3087
+ return yield fn(tx);
3088
+ }));
3104
3089
  }
3105
3090
  catch (error) {
3106
- console.error(error);
3091
+ console.error("Transaction Error:", error);
3107
3092
  throw this.createDatabaseError(error);
3108
3093
  }
3109
3094
  });
@@ -1,6 +1,6 @@
1
1
  import { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
2
2
  import { PgTable } from 'drizzle-orm/pg-core';
3
- import { DrizzleSqlConnector, DrizzleSelectOptions, DrizzleInsertOptions, DrizzleUpdateOptions, DrizzleDeleteOptions, DrizzleQueryOptions, DrizzleTransaction } from '../abstract/DrizzleSQLConnector';
3
+ import { DrizzleSqlConnector, DrizzleSelectOptions, DrizzleInsertOptions, DrizzleUpdateOptions, DrizzleDeleteOptions, DrizzleQueryOptions } from '../abstract/DrizzleSQLConnector';
4
4
  import { CredentialsConnection } from '../types/CredentialsConnection';
5
5
  export declare class DrizzlePostgresConnector extends DrizzleSqlConnector {
6
6
  private readonly creds;
@@ -19,7 +19,7 @@ export declare class DrizzlePostgresConnector extends DrizzleSqlConnector {
19
19
  update(entity: string, filter: Record<string, any>, data: Record<string, any>, options?: DrizzleUpdateOptions): Promise<number>;
20
20
  delete(entity: string, filter: Record<string, any>, options?: DrizzleDeleteOptions): Promise<number>;
21
21
  query<T = any>(sql: string, options?: DrizzleQueryOptions): Promise<T[]>;
22
- withTransaction<T>(fn: (tx: DrizzleTransaction) => Promise<T>): Promise<T>;
22
+ withTransaction<T>(fn: (tx: any) => Promise<T>): Promise<T>;
23
23
  private buildDrizzleWhere;
24
24
  private buildRawWhereClause;
25
25
  private executeRawQuery;
@@ -1,3 +1,4 @@
1
+ import { PgTransaction } from "drizzle-orm/pg-core";
1
2
  export interface DrizzleSelectOptions {
2
3
  where?: Record<string, any>;
3
4
  limit?: number;
@@ -27,10 +28,7 @@ export interface DrizzleQueryOptions {
27
28
  bind?: Record<string, any>;
28
29
  replacements?: any[];
29
30
  }
30
- export interface DrizzleTransaction {
31
- commit(): Promise<void>;
32
- rollback(): Promise<void>;
33
- }
31
+ export type DrizzleTransaction = PgTransaction<any, any, any>;
34
32
  export declare abstract class DrizzleSqlConnector {
35
33
  abstract connect(): Promise<void>;
36
34
  abstract disconnect(): Promise<void>;
@@ -40,5 +38,5 @@ export declare abstract class DrizzleSqlConnector {
40
38
  abstract update(entity: string, filter: Record<string, any>, data: Record<string, any>, options?: DrizzleUpdateOptions): Promise<number>;
41
39
  abstract delete(entity: string, filter: Record<string, any>, options?: DrizzleDeleteOptions): Promise<number>;
42
40
  abstract query<T = any>(sql: string, options?: DrizzleQueryOptions): Promise<T[]>;
43
- abstract withTransaction<T>(fn: (tx: DrizzleTransaction) => Promise<T>): Promise<T>;
41
+ abstract withTransaction<T>(fn: (tx: any) => Promise<T>): Promise<T>;
44
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hemia/db-connector",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "Hemia Database Conector",
5
5
  "main": "dist/hemia-db-connector.js",
6
6
  "module": "dist/hemia-db-connector.esm.js",