* Parse host and database from source config
(source: SourceConfig)
| 33 | * Parse host and database from source config |
| 34 | */ |
| 35 | function 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 |
no test coverage detected