@holo-js/db-mysql 0.1.9 → 0.2.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
@@ -31,6 +31,7 @@ declare class MySQLAdapter implements DriverAdapter {
31
31
  private readonly transactionScope;
32
32
  constructor(options?: MySQLAdapterOptions);
33
33
  initialize(): Promise<void>;
34
+ isDatabaseMissingError(error: unknown): boolean;
34
35
  disconnect(): Promise<void>;
35
36
  isConnected(): boolean;
36
37
  runWithTransactionScope<T>(callback: () => Promise<T>): Promise<T>;
@@ -44,7 +45,7 @@ declare class MySQLAdapter implements DriverAdapter {
44
45
  rollbackToSavepoint(name: string): Promise<void>;
45
46
  releaseSavepoint(name: string): Promise<void>;
46
47
  private getQueryable;
47
- private ensureDatabaseExists;
48
+ ensureDatabaseExists(): Promise<void>;
48
49
  private leaseTransactionClient;
49
50
  private requireTransactionClient;
50
51
  private releaseTransactionClient;
package/dist/index.mjs CHANGED
@@ -63,6 +63,9 @@ function wrapMySQLPool(pool) {
63
63
  end: rawPool.end.bind(rawPool)
64
64
  };
65
65
  }
66
+ function isMySQLDatabaseMissing(error) {
67
+ return typeof error === "object" && error !== null && ("code" in error && error.code === "ER_BAD_DB_ERROR" || "errno" in error && error.errno === 1049);
68
+ }
66
69
  var MySQLAdapter = class {
67
70
  pool;
68
71
  directClient;
@@ -84,11 +87,13 @@ var MySQLAdapter = class {
84
87
  return;
85
88
  }
86
89
  if (this.createPoolInstance) {
87
- await this.ensureDatabaseExists();
88
90
  this.pool = this.createPoolInstance(this.config);
89
91
  }
90
92
  this.connected = true;
91
93
  }
94
+ isDatabaseMissingError(error) {
95
+ return isMySQLDatabaseMissing(error);
96
+ }
92
97
  async disconnect() {
93
98
  if (!this.connected) {
94
99
  return;
@@ -216,7 +221,10 @@ var MySQLAdapter = class {
216
221
  }
217
222
  } catch (error) {
218
223
  const message = error instanceof Error ? error.message : String(error);
219
- throw new Error(`Unable to ensure MySQL database "${target.database}" exists: ${message}`, { cause: error });
224
+ throw new Error(
225
+ `MySQL database "${target.database}" could not be found or created. Please create the database and try again. Original error: ${message}`,
226
+ { cause: error }
227
+ );
220
228
  } finally {
221
229
  await bootstrapPool.end();
222
230
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holo-js/db-mysql",
3
- "version": "0.1.9",
3
+ "version": "0.2.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.1.9"
27
+ "@holo-js/db": "^0.2.0"
28
28
  },
29
29
  "dependencies": {
30
30
  "mysql2": "^3.17.1"
31
31
  },
32
32
  "devDependencies": {
33
- "@holo-js/db": "^0.1.9",
33
+ "@holo-js/db": "^0.2.0",
34
34
  "tsup": "^8.3.5",
35
35
  "typescript": "^5.7.2",
36
36
  "vitest": "^4.1.5"