@bytebase/dbhub 0.24.0 → 1.1.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/README.md +8 -44
- package/dist/{chunk-JO7YQPBQ.js → chunk-EPOKWSFC.js} +24 -2
- package/dist/chunk-FU2ZJE4E.js +16 -0
- package/dist/{chunk-MQR6VX5F.js → chunk-GSSLHJB6.js} +13 -4
- package/dist/chunk-NIILHXTG.js +190 -0
- package/dist/{chunk-D2BIPC7V.js → chunk-S2V6RZ3C.js} +4 -2
- package/dist/index.js +377 -97
- package/dist/{mariadb-VZMU7LYA.js → mariadb-DUDFBY5W.js} +12 -13
- package/dist/{mysql-MHIZK2UY.js → mysql-265M3KBD.js} +15 -13
- package/dist/{postgres-ZQFXCBYA.js → postgres-5ZOFYV6X.js} +63 -14
- package/dist/{registry-ZU6ZFNQ2.js → registry-JYRRNC3E.js} +1 -1
- package/dist/{sqlite-JH5CNV5E.js → sqlite-5M7SDAQZ.js} +4 -18
- package/dist/{sqlserver-LHWZ7WOP.js → sqlserver-PSAZRH7G.js} +307 -65
- package/package.json +5 -3
- package/dist/chunk-DUCNPMNW.js +0 -113
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MissingDatabaseError,
|
|
3
3
|
extractAffectedRows,
|
|
4
|
+
getMySQLFamilyHealthCheck,
|
|
4
5
|
isTiDBVersion,
|
|
5
6
|
parseQueryResults,
|
|
6
7
|
requireDatabaseInDSN,
|
|
7
8
|
withReadOnlyTransaction
|
|
8
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-NIILHXTG.js";
|
|
10
|
+
import "./chunk-FU2ZJE4E.js";
|
|
9
11
|
import {
|
|
10
12
|
quoteIdentifier
|
|
11
13
|
} from "./chunk-JFWX35TB.js";
|
|
12
14
|
import {
|
|
13
15
|
SQLRowLimiter,
|
|
14
16
|
closeQuietly
|
|
15
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-S2V6RZ3C.js";
|
|
16
18
|
import {
|
|
17
19
|
ConnectorRegistry,
|
|
18
20
|
SafeURL,
|
|
@@ -338,6 +340,13 @@ var MariaDBConnector = class _MariaDBConnector {
|
|
|
338
340
|
return null;
|
|
339
341
|
}
|
|
340
342
|
}
|
|
343
|
+
async getHealthCheck() {
|
|
344
|
+
if (!this.pool) {
|
|
345
|
+
throw new Error("Not connected to database");
|
|
346
|
+
}
|
|
347
|
+
const pool = this.pool;
|
|
348
|
+
return getMySQLFamilyHealthCheck((sql) => pool.query(sql));
|
|
349
|
+
}
|
|
341
350
|
async getStoredProcedures(schema, routineType) {
|
|
342
351
|
if (!this.pool) {
|
|
343
352
|
throw new Error("Not connected to database");
|
|
@@ -509,14 +518,7 @@ var MariaDBConnector = class _MariaDBConnector {
|
|
|
509
518
|
}
|
|
510
519
|
let results;
|
|
511
520
|
if (parameters && parameters.length > 0) {
|
|
512
|
-
|
|
513
|
-
results = await conn.query(processedSQL, parameters);
|
|
514
|
-
} catch (error) {
|
|
515
|
-
console.error(`[MariaDB executeSQL] ERROR: ${error.message}`);
|
|
516
|
-
console.error(`[MariaDB executeSQL] SQL: ${processedSQL}`);
|
|
517
|
-
console.error(`[MariaDB executeSQL] Parameters: ${JSON.stringify(parameters)}`);
|
|
518
|
-
throw error;
|
|
519
|
-
}
|
|
521
|
+
results = await conn.query(processedSQL, parameters);
|
|
520
522
|
} else {
|
|
521
523
|
results = await conn.query(processedSQL);
|
|
522
524
|
}
|
|
@@ -525,9 +527,6 @@ var MariaDBConnector = class _MariaDBConnector {
|
|
|
525
527
|
return { rows, rowCount };
|
|
526
528
|
}
|
|
527
529
|
);
|
|
528
|
-
} catch (error) {
|
|
529
|
-
console.error("Error executing query:", error);
|
|
530
|
-
throw error;
|
|
531
530
|
} finally {
|
|
532
531
|
conn.release();
|
|
533
532
|
}
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MissingDatabaseError,
|
|
3
3
|
extractAffectedRows,
|
|
4
|
+
getMySQLFamilyHealthCheck,
|
|
4
5
|
isTiDBVersion,
|
|
5
6
|
parseQueryResults,
|
|
6
7
|
requireDatabaseInDSN,
|
|
7
8
|
withReadOnlyTransaction
|
|
8
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-NIILHXTG.js";
|
|
10
|
+
import "./chunk-FU2ZJE4E.js";
|
|
9
11
|
import {
|
|
10
12
|
quoteIdentifier
|
|
11
13
|
} from "./chunk-JFWX35TB.js";
|
|
12
14
|
import {
|
|
13
15
|
SQLRowLimiter,
|
|
14
16
|
closeQuietly
|
|
15
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-S2V6RZ3C.js";
|
|
16
18
|
import {
|
|
17
19
|
ConnectorRegistry,
|
|
18
20
|
SafeURL,
|
|
@@ -343,6 +345,16 @@ var MySQLConnector = class _MySQLConnector {
|
|
|
343
345
|
return null;
|
|
344
346
|
}
|
|
345
347
|
}
|
|
348
|
+
async getHealthCheck() {
|
|
349
|
+
if (!this.pool) {
|
|
350
|
+
throw new Error("Not connected to database");
|
|
351
|
+
}
|
|
352
|
+
const pool = this.pool;
|
|
353
|
+
return getMySQLFamilyHealthCheck(async (sql) => {
|
|
354
|
+
const [rows] = await pool.query(sql);
|
|
355
|
+
return rows;
|
|
356
|
+
});
|
|
357
|
+
}
|
|
346
358
|
async getStoredProcedures(schema, routineType) {
|
|
347
359
|
if (!this.pool) {
|
|
348
360
|
throw new Error("Not connected to database");
|
|
@@ -514,14 +526,7 @@ var MySQLConnector = class _MySQLConnector {
|
|
|
514
526
|
}
|
|
515
527
|
let results;
|
|
516
528
|
if (parameters && parameters.length > 0) {
|
|
517
|
-
|
|
518
|
-
results = await conn.query({ sql: processedSQL, timeout: this.queryTimeoutMs }, parameters);
|
|
519
|
-
} catch (error) {
|
|
520
|
-
console.error(`[MySQL executeSQL] ERROR: ${error.message}`);
|
|
521
|
-
console.error(`[MySQL executeSQL] SQL: ${processedSQL}`);
|
|
522
|
-
console.error(`[MySQL executeSQL] Parameters: ${JSON.stringify(parameters)}`);
|
|
523
|
-
throw error;
|
|
524
|
-
}
|
|
529
|
+
results = await conn.query({ sql: processedSQL, timeout: this.queryTimeoutMs }, parameters);
|
|
525
530
|
} else {
|
|
526
531
|
results = await conn.query({ sql: processedSQL, timeout: this.queryTimeoutMs });
|
|
527
532
|
}
|
|
@@ -531,9 +536,6 @@ var MySQLConnector = class _MySQLConnector {
|
|
|
531
536
|
return { rows, rowCount };
|
|
532
537
|
}
|
|
533
538
|
);
|
|
534
|
-
} catch (error) {
|
|
535
|
-
console.error("Error executing query:", error);
|
|
536
|
-
throw error;
|
|
537
539
|
} finally {
|
|
538
540
|
conn.release();
|
|
539
541
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
toNullableNumber
|
|
3
|
+
} from "./chunk-FU2ZJE4E.js";
|
|
1
4
|
import {
|
|
2
5
|
quoteIdentifier
|
|
3
6
|
} from "./chunk-JFWX35TB.js";
|
|
4
7
|
import {
|
|
5
8
|
SQLRowLimiter,
|
|
6
9
|
closeQuietly
|
|
7
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-S2V6RZ3C.js";
|
|
8
11
|
import {
|
|
9
12
|
ConnectorRegistry,
|
|
10
13
|
SafeURL,
|
|
@@ -383,6 +386,64 @@ var PostgresConnector = class _PostgresConnector {
|
|
|
383
386
|
client.release();
|
|
384
387
|
}
|
|
385
388
|
}
|
|
389
|
+
async getHealthCheck() {
|
|
390
|
+
if (!this.pool) {
|
|
391
|
+
throw new Error("Not connected to database");
|
|
392
|
+
}
|
|
393
|
+
const client = await this.pool.connect();
|
|
394
|
+
try {
|
|
395
|
+
const [connectionsResult, maxConnectionsResult, bufferCacheResult] = await Promise.all([
|
|
396
|
+
client.query(`
|
|
397
|
+
SELECT
|
|
398
|
+
count(*) AS total,
|
|
399
|
+
count(*) FILTER (WHERE state = 'active') AS active,
|
|
400
|
+
count(*) FILTER (WHERE state = 'idle') AS idle,
|
|
401
|
+
count(*) FILTER (WHERE state = 'idle in transaction') AS idle_in_transaction,
|
|
402
|
+
count(*) FILTER (WHERE state = 'idle in transaction (aborted)') AS idle_in_transaction_aborted,
|
|
403
|
+
max(EXTRACT(EPOCH FROM (now() - state_change)))
|
|
404
|
+
FILTER (WHERE state = 'idle in transaction') AS longest_idle_in_transaction_seconds,
|
|
405
|
+
max(EXTRACT(EPOCH FROM (now() - query_start)))
|
|
406
|
+
FILTER (WHERE state = 'active') AS longest_active_query_seconds
|
|
407
|
+
FROM pg_stat_activity
|
|
408
|
+
WHERE pid <> pg_backend_pid()
|
|
409
|
+
`),
|
|
410
|
+
client.query(`SHOW max_connections`),
|
|
411
|
+
client.query(
|
|
412
|
+
`
|
|
413
|
+
SELECT
|
|
414
|
+
blks_hit,
|
|
415
|
+
blks_read,
|
|
416
|
+
CASE WHEN (blks_hit + blks_read) = 0 THEN NULL
|
|
417
|
+
ELSE round(100.0 * blks_hit / (blks_hit + blks_read), 2)
|
|
418
|
+
END AS hit_ratio_pct
|
|
419
|
+
FROM pg_stat_database
|
|
420
|
+
WHERE datname = current_database()
|
|
421
|
+
`
|
|
422
|
+
)
|
|
423
|
+
]);
|
|
424
|
+
const conn = connectionsResult.rows[0];
|
|
425
|
+
const cache = bufferCacheResult.rows[0];
|
|
426
|
+
return {
|
|
427
|
+
connections: {
|
|
428
|
+
total: Number(conn.total),
|
|
429
|
+
active: Number(conn.active),
|
|
430
|
+
idle: Number(conn.idle),
|
|
431
|
+
idleInTransaction: Number(conn.idle_in_transaction),
|
|
432
|
+
idleInTransactionAborted: Number(conn.idle_in_transaction_aborted),
|
|
433
|
+
maxConnections: Number(maxConnectionsResult.rows[0].max_connections),
|
|
434
|
+
longestIdleInTransactionSeconds: toNullableNumber(conn.longest_idle_in_transaction_seconds),
|
|
435
|
+
longestActiveQuerySeconds: toNullableNumber(conn.longest_active_query_seconds)
|
|
436
|
+
},
|
|
437
|
+
bufferCache: {
|
|
438
|
+
hitRatioPct: toNullableNumber(cache.hit_ratio_pct),
|
|
439
|
+
blocksHit: Number(cache.blks_hit),
|
|
440
|
+
blocksRead: Number(cache.blks_read)
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
} finally {
|
|
444
|
+
client.release();
|
|
445
|
+
}
|
|
446
|
+
}
|
|
386
447
|
async getStoredProcedures(schema, routineType) {
|
|
387
448
|
if (!this.pool) {
|
|
388
449
|
throw new Error("Not connected to database");
|
|
@@ -508,24 +569,12 @@ var PostgresConnector = class _PostgresConnector {
|
|
|
508
569
|
await client.query("ROLLBACK");
|
|
509
570
|
} catch {
|
|
510
571
|
}
|
|
511
|
-
console.error(`[PostgreSQL executeSQL] ERROR: ${error.message}`);
|
|
512
|
-
console.error(`[PostgreSQL executeSQL] SQL: ${processedStatement}`);
|
|
513
|
-
if (parameters && parameters.length > 0) {
|
|
514
|
-
console.error(`[PostgreSQL executeSQL] Parameters: ${JSON.stringify(parameters)}`);
|
|
515
|
-
}
|
|
516
572
|
throw error;
|
|
517
573
|
}
|
|
518
574
|
}
|
|
519
575
|
let result;
|
|
520
576
|
if (parameters && parameters.length > 0) {
|
|
521
|
-
|
|
522
|
-
result = await client.query(processedStatement, parameters);
|
|
523
|
-
} catch (error) {
|
|
524
|
-
console.error(`[PostgreSQL executeSQL] ERROR: ${error.message}`);
|
|
525
|
-
console.error(`[PostgreSQL executeSQL] SQL: ${processedStatement}`);
|
|
526
|
-
console.error(`[PostgreSQL executeSQL] Parameters: ${JSON.stringify(parameters)}`);
|
|
527
|
-
throw error;
|
|
528
|
-
}
|
|
577
|
+
result = await client.query(processedStatement, parameters);
|
|
529
578
|
} else {
|
|
530
579
|
result = await client.query(processedStatement);
|
|
531
580
|
}
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
SQLRowLimiter,
|
|
6
6
|
closeQuietly
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-S2V6RZ3C.js";
|
|
8
8
|
import {
|
|
9
9
|
ConnectorRegistry,
|
|
10
10
|
SafeURL,
|
|
@@ -339,15 +339,8 @@ var SQLiteConnector = class _SQLiteConnector {
|
|
|
339
339
|
}
|
|
340
340
|
if (isReadStatement) {
|
|
341
341
|
if (parameters && parameters.length > 0) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
return { rows, rowCount: rows.length };
|
|
345
|
-
} catch (error) {
|
|
346
|
-
console.error(`[SQLite executeSQL] ERROR: ${error.message}`);
|
|
347
|
-
console.error(`[SQLite executeSQL] SQL: ${processedStatement}`);
|
|
348
|
-
console.error(`[SQLite executeSQL] Parameters: ${JSON.stringify(parameters)}`);
|
|
349
|
-
throw error;
|
|
350
|
-
}
|
|
342
|
+
const rows = this.prepare(processedStatement).all(...parameters);
|
|
343
|
+
return { rows, rowCount: rows.length };
|
|
351
344
|
} else {
|
|
352
345
|
const rows = this.prepare(processedStatement).all();
|
|
353
346
|
return { rows, rowCount: rows.length };
|
|
@@ -355,14 +348,7 @@ var SQLiteConnector = class _SQLiteConnector {
|
|
|
355
348
|
} else {
|
|
356
349
|
let result;
|
|
357
350
|
if (parameters && parameters.length > 0) {
|
|
358
|
-
|
|
359
|
-
result = this.prepare(processedStatement).run(...parameters);
|
|
360
|
-
} catch (error) {
|
|
361
|
-
console.error(`[SQLite executeSQL] ERROR: ${error.message}`);
|
|
362
|
-
console.error(`[SQLite executeSQL] SQL: ${processedStatement}`);
|
|
363
|
-
console.error(`[SQLite executeSQL] Parameters: ${JSON.stringify(parameters)}`);
|
|
364
|
-
throw error;
|
|
365
|
-
}
|
|
351
|
+
result = this.prepare(processedStatement).run(...parameters);
|
|
366
352
|
} else {
|
|
367
353
|
result = this.prepare(processedStatement).run();
|
|
368
354
|
}
|