ODBC Fast - Rust-native ODBC for Dart

CI E2E Multi-DB codecov

odbc_fast is an ODBC data access package for Dart backed by an in-repo Rust engine over dart:ffi.

Current package version: 5.0.5. See the changelog for release history and 4.x migration notes.

Installation

Use Dart 3.6 or later in the 3.x line. Install the ODBC driver for your database and configure its connection string or DSN. Windows provides the ODBC Driver Manager. On Linux, install unixODBC. See the build guide for native library resolution and source builds.

dependencies:
  odbc_fast: ^5.0.5

Run dart pub get. Application code imports package:odbc_fast/odbc_fast.dart. For direct FFI access, use package:odbc_fast/odbc_fast_native.dart.

Quick Start (High-level service)

For a general-purpose async application, select OdbcUsageProfile.balanced explicitly. Calling initialize() without a profile selects the synchronous legacy preset. Replace DSN=MyDsn with your configured connection string.

import 'dart:io';

import 'package:odbc_fast/odbc_fast.dart';

void reportFailure(Object error) {
  exitCode = 1;
  if (error is OdbcError) {
    stderr.writeln('${error.code.name}: ${error.userMessage}');
  } else {
    stderr.writeln('The database operation could not be completed.');
  }
}

Future<void> main() async {
  AppLogger.initialize();
  final locator = ServiceLocator();
  try {
    locator.initialize(profile: OdbcUsageProfile.balanced);
    final service = locator.service;
    (await service.initialize()).getOrThrow();
    final connection = (await service.connect(
      'DSN=MyDsn',
      options: locator.recommendedConnectionOptions,
    )).getOrThrow();
    try {
      final result = (await locator.queryService.executeQueryParamValues(
        connection.id,
        'SELECT CAST(? AS INTEGER) AS id',
        const [ParamValueInt32(1)],
      )).getOrThrow();
      final id = result.reader().scalar<int>('id', ignoreCase: true);
      stdout.writeln('rows=${result.rowCount} id=$id');
    } finally {
      final disconnected = await service.disconnect(connection.id);
      disconnected.fold((_) {}, reportFailure);
    }
  } on Object catch (error, stackTrace) {
    reportFailure(error);
    AppLogger.severe('Database operation failed', error, stackTrace);
  } finally {
    locator.shutdown();
  }
}

The CLI boundary catches getOrThrow() failures, prints the presentation message and keeps technical diagnostics in the logger. Disconnect is checked separately, and shutdown runs after initialization or query failures. Adapt the sample SELECT for your driver's dialect; connection settings stay outside SQL parameter values. Runnable version: quick_start_balanced_demo.dart.

Choosing a query API

Workload API and usage
A bounded result consumed by row Use executeQueryParamValues with bound values. Reuse one result.reader() for named lookups.
A large scan consumed by row Process each batch from streamQuery before requesting more. Retaining every batch also retains its rows.
Processing values by column Use executeQueryColumnarParamValues or streamQueryColumnar and resolve the typed columns once per batch. Typed column example
Several result sets Use executeQueryMultiParamValues for bounded results or streamQueryMultiBatches for incremental processing. Multi-result batches
Repeated SQL or batch writes Prepare once and bind each set of values. For bulk inserts, send bounded batches and compare parallel execution on your own driver. Bulk insert example

The performance guide explains fetch sizes, worker profiles and how to measure the path your application actually uses.

Transactions and recovery

Use the transaction helper for local transactions. For distributed transactions, check the driver's XA capabilities before using runInXaTransaction. XA example

Reconnection restores the connection for subsequent operations. Enable query replay only for operations that are safe to repeat. If a timeout or completion failure leaves OdbcError.details.outcomeUnknown set, reconcile the transaction outcome before retrying a write.

Documentation

Support

If this project helps you, consider supporting the maintainer via Pix:

  • cesar_carlos@msn.com

License

MIT (see LICENSE).

Libraries

