@travetto/model-sqlite 3.4.5 → 4.0.0-rc.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-sqlite",
3
- "version": "3.4.5",
3
+ "version": "4.0.0-rc.1",
4
4
  "description": "SQLite backing for the travetto model module, with real-time modeling support for SQL schemas.",
5
5
  "keywords": [
6
6
  "sql",
@@ -26,13 +26,13 @@
26
26
  "directory": "module/model-sqlite"
27
27
  },
28
28
  "dependencies": {
29
- "@travetto/config": "^3.4.4",
30
- "@travetto/context": "^3.4.2",
31
- "@travetto/model": "^3.4.5",
32
- "@travetto/model-query": "^3.4.5",
33
- "@travetto/model-sql": "^3.4.5",
34
- "@types/better-sqlite3": "^7.6.7",
35
- "better-sqlite3": "^9.1.1"
29
+ "@travetto/config": "^4.0.0-rc.1",
30
+ "@travetto/context": "^4.0.0-rc.1",
31
+ "@travetto/model": "^4.0.0-rc.1",
32
+ "@travetto/model-query": "^4.0.0-rc.1",
33
+ "@travetto/model-sql": "^4.0.0-rc.1",
34
+ "@types/better-sqlite3": "^7.6.9",
35
+ "better-sqlite3": "^9.4.0"
36
36
  },
37
37
  "travetto": {
38
38
  "displayName": "SQLite Model Service"
package/src/connection.ts CHANGED
@@ -1,9 +1,10 @@
1
- import fs from 'fs/promises';
1
+ import fs from 'node:fs/promises';
2
+ import timers from 'node:timers/promises';
2
3
  import sqlDb, * as sqlite3 from 'better-sqlite3';
3
4
  import pool from 'generic-pool';
4
5
 
5
- import { ManifestFileUtil, RootIndex, path } from '@travetto/manifest';
6
- import { ShutdownManager, TimeUtil } from '@travetto/base';
6
+ import { RuntimeContext, path } from '@travetto/manifest';
7
+ import { ShutdownManager } from '@travetto/base';
7
8
  import { AsyncContext, WithAsyncContext } from '@travetto/context';
8
9
  import { ExistsError } from '@travetto/model';
9
10
  import { SQLModelConfig, Connection } from '@travetto/model-sql';
@@ -33,7 +34,7 @@ export class SqliteConnection extends Connection<sqlite3.Database> {
33
34
  } catch (err) {
34
35
  if (err instanceof Error && retries > 1 && err.message.includes('database is locked')) {
35
36
  console.error('Failed, and waiting', retries);
36
- await TimeUtil.wait(delay);
37
+ await timers.setTimeout(delay);
37
38
  retries -= 1;
38
39
  } else {
39
40
  throw err;
@@ -43,8 +44,7 @@ export class SqliteConnection extends Connection<sqlite3.Database> {
43
44
  }
44
45
 
45
46
  async #create(): Promise<sqlite3.Database> {
46
- const file = path.resolve(this.#config.options.file ??
47
- ManifestFileUtil.toolPath(RootIndex, 'sqlite_db', true));
47
+ const file = path.resolve(this.#config.options.file ?? RuntimeContext.toolPath('@', 'sqlite_db'));
48
48
  await fs.mkdir(path.dirname(file), { recursive: true });
49
49
  const db = new sqlDb(file, this.#config.options);
50
50
  await db.pragma('foreign_keys = ON');
@@ -66,7 +66,7 @@ export class SqliteConnection extends Connection<sqlite3.Database> {
66
66
  }, { max: 1 });
67
67
 
68
68
  // Close postgres
69
- ShutdownManager.onShutdown(this, () => this.#pool.clear());
69
+ ShutdownManager.onGracefulShutdown(() => this.#pool.clear(), this);
70
70
  }
71
71
 
72
72
  async execute<T = unknown>(conn: sqlite3.Database, query: string): Promise<{ count: number, records: T[] }> {