Skip to content

Commit 94b5a66

Browse files
committed
chore: sqlite
1 parent 819d240 commit 94b5a66

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/utils/startup-table.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { SourceConfig } from "../types/config.js";
2+
import { parseConnectionInfoFromDSN, getDefaultPortForType } from "./dsn-obfuscate.js";
23

34
/**
45
* Information about a source and its tools for display
@@ -32,24 +33,28 @@ const BOX = {
3233
* Parse host and database from source config
3334
*/
3435
function parseHostAndDatabase(source: SourceConfig): { host: string; database: string } {
35-
// If DSN is provided, parse it
36+
// If DSN is provided, use the proper DSN parser
3637
if (source.dsn) {
37-
try {
38-
const url = new URL(source.dsn);
39-
const host = url.port ? `${url.hostname}:${url.port}` : url.hostname;
40-
const database = url.pathname.replace(/^\//, "") || "";
41-
return { host, database };
42-
} catch {
43-
return { host: "unknown", database: "" };
38+
const parsed = parseConnectionInfoFromDSN(source.dsn);
39+
if (parsed) {
40+
// For SQLite, there's no host - just show the database path
41+
if (parsed.type === "sqlite") {
42+
return { host: "", database: parsed.database || ":memory:" };
43+
}
44+
// For other databases, construct host:port string
45+
const port = parsed.port || getDefaultPortForType(parsed.type!);
46+
const host = port ? `${parsed.host}:${port}` : parsed.host || "";
47+
return { host, database: parsed.database || "" };
4448
}
49+
return { host: "unknown", database: "" };
4550
}
4651

4752
// Otherwise use individual connection params
4853
const host = source.host
4954
? source.port
5055
? `${source.host}:${source.port}`
5156
: source.host
52-
: "localhost";
57+
: "";
5358
const database = source.database || "";
5459

5560
return { host, database };
@@ -88,7 +93,9 @@ export function generateStartupTable(sources: SourceDisplayInfo[]): string {
8893
const hostDbWidth = Math.max(
8994
24,
9095
...sources.map((s) => {
91-
const hostDb = s.database ? `${s.host}/${s.database}` : s.host;
96+
const hostDb = s.host
97+
? s.database ? `${s.host}/${s.database}` : s.host
98+
: s.database || "";
9299
return hostDb.length;
93100
})
94101
);
@@ -120,7 +127,9 @@ export function generateStartupTable(sources: SourceDisplayInfo[]): string {
120127
// Source header row
121128
const idType = fitString(`${source.id} (${source.type})`, idTypeWidth);
122129
const hostDb = fitString(
123-
source.database ? `${source.host}/${source.database}` : source.host,
130+
source.host
131+
? source.database ? `${source.host}/${source.database}` : source.host
132+
: source.database || "",
124133
hostDbWidth
125134
);
126135

0 commit comments

Comments
 (0)