Skip to content

feat: implement builder-based connection API with TLS support (v0.3.0)#40

Merged
bug-ops merged 4 commits intomainfrom
feature/builder-based-connection-api
Jan 29, 2026
Merged

feat: implement builder-based connection API with TLS support (v0.3.0)#40
bug-ops merged 4 commits intomainfrom
feature/builder-based-connection-api

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Jan 29, 2026

Summary

Implements Phase 7 of the builder-based connection API with comprehensive TLS/SSL support. This is a breaking change release (v0.3.0) that removes deprecated code and adds a modern builder pattern for connections and pools.

New Features

TlsConfig Class

Factory-based configuration for SSL/TLS connections:

  • TlsConfig.from_directory(path) - Load certificates from directory
  • TlsConfig.from_environment(env_var) - Load from environment variable
  • TlsConfig.from_certificate(pem_content) - Use PEM string directly
  • TlsConfig.with_system_roots() - Use system root certificates
  • TlsConfig.insecure() - Disable verification (development only)

Builder API

  • ConnectionBuilder - Programmatic connection configuration
  • AsyncConnectionBuilder - Async connections with builder pattern
  • ConnectionPoolBuilder - Pool configuration with TLS support
  • Automatic TLS detection for hdbsqls:// URL scheme

Python Integration

  • All builder classes registered in PyModule
  • Comprehensive type stubs in _core.pyi for IDE autocomplete
  • Export from pyhdb_rs and pyhdb_rs.aio packages
  • Security: no credential leaks in __repr__ or error messages

Breaking Changes

  • Removed statement_cache_size parameter from async connect() (deprecated since v0.2.x)
  • Removed TypedConnection<S> internal typestate implementation (unused, 270 lines)

Migration Guide

# Old API (still works)
conn = await connect("hdbsql://user:pass@host:30015")

# New builder API  
from pyhdb_rs import TlsConfig, ConnectionBuilder

conn = (ConnectionBuilder()
    .host("hana.example.com")
    .port(30015)
    .credentials("SYSTEM", "password")
    .tls(TlsConfig.with_system_roots())
    .build())

See CHANGELOG.md for complete migration details.

Implementation Details

  • Dual builder architecture:
    • Internal builder.rs - Typestate pattern for compile-time safety
    • Public py_builder.rs - Runtime validation for Python API
  • Security: No credential leaks in repr/errors
  • Quality: All clippy checks pass (strict mode), formatted with cargo +nightly fmt
  • Testing: 48 clippy warnings fixed, all unit tests pass

Documentation

  • ✅ Added v0.3.0 section to CHANGELOG.md
  • ✅ Updated README with TLS/SSL examples
  • ✅ Complete Python type stubs for IDE support
  • ✅ Docstrings for all public methods

Verification

# Rust checks
cargo +nightly fmt --check
cargo clippy --workspace --all-features -- -D warnings  
cargo nextest run --workspace

# Python checks
ruff check python/ tests/
ruff format --check python/ tests/

# Python imports
maturin develop
python -c "from pyhdb_rs import TlsConfig, ConnectionBuilder"
python -c "from pyhdb_rs.aio import AsyncConnectionBuilder"

Files Changed

  • Added: crates/hdbconnect-py/src/tls.rs (332 lines)
  • Added: crates/hdbconnect-py/src/connection/py_builder.rs (790 lines)
  • Deleted: crates/hdbconnect-py/src/connection/state.rs (270 lines)
  • Modified: lib.rs, pool.rs, wrapper.rs, Python files, docs

Stats: 14 files changed, 2359 insertions(+), 314 deletions(-)

Phase 7 Status

All acceptance criteria met:

  • ✅ Builder classes implemented with TLS support
  • ✅ PyModule registration complete
  • ✅ Type stubs and exports added
  • ✅ ConnectionPool TLS integration
  • ✅ Documentation updated (README, CHANGELOG, type stubs)
  • ✅ All clippy/fmt/test checks pass
  • ✅ Code review completed
  • ✅ Bloat analysis complete (minimal optimization opportunities found)

Related

  • Architecture plan: .local/plan/phase-7-builder-connection-api.md
  • Bloat analysis: .local/analysis/hdbconnect-py-bloat-analysis.md
  • Review report: .local/review/phase-7-code-review.md

Add comprehensive builder pattern for connections and pools with full TLS
configuration options. This is a breaking change release (v0.3.0) that
removes deprecated parameters and dead code.

Breaking Changes:
- Remove deprecated statement_cache_size parameter from async connect()
- Remove TypedConnection<S> (unused internal typestate implementation)

