@mostajs/setup 1.4.3 → 1.4.4
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/lib/db-test.js +39 -0
- package/package.json +1 -1
package/dist/lib/db-test.js
CHANGED
|
@@ -25,6 +25,45 @@ export async function testDbConnection(params) {
|
|
|
25
25
|
return { ok: true };
|
|
26
26
|
default: {
|
|
27
27
|
const uri = composeDbUri(dialect, dbConfig);
|
|
28
|
+
// For JDBC bridge dialects, try testing via the bridge HTTP endpoint directly.
|
|
29
|
+
// This avoids module singleton issues in Next.js where BridgeManager instances
|
|
30
|
+
// may differ between API routes.
|
|
31
|
+
const JDBC_DIALECTS = ['hsqldb', 'oracle', 'db2', 'hana', 'sybase'];
|
|
32
|
+
if (JDBC_DIALECTS.includes(dialect)) {
|
|
33
|
+
const bridgePort = parseInt(process.env.MOSTA_BRIDGE_PORT_BASE || '8765');
|
|
34
|
+
// Scan ports 8765..8774 for an active bridge
|
|
35
|
+
for (let port = bridgePort; port < bridgePort + 10; port++) {
|
|
36
|
+
try {
|
|
37
|
+
const healthRes = await fetch(`http://localhost:${port}/health`, {
|
|
38
|
+
signal: AbortSignal.timeout(1000),
|
|
39
|
+
});
|
|
40
|
+
if (!healthRes.ok)
|
|
41
|
+
continue;
|
|
42
|
+
// Bridge found — test a query
|
|
43
|
+
// Use dialect-appropriate ping query
|
|
44
|
+
const pingQuery = dialect === 'hsqldb'
|
|
45
|
+
? 'SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS'
|
|
46
|
+
: dialect === 'oracle'
|
|
47
|
+
? 'SELECT 1 FROM DUAL'
|
|
48
|
+
: 'SELECT 1';
|
|
49
|
+
const queryRes = await fetch(`http://localhost:${port}/query`, {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
headers: { 'Content-Type': 'application/json' },
|
|
52
|
+
body: JSON.stringify({ sql: pingQuery, params: [] }),
|
|
53
|
+
signal: AbortSignal.timeout(5000),
|
|
54
|
+
});
|
|
55
|
+
if (queryRes.ok) {
|
|
56
|
+
return { ok: true };
|
|
57
|
+
}
|
|
58
|
+
const text = await queryRes.text();
|
|
59
|
+
return { ok: false, error: `Bridge query failed: ${text}` };
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return { ok: false, error: `Aucun bridge JDBC actif. Lancez le bridge d'abord.` };
|
|
66
|
+
}
|
|
28
67
|
const { testConnection } = await import('@mostajs/orm');
|
|
29
68
|
const result = await testConnection({
|
|
30
69
|
dialect,
|
package/package.json
CHANGED