Open
Description
Overview
Add ODBC (Open Database Connectivity) support to SQLx to enable connections to any ODBC-compliant database while maintaining SQLx's core principles of type safety, async-first design, and compile-time checked queries.
Motivation
- Support databases not directly supported by SQLx (Oracle, DB2, etc.)
- Enable enterprise adoption where ODBC is a requirement
- Provide a unified interface for legacy databases and data warehouses
- Leverage existing ODBC infrastructure in enterprise environments
Architecture
1. Core Components
Database Driver
- New
Odbc
struct implementingDatabase
trait - Associated types:
OdbcConnection
,OdbcRow
,OdbcColumn
,OdbcValue
, etc. - Integration with SQLx's
Any
driver system - Connection pooling via
OdbcPool
Async Implementation
- Either use a thread pool for handling synchronous ODBC calls or implement missing async features in https://github.com/pacman82/odbc-api
- Support for the tokio runtime (the driver can be disabled on other runtimes)
- Efficient connection and statement caching
- Safe resource management across async boundaries
Type System
- Implement all the required traits on base types to be able to pass them to odbc
- NULL handling and optional types
Implementation Plan
Phase 1: Foundation
- Basic ODBC driver structure with stub implementation (
todo!
) - Test infrastructure
- Add the new driver to CI
Phase 2: Features
- Query execution and prepared statements
- Connection pooling
Phase 3: Integration
- Any driver support
- Documentation and examples
- Migration guides
- Performance optimization
Technical Considerations
Safety & Performance
- Efficient async/sync boundary handling
- Connection pooling optimization
- Resource cleanup guarantees
Compatibility
- Support for major ODBC driver managers
- Cross-platform compatibility
- Multiple ODBC versions
- TLS/SSL support
Feature Flags
[dependencies]
sqlx = { version = "...", features = ["odbc"] }
# Optional features
sqlx = { version = "...", features = ["odbc-native", "odbc-vendored"] }
Testing Strategy
- Unit tests for core functionality
- Integration tests with multiple databases
- Cross-platform compatibility testing
- Performance benchmarking
Documentation
- Connection string format and options
- Type mapping reference
- Migration guides
- Best practices and examples
This implementation would make SQLx more versatile while maintaining its high standards for safety, performance, and developer experience. The ODBC support would particularly benefit enterprise users and those working with legacy databases.