New Features:
- Add TlsConfig class with factory methods:
  - from_directory(path) - load certificates from directory
  - from_environment(env_var) - load from environment variable
  - from_certificate(pem_content) - use PEM string directly
  - with_system_roots() - use system root certificates
  - insecure() - disable verification (development only)
- Add ConnectionBuilder for programmatic connection configuration
- Add AsyncConnectionBuilder for async connections
- Add ConnectionPoolBuilder for pool configuration with TLS
- Automatic TLS detection for hdbsqls:// URL scheme
- Register all builder classes in PyModule
- Add comprehensive Python type stubs in _core.pyi
- Update README with TLS configuration examples

Implementation Details:
- PyConnectionBuilder/PyAsyncConnectionBuilder use runtime validation
- PyConnectionPoolBuilder supports TLS configuration
- Internal builder.rs typestate pattern retained for Rust code safety
- Python-facing builders provide ergonomic fluent API
- Security: no credential leaks in __repr__ or error messages
- All clippy checks pass with strict mode
- Code formatted with cargo +nightly fmt

Documentation:
- Add v0.3.0 section to CHANGELOG.md
- Document breaking changes and migration paths
- Add TLS/SSL Connections section to README
- Complete type stubs for IDE support

Phase 7 implementation complete.
@github-actions github-actions bot added enhancement New feature or request documentation Improvements or additions to documentation rust Pull requests that update rust code python pyo3 size/XL and removed enhancement New feature or request labels Jan 29, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jan 29, 2026

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
python/pyhdb_rs/aio/__init__.py 0.00% 2 Missing ⚠️
crates/hdbconnect-py/src/async_support/pool.rs 0.00% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #40      +/-   ##
==========================================
+ Coverage   72.24%   72.27%   +0.03%     
==========================================
  Files          38       38              
  Lines        6117     6114       -3     
==========================================
  Hits         4419     4419              
+ Misses       1698     1695       -3     
Files with missing lines Coverage Δ
...ates/hdbconnect-py/src/async_support/connection.rs 0.00% <ø> (ø)
crates/hdbconnect-py/src/connection/builder.rs 91.50% <ø> (+4.12%) ⬆️
crates/hdbconnect-py/src/connection/wrapper.rs 0.00% <ø> (ø)
crates/hdbconnect-py/src/lib.rs 0.00% <ø> (ø)
python/pyhdb_rs/__init__.py 75.00% <ø> (ø)
crates/hdbconnect-py/src/async_support/pool.rs 4.40% <0.00%> (ø)
python/pyhdb_rs/aio/__init__.py 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions bot added the enhancement New feature or request label Jan 29, 2026
Remove check_connection_valid helper function from async_support/common.rs
that was defined but never called. The is_valid() methods in AsyncPyConnection
and PooledConnection implement validation inline instead.

Impact:
- Removed ~20 lines (function + docs + test)
- No functional changes - function was never used
- All checks pass (cargo check, clippy)
@bug-ops bug-ops force-pushed the feature/builder-based-connection-api branch from 4cf7d80 to 2952140 Compare January 29, 2026 14:50
@github-actions github-actions bot added the tests label Jan 29, 2026
Phase 8 critical improvements based on connection API completeness audit:

## Bug Fixes

- **Fix database field ignored in typestate builder** (builder.rs:233-241)
  Previously self.database was stored but never passed to hdbconnect builder,
  causing database selection to fail silently in internal Rust API.

## New Features

### CursorHoldability Enum
- Add CursorHoldability for transaction control (NEW: cursor_holdability.rs)
- Variants: None, Commit, Rollback, CommitAndRollback
- Controls result set behavior across transaction boundaries
- Critical for applications reading results after committing other changes
- Integrated with:
  - ConnectionBuilder.cursor_holdability()
  - AsyncConnectionBuilder.cursor_holdability()
  - Python type stubs

### Network Group Parameter
- Add network_group for HANA Scale-Out and HA deployments
- Essential for multi-node routing and load balancing
- Integrated with:
  - ConnectionBuilder.network_group(group)
  - AsyncConnectionBuilder.network_group(group)
  - ConnectionPoolBuilder.network_group(group)
  - HanaConnectionManager for pool support

## Documentation

- Update CHANGELOG.md v0.3.0 section
- Add README sections:
  - Cursor Holdability usage with examples
  - High Availability configuration with network groups
- Complete Python type stubs (_core.pyi):
  - CursorHoldability enum
  - ConnectionPoolBuilder class (was missing)
  - All new builder methods

