JDBC string support

This commit is contained in:
eelke 2025-08-31 10:22:08 +02:00
parent 1d53ca2fc2
commit 0090f39910
7 changed files with 396 additions and 28 deletions

View file

@ -2,20 +2,23 @@
This document tracks the plan for supporting multiple PostgreSQL connection string formats, converting between them, and mapping to/from a canonical model.
## Current Status (2025-08-30)
## Current Status (2025-08-31)
Implemented:
- Abstractions: `ConnStringFormat`, `HostEndpoint`, `ConnectionDescriptor`, `IConnectionStringCodec`, `IConnectionStringService`.
- Codecs:
- `LibpqCodec` (libpq): parse/format; multi-host; `sslmode`, `application_name`, `connect_timeout`; quoting/escaping; preserves extras.
- `NpgsqlCodec` (.NET/Npgsql): parse/format; alias recognition; multi-host with single or per-host ports; `SSL Mode`, `Application Name`, `Timeout`; double-quote rules; preserves extras.
- Tests for both codecs: parse, format, round-trip, edge quoting.
- `UrlCodec` (postgresql://): parse/format; userinfo, multi-host with per-host ports, IPv6 `[::1]` handling, database path, percent-decoding/encoding, common params mapping, preserves extras.
- Composite `ConnectionStringService` (detect + convert) composing Libpq, Npgsql, and Url codecs.
- Mapping helpers to/from `ServerConfiguration` (primary host/port, database, SSL mode) with sensible defaults.
- Tests:
- Unit tests for Libpq, Npgsql, and Url codecs (parse/format/round-trip/edge quoting and percent-encoding).
- ConnectionStringService detection/conversion tests.
- ServerConfiguration mapping tests.
Not yet implemented:
- URL (postgresql://) codec ✓
- JDBC (jdbc:postgresql://) codec
- Composite `ConnectionStringService` (detect + convert) ✓
- Mapping helpers to/from `ServerConfiguration`
## Updated Plan
@ -26,26 +29,26 @@ Not yet implemented:
- Npgsql codec (parse/format; aliases, multi-host/ports, quoting, ssl mode, timeout, extras). ✓
- URL (postgresql://) codec (parse/format; userinfo, host[:port], db, query params, percent-encoding). ✓
- JDBC (jdbc:postgresql://) codec (parse/format; hosts, ports, db, properties; URL-like semantics).
4. Composite conversion service:
- Implement `ConnectionStringService` composing codecs, detecting formats, converting via `ConnectionDescriptor`, and resolving alias priorities.
5. Mapping with application model:
- Add mapping utilities between `ConnectionDescriptor` and `ServerConfiguration` (primary host/port, db, SSL mode), with sensible defaults.
4. Composite conversion service. ✓
5. Mapping with application model. ✓
6. Validation and UX:
- Validation for malformed inputs & edge cases (mismatched host/port counts, invalid SSL mode, missing db/host, IPv6 bracket handling).
- Ensure sensitive fields (password) are masked in logs/preview.
- Validation for malformed inputs & edge cases (mismatched host/port counts, invalid SSL mode, missing db/host, IPv6 bracket handling). ✓
- Ensure sensitive fields (password) are masked in logs/preview). ✓
7. Tests:
- Unit tests for URL and JDBC codecs; composite service detect/convert; mapping functions; cross-format round-trips; edge cases (spaces, quotes, unicode, IPv6, percent-encoding).
- Unit tests for URL codec (parse/format/round-trip/percent-encoding). ✓
- Tests for composite service detect/convert; mapping functions; cross-format round-trips; edge cases (spaces, quotes, unicode, IPv6, percent-encoding). ✓
- Unit tests for JDBC codec.
8. Documentation:
- Keep this plan updated and enrich XML docs on codecs/service including alias mappings and quoting/escaping rules per format.
- Keep this plan updated and enrich XML docs on codecs/service including alias mappings and quoting/escaping rules per format. *
## Next Small Step
Implement the URL (postgresql://) codec with unit tests. Scope:
- Parse: `postgresql://[user[:password]@]host1[:port1][,hostN[:portN]]/[database]?param=value&...`
- Support percent-decoding for user, password, database, and query values.
- Handle IPv6 literals in `[::1]` form; allow multiple hosts with optional per-host ports.
- Map common params: `sslmode`, `application_name`, `connect_timeout` and preserve other query params in `Properties`.
- Format: Build a URL using percent-encoding where required; emit multi-hosts and parameters from `Properties` not already emitted.
- Tests: basic parse/format, quoting/percent-encoding, multi-host with mixed ports, round-trips.
Implement the JDBC (jdbc:postgresql://) codec with unit tests. Scope:
- Parse: `jdbc:postgresql://host1[:port1][,hostN[:portN]]/[database]?param=value&...`
- Support multiple hosts with optional per-host ports; IPv6 bracket handling.
- Recognize common properties (sslmode/SSL, applicationName, loginTimeout/connectTimeout) and preserve unrecognized properties.
- Ensure URL-like semantics consistent with UrlCodec percent-decoding/encoding.
- Format: Build JDBC URL from ConnectionDescriptor; emit multi-hosts and properties from `Properties` not already emitted.
- Tests: basic parse/format, multi-host with mixed ports, percent-encoding, round-trips; cross-format conversions via ConnectionStringService.
After that, implement the composite `ConnectionStringService` to detect/convert across libpq, Npgsql, and URL formats.
After that, consider minor documentation polish and any gaps in edge-case validation discovered while adding JDBC support.