@mikro-orm/knex 6.0.0-dev.317 → 6.0.0-dev.319

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.
@@ -37,13 +37,8 @@ class AbstractSqlConnection extends core_1.Connection {
37
37
  * @inheritDoc
38
38
  */
39
39
  async isConnected() {
40
- try {
41
- await this.getKnex().raw('select 1');
42
- return true;
43
- }
44
- catch {
45
- return false;
46
- }
40
+ const check = await this.checkConnection();
41
+ return check.ok;
47
42
  }
48
43
  /**
49
44
  * @inheritDoc
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.0.0-dev.317",
3
+ "version": "6.0.0-dev.319",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -66,6 +66,6 @@
66
66
  "@mikro-orm/core": "^5.0.0"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.0.0-dev.317"
69
+ "@mikro-orm/core": "6.0.0-dev.319"
70
70
  }
71
71
  }
@@ -21,17 +21,20 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
21
21
  */
22
22
  async ensureDatabase(options) {
23
23
  const dbName = this.config.get('dbName');
24
- if (this.lastEnsuredDatabase === dbName) {
24
+ if (this.lastEnsuredDatabase === dbName && !options?.forceCheck) {
25
25
  return true;
26
26
  }
27
27
  const exists = await this.helper.databaseExists(this.connection, dbName);
28
28
  this.lastEnsuredDatabase = dbName;
29
29
  if (!exists) {
30
- this.config.set('dbName', this.helper.getManagementDbName());
31
- await this.driver.reconnect();
32
- await this.createDatabase(dbName);
33
- this.config.set('dbName', dbName);
34
- await this.driver.reconnect();
30
+ const managementDbName = this.helper.getManagementDbName();
31
+ if (managementDbName) {
32
+ this.config.set('dbName', managementDbName);
33
+ await this.driver.reconnect();
34
+ await this.createDatabase(dbName);
35
+ this.config.set('dbName', dbName);
36
+ await this.driver.reconnect();
37
+ }
35
38
  if (options?.create) {
36
39
  await this.createSchema(options);
37
40
  }
@@ -376,7 +379,10 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
376
379
  * creates new database and connects to it
377
380
  */
378
381
  async createDatabase(name) {
379
- await this.driver.execute(this.helper.getCreateDatabaseSQL('' + this.knex.ref(name)));
382
+ const sql = this.helper.getCreateDatabaseSQL('' + this.knex.ref(name));
383
+ if (sql) {
384
+ await this.driver.execute(sql);
385
+ }
380
386
  this.config.set('dbName', name);
381
387
  await this.driver.reconnect();
382
388
  }