## Tests

- Update Python tests to use new features
- All validation passed:
  - cargo +nightly fmt --check ✓
  - cargo clippy --workspace --all-features -- -D warnings ✓
  - cargo check --workspace --all-features ✓
  - cargo deny check ✓
  - ruff check/format ✓

## Files Changed

New:
- crates/hdbconnect-py/src/cursor_holdability.rs (148 lines)

Modified:
- crates/hdbconnect-py/src/connection/builder.rs
- crates/hdbconnect-py/src/connection/py_builder.rs
- crates/hdbconnect-py/src/async_support/pool.rs
- crates/hdbconnect-py/src/lib.rs
- python/pyhdb_rs/_core.pyi
- CHANGELOG.md
- README.md
- Python tests (4 files)

Audit sources:
- .local/analysis/hdb-connection-completeness-audit.md
- .local/analysis/pool-over-engineering-analysis.md

All changes are additive - no new breaking changes beyond v0.3.0 already planned.
@bug-ops bug-ops force-pushed the feature/builder-based-connection-api branch from 736f29f to 8ddfcba Compare January 29, 2026 15:29
@github-actions github-actions bot removed the tests label Jan 29, 2026
Complete documentation update for v0.3.0 release with all new features
and refactored README using collapsible sections for better readability.

## Version Updates

- Bump version: 0.2.4 → 0.3.0
- Cargo.toml workspace version
- python/pyproject.toml

## README.md Enhancements (995 → 1031 lines, ~50% visual reduction)

**New sections:**
- Builder API (basic, TLS, URL overrides, async)
- TLS/SSL Connections (all 5 factory methods)
- Cursor Holdability (transaction control)
- High Availability & Scale-Out (network groups)
- Migration Guide (v0.2.x → v0.3.0)
- API Patterns & Best Practices

**Refactored with collapsible sections:**
Made 11 advanced sections collapsible using <details><summary> tags:
- Builder API advanced examples
- Polars integration
- TLS/SSL configuration
- Cursor holdability
- HA & Scale-Out
- Async support
- Migration guide
- API patterns
- Error handling
- Connection URL format
- Arrow ecosystem

**Kept visible:**
- Project description + badges
- Features list
- Installation
- Quick start (DB-API, Builder basics)
- Bottom sections (MSRV, Contributing, License)

Result: More scannable README while maintaining full content accessibility

## Python Examples (7 new files in examples/python/)

1. builder_basic.py - Basic ConnectionBuilder usage
2. builder_tls.py - All 5 TlsConfig methods
3. builder_async.py - AsyncConnectionBuilder
4. pool_builder.py - ConnectionPoolBuilder
5. cursor_holdability.py - All 4 CursorHoldability variants
6. ha_network_group.py - HA/Scale-Out configurations
7. migration_guide.py - v0.2.x → v0.3.0 migration
8. README.md - Examples overview

## Jupyter Notebooks

**Updated existing:**
- 01_quickstart.ipynb - Added Builder API section (5 new cells)

**Created new (4 notebooks):**
- 05_builder_api.ipynb - Comprehensive builder guide
- 06_tls_configuration.ipynb - All TLS methods + best practices
- 07_connection_pooling.ipynb - ConnectionPoolBuilder usage
- 08_advanced_features.ipynb - CursorHoldability + network groups

**Updated:**
- examples/notebooks/README.md - Complete rewrite for v0.3.0

## Documentation Quality

- All documentation in English
- Professional, expert tone
- Proper GitHub callouts ([!TIP], [!WARNING], [!IMPORTANT])
- Comprehensive code examples
- Production-ready patterns
- Mobile-friendly collapsible sections

## Files Summary

Modified (7):
- Cargo.toml, Cargo.lock
- README.md
- python/pyproject.toml, python/uv.lock
- examples/notebooks/01_quickstart.ipynb
- examples/notebooks/README.md

Added (12):
- 4 Jupyter notebooks (05-08)
- 7 Python examples
- examples/python/README.md

All examples tested and working. Documentation ready for v0.3.0 release.
@github-actions github-actions bot added dependencies Pull requests that update a dependency file examples Example code and Jupyter notebooks labels Jan 29, 2026
@bug-ops bug-ops merged commit d463dac into main Jan 29, 2026
35 checks passed
@bug-ops bug-ops deleted the feature/builder-based-connection-api branch January 29, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation enhancement New feature or request examples Example code and Jupyter notebooks pyo3 python rust Pull requests that update rust code size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants