@travetto/model-sqlite 7.1.4 → 8.0.0-alpha.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/package.json +7 -7
- package/src/connection.ts +7 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-sqlite",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0-alpha.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "SQLite backing for the travetto model module, with real-time modeling support for SQL schemas.",
|
|
6
6
|
"keywords": [
|
|
@@ -27,13 +27,13 @@
|
|
|
27
27
|
"directory": "module/model-sqlite"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@travetto/config": "^
|
|
31
|
-
"@travetto/context": "^
|
|
32
|
-
"@travetto/model": "^
|
|
33
|
-
"@travetto/model-query": "^
|
|
34
|
-
"@travetto/model-sql": "^
|
|
30
|
+
"@travetto/config": "^8.0.0-alpha.0",
|
|
31
|
+
"@travetto/context": "^8.0.0-alpha.0",
|
|
32
|
+
"@travetto/model": "^8.0.0-alpha.0",
|
|
33
|
+
"@travetto/model-query": "^8.0.0-alpha.0",
|
|
34
|
+
"@travetto/model-sql": "^8.0.0-alpha.0",
|
|
35
35
|
"@types/better-sqlite3": "^7.6.13",
|
|
36
|
-
"better-sqlite3": "^12.6.
|
|
36
|
+
"better-sqlite3": "^12.6.2"
|
|
37
37
|
},
|
|
38
38
|
"travetto": {
|
|
39
39
|
"displayName": "SQLite Model Service",
|
package/src/connection.ts
CHANGED
|
@@ -4,7 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import sqlDb, { type Database, type Options } from 'better-sqlite3';
|
|
5
5
|
import { type Pool, createPool } from 'generic-pool';
|
|
6
6
|
|
|
7
|
-
import { ShutdownManager, Util, Runtime,
|
|
7
|
+
import { ShutdownManager, Util, Runtime, RuntimeError, castTo } from '@travetto/runtime';
|
|
8
8
|
import { type AsyncContext, WithAsyncContext } from '@travetto/context';
|
|
9
9
|
import { ExistsError } from '@travetto/model';
|
|
10
10
|
import { type SQLModelConfig, Connection } from '@travetto/model-sql';
|
|
@@ -45,7 +45,7 @@ export class SqliteConnection extends Connection<Database> {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
throw new
|
|
48
|
+
throw new RuntimeError('Max retries exceeded');
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
async #create(): Promise<Database> {
|
|
@@ -80,12 +80,15 @@ export class SqliteConnection extends Connection<Database> {
|
|
|
80
80
|
async execute<T = unknown>(connection: Database, query: string, values?: unknown[]): Promise<{ count: number, records: T[] }> {
|
|
81
81
|
return this.#withRetries(async () => {
|
|
82
82
|
console.debug('Executing query', { query });
|
|
83
|
+
|
|
83
84
|
try {
|
|
84
|
-
const
|
|
85
|
-
if (
|
|
85
|
+
const prepared = connection.prepare<unknown[], T>(query).safeIntegers(true);
|
|
86
|
+
if (query.trim().startsWith('SELECT')) {
|
|
87
|
+
const out = prepared.all(...values ?? []);
|
|
86
88
|
const records: T[] = out.map(item => ({ ...item }));
|
|
87
89
|
return { count: out.length, records };
|
|
88
90
|
} else {
|
|
91
|
+
const out = prepared.run(...values ?? []);
|
|
89
92
|
return { count: out.changes, records: [] };
|
|
90
93
|
}
|
|
91
94
|
} catch (error) {
|