@holo-js/db-mysql 0.2.5 → 0.3.0

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PoolOptions } from 'mysql2/promise';
2
- import { DriverAdapter, DriverQueryResult, DriverExecutionResult } from '@holo-js/db';
2
+ import { DriverAdapter, DriverQueryResult, DriverExecutionResult, DatabaseDriverFactory } from '@holo-js/db';
3
3
  export { DriverAdapter, DriverExecutionResult, DriverQueryResult } from '@holo-js/db';
4
4
 
5
5
  interface MySQLQueryableLike {
@@ -13,14 +13,15 @@ interface MySQLPoolLike extends MySQLQueryableLike {
13
13
  getConnection(): Promise<MySQLClientLike>;
14
14
  end(): Promise<void>;
15
15
  }
16
- interface MySQLAdapterOptions {
16
+ interface MySQLAdapterOptions<TConfig extends PoolOptions = PoolOptions> {
17
17
  uri?: string;
18
- config?: PoolOptions;
18
+ config?: TConfig;
19
19
  client?: MySQLClientLike;
20
20
  pool?: MySQLPoolLike;
21
- createPool?: (config: PoolOptions) => MySQLPoolLike;
21
+ createPool?: (config: TConfig) => MySQLPoolLike;
22
22
  }
23
- declare class MySQLAdapter implements DriverAdapter {
23
+ declare class MySQLAdapter<TConfig extends PoolOptions = PoolOptions> implements DriverAdapter {
24
+ readonly supportsConcurrentTransactionScopes = true;
24
25
  private pool?;
25
26
  private readonly directClient?;
26
27
  private readonly createPoolInstance?;
@@ -29,7 +30,7 @@ declare class MySQLAdapter implements DriverAdapter {
29
30
  private transactionClient?;
30
31
  private leasedTransactionClient;
31
32
  private readonly transactionScope;
32
- constructor(options?: MySQLAdapterOptions);
33
+ constructor(options?: MySQLAdapterOptions<TConfig>);
33
34
  initialize(): Promise<void>;
34
35
  isDatabaseMissingError(error: unknown): boolean;
35
36
  disconnect(): Promise<void>;
@@ -52,6 +53,7 @@ declare class MySQLAdapter implements DriverAdapter {
52
53
  private releaseScopedTransaction;
53
54
  private normalizeSavepointName;
54
55
  }
55
- declare function createMySQLAdapter(options?: MySQLAdapterOptions): MySQLAdapter;
56
+ declare function createMySQLAdapter<TConfig extends PoolOptions = PoolOptions>(options?: MySQLAdapterOptions<TConfig>): MySQLAdapter<TConfig>;
57
+ declare const mysqlDatabaseDriverFactory: DatabaseDriverFactory;
56
58
 
57
- export { MySQLAdapter, type MySQLAdapterOptions, type MySQLClientLike, type MySQLPoolLike, type MySQLQueryableLike, createMySQLAdapter };
59
+ export { MySQLAdapter, type MySQLAdapterOptions, type MySQLClientLike, type MySQLPoolLike, type MySQLQueryableLike, createMySQLAdapter, mysqlDatabaseDriverFactory };
package/dist/index.mjs CHANGED
@@ -67,6 +67,7 @@ function isMySQLDatabaseMissing(error) {
67
67
  return typeof error === "object" && error !== null && ("code" in error && error.code === "ER_BAD_DB_ERROR" || "errno" in error && error.errno === 1049);
68
68
  }
69
69
  var MySQLAdapter = class {
70
+ supportsConcurrentTransactionScopes = true;
70
71
  pool;
71
72
  directClient;
72
73
  createPoolInstance;
@@ -122,16 +123,14 @@ var MySQLAdapter = class {
122
123
  await this.initialize();
123
124
  if (this.directClient) {
124
125
  return this.transactionScope.run({
125
- client: this.directClient,
126
- leased: false
126
+ client: this.directClient
127
127
  }, callback);
128
128
  }
129
129
  if (!this.pool) {
130
130
  throw new TransactionError("MySQL adapter is not initialized with a pool or client.");
131
131
  }
132
132
  const state = {
133
- client: await this.pool.getConnection(),
134
- leased: true
133
+ client: await this.pool.getConnection()
135
134
  };
136
135
  return this.transactionScope.run(state, async () => {
137
136
  try {
@@ -268,9 +267,6 @@ var MySQLAdapter = class {
268
267
  this.leasedTransactionClient = false;
269
268
  }
270
269
  releaseScopedTransaction(state) {
271
- if (!state.leased) {
272
- return;
273
- }
274
270
  state.client.release?.();
275
271
  }
276
272
  normalizeSavepointName(name) {
@@ -283,7 +279,22 @@ var MySQLAdapter = class {
283
279
  function createMySQLAdapter(options = {}) {
284
280
  return new MySQLAdapter(options);
285
281
  }
282
+ var mysqlDatabaseDriverFactory = Object.freeze({
283
+ driver: "mysql",
284
+ supportsConcurrentTransactionScopes: true,
285
+ create(connection) {
286
+ return connection.url ? createMySQLAdapter({ uri: connection.url }) : createMySQLAdapter({ config: {
287
+ host: connection.host,
288
+ port: connection.port,
289
+ user: connection.username,
290
+ password: connection.password,
291
+ database: connection.database,
292
+ ssl: connection.ssl === true ? {} : connection.ssl || void 0
293
+ } });
294
+ }
295
+ });
286
296
  export {
287
297
  MySQLAdapter,
288
- createMySQLAdapter
298
+ createMySQLAdapter,
299
+ mysqlDatabaseDriverFactory
289
300
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holo-js/db-mysql",
3
- "version": "0.2.5",
3
+ "version": "0.3.0",
4
4
  "description": "Holo-JS Framework - MySQL database adapter",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -24,13 +24,13 @@
24
24
  "test:integration": "HOLO_MYSQL_INTEGRATION=1 vitest --run tests/mysql.test.ts"
25
25
  },
26
26
  "peerDependencies": {
27
- "@holo-js/db": "^0.2.5"
27
+ "@holo-js/db": "^0.3.0"
28
28
  },
29
29
  "dependencies": {
30
30
  "mysql2": "^3.17.1"
31
31
  },
32
32
  "devDependencies": {
33
- "@holo-js/db": "^0.2.5",
33
+ "@holo-js/db": "^0.3.0",
34
34
  "tsup": "^8.3.5",
35
35
  "typescript": "^5.7.2",
36
36
  "vitest": "^4.1.5"