Skip to content

Add ODBC Support to SQLx-oldapi #10

Open
@lovasoa

Description

@lovasoa

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

  1. Support databases not directly supported by SQLx (Oracle, DB2, etc.)
  2. Enable enterprise adoption where ODBC is a requirement
  3. Provide a unified interface for legacy databases and data warehouses
  4. Leverage existing ODBC infrastructure in enterprise environments

Architecture

1. Core Components

Database Driver

  • New Odbc struct implementing Database 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

  1. Unit tests for core functionality
  2. Integration tests with multiple databases
  3. Cross-platform compatibility testing
  4. Performance benchmarking

Documentation

  1. Connection string format and options
  2. Type mapping reference
  3. Migration guides
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions