MCPcopy Create free account
hub / github.com/bytebase/dbhub / parseHostAndDatabase

Function parseHostAndDatabase

src/utils/startup-table.ts:35–64  ·  view source on GitHub ↗

* Parse host and database from source config

(source: SourceConfig)

Source from the content-addressed store, hash-verified

33 * Parse host and database from source config
34 */
35function parseHostAndDatabase(source: SourceConfig): { host: string; database: string } {
36 // If DSN is provided, use the proper DSN parser
37 if (source.dsn) {
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 if (!parsed.host) {
46 return { host: "", database: parsed.database || "" };
47 }
48 const port = parsed.port ?? getDefaultPortForType(parsed.type!);
49 const host = port ? `${parsed.host}:${port}` : parsed.host;
50 return { host, database: parsed.database || "" };
51 }
52 return { host: "unknown", database: "" };
53 }
54
55 // Otherwise use individual connection params
56 const host = source.host
57 ? source.port
58 ? `${source.host}:${source.port}`
59 : source.host
60 : "";
61 const database = source.database || "";
62
63 return { host, database };
64}
65
66/**
67 * Generate a horizontal line of specified width

Callers 1

buildSourceDisplayInfoFunction · 0.85

Calls 2

getDefaultPortForTypeFunction · 0.85

Tested by

no test coverage detected