application/repositories/odbc_repository_extensions
application/services/i_admin_service
application/services/i_dialect_service
application/services/i_odbc_service
application/services/i_pool_service
application/services/i_query_service
application/services/i_query_service_extensions
application/services/i_transaction_service
application/services/odbc_admin_service
application/services/odbc_dialect_service
application/services/odbc_pool_service
application/services/odbc_query_service
application/services/odbc_service
application/services/odbc_transaction_service
application/telemetry/telemetry_odbc_admin_decorator
application/telemetry/telemetry_odbc_decorators
application/telemetry/telemetry_odbc_operations
application/telemetry/telemetry_odbc_pool_decorator
application/telemetry/telemetry_odbc_query_decorator
application/telemetry/telemetry_odbc_service_decorator
application/telemetry/telemetry_odbc_service_decorator_admin_forwards
application/telemetry/telemetry_odbc_service_decorator_base
application/telemetry/telemetry_odbc_service_decorator_dialect_forwards
application/telemetry/telemetry_odbc_service_decorator_pool_forwards
application/telemetry/telemetry_odbc_service_decorator_query_forwards
application/telemetry/telemetry_odbc_service_decorator_transaction_forwards
application/telemetry/telemetry_odbc_transaction_decorator
core/di/async_backpressure_mode
core/di/odbc_profile_async_defaults
core/di/resolved_odbc_usage_profile
core/di/service_locator
core/utils/logger
domain/builders/connection_string_builder
domain/entities/async_worker_pool_stats
domain/entities/column_metadata
domain/entities/connection
domain/entities/connection_options
domain/entities/dart_side_metrics
domain/entities/directed_param
domain/entities/driver_capabilities
domain/entities/isolation_level
domain/entities/odbc_event
domain/entities/odbc_metrics
domain/entities/odbc_usage_profile
domain/entities/odbc_usage_profile_preset
domain/entities/param_value
domain/entities/pool_options
domain/entities/pool_state
domain/entities/prepared_statement_config
domain/entities/query_result
domain/entities/query_result_multi
domain/entities/result_encoding
domain/entities/retry_options
domain/entities/savepoint_dialect
domain/entities/schema_info
domain/entities/statement_options
domain/entities/transaction_access_mode
domain/entities/typed_columnar_result
domain/entities/xa_transaction_handle
domain/entities/xid
domain/errors/odbc_error
domain/errors/odbc_error_boundary
domain/errors/odbc_error_details
domain/errors/telemetry_error
Domain errors for telemetry operations.
domain/helpers/param_value_conversion
domain/helpers/query_result_access
domain/helpers/retry_helper
domain/helpers/typed_columnar_converter
domain/repositories/i_admin_repository
domain/repositories/i_connection_repository
domain/repositories/i_pool_repository
domain/repositories/i_query_repository
domain/repositories/i_transaction_repository
domain/repositories/itelemetry_repository
domain/repositories/odbc_repository
domain/services/itelemetry_service
domain/services/simple_telemetry_service
domain/telemetry/entities
domain/types/param_direction
domain/types/sql_data_type
infrastructure/native/async_native_odbc_connection
infrastructure/native/audit/async_odbc_audit_logger
infrastructure/native/audit/odbc_audit_logger
infrastructure/native/bindings/columnar_decompress.g
infrastructure/native/bindings/ffi_buffer_helper
infrastructure/native/bindings/ffi_copy_budget
Internal copy/allocation counters for FFI hot-path regression tests.
infrastructure/native/bindings/library_loader
infrastructure/native/bindings/native_byte_view
infrastructure/native/bindings/odbc_bindings
infrastructure/native/bindings/odbc_native
infrastructure/native/bindings/opentelemetry_ffi
infrastructure/native/bindings/sql_pointer_cache
infrastructure/native/columnar_decompress_ffi
infrastructure/native/driver_capabilities
infrastructure/native/driver_capabilities_mapper
infrastructure/native/driver_capabilities_v3
infrastructure/native/errors/async_error
infrastructure/native/errors/native_call_context
infrastructure/native/errors/native_cleanup
infrastructure/native/errors/native_execution_stage
infrastructure/native/errors/odbc_error_translator
infrastructure/native/errors/structured_error
infrastructure/native/isolate/error_recovery
infrastructure/native/isolate/message_protocol
infrastructure/native/isolate/worker_failure_snapshot
infrastructure/native/isolate/worker_isolate
infrastructure/native/native_bcp_runtime
infrastructure/native/native_odbc_connection
infrastructure/native/odbc_backend
infrastructure/native/odbc_connection_backend
infrastructure/native/pool_options
infrastructure/native/protocol/binary_protocol
infrastructure/native/protocol/binary_protocol_cell_decode
infrastructure/native/protocol/binary_protocol_columnar
infrastructure/native/protocol/binary_protocol_constants
infrastructure/native/protocol/binary_protocol_reader
infrastructure/native/protocol/binary_protocol_row_major
infrastructure/native/protocol/binary_protocol_trailers
infrastructure/native/protocol/binary_protocol_types
infrastructure/native/protocol/bulk_insert_builder
infrastructure/native/protocol/columnar_v2_flags
infrastructure/native/protocol/directed_param
infrastructure/native/protocol/frame_accumulator
infrastructure/native/protocol/lazy_string
infrastructure/native/protocol/multi_result_parser
infrastructure/native/protocol/multi_result_stream_decoder
infrastructure/native/protocol/named_parameter_parser
infrastructure/native/protocol/odbc_type
infrastructure/native/protocol/param_value
infrastructure/native/protocol/protocol_ascii_parse
infrastructure/native/protocol/protocol_byte_accumulator
infrastructure/native/protocol/stream_frame_decode
infrastructure/native/protocol/typed_columnar_converter
infrastructure/native/streaming_query
infrastructure/native/telemetry/console
infrastructure/native/telemetry/telemetry_buffer
infrastructure/native/wrappers/catalog_query
infrastructure/native/wrappers/connection_pool
infrastructure/native/wrappers/prepared_statement
infrastructure/native/wrappers/transaction_completion_status
infrastructure/native/wrappers/transaction_handle
infrastructure/native/wrappers/xa_transaction_handle
infrastructure/repositories/odbc_repository_impl
infrastructure/repositories/repository_state
infrastructure/repositories/runners/multi_stream_coalescer
infrastructure/repositories/runners/odbc_admin_runner
infrastructure/repositories/runners/odbc_bulk_runner
infrastructure/repositories/runners/odbc_catalog_runner
infrastructure/repositories/runners/odbc_connection_runner
infrastructure/repositories/runners/odbc_ffi_dispatch
infrastructure/repositories/runners/odbc_pool_runner
infrastructure/repositories/runners/odbc_query_multi_runner
infrastructure/repositories/runners/odbc_query_prepared_runner
infrastructure/repositories/runners/odbc_query_runner
infrastructure/repositories/runners/odbc_query_sync_runner
infrastructure/repositories/runners/odbc_repository_types
infrastructure/repositories/runners/odbc_result_parser
infrastructure/repositories/runners/odbc_stream_runner
infrastructure/repositories/runners/odbc_transaction_runner
infrastructure/repositories/runners/query_timeout_helpers
infrastructure/repositories/runners/stream_async_lifecycle_runner
infrastructure/repositories/runners/stream_capability_policy
infrastructure/repositories/runners/stream_chunk_decoder
infrastructure/repositories/runners/stream_columnar_runner
infrastructure/repositories/runners/stream_error_mapper
infrastructure/repositories/runners/stream_query_runner
infrastructure/repositories/telemetry_repository
odbc_fast
Enterprise-grade ODBC data platform for Dart with a Rust native engine.
odbc_fast_native
Opt-in exports for native FFI, repository implementation, and other infrastructure surfaces.