sqlx-exasol
A database driver for Exasol to be used with the Rust sqlx framework, based on the Exasol Websocket API.
Inspired by Py-Exasol and based on the (now archived) rust-exasol sync driver.
MSRV: 1.70
Note
The crate's version resembles the
sqlxversion it is based on so that managing dependencies is simpler.With that in mind, please favor using a fixed version of
sqlxandsqlx-exasolinCargo.tomlto avoid issues, such as:= "=0.7.3" = "=0.7.3"
Crate Features flags
etl- enables the usage ETL jobs without TLS encryption.etl_native_tls- enables theetlfeature and adds TLS encryption throughnative-tls1etl_rustls- enables theetlfeature and adds TLS encryption throughrustls1compression- enables compression support (for both connections and ETL jobs)uuid- enables support for theuuidcratechrono- enables support for thechronocrate typesrust_decimal- enables support for therust_decimaltypemigrate- enables the use of migrations and testing (just like in othersqlxdrivers).
Comparison to native sqlx drivers
Since the driver is used through sqlx and it implements the interfaces there, it can do all
the drivers shipped with sqlx do, with some caveats:
-
Limitations
-
Additions
- array-like parameter binding in queries, thanks to the columnar nature of the Exasol database
- performant & parallelizable ETL IMPORT/EXPORT jobs in CSV format through HTTP Transport
Connection string
The connection string is expected to be an URL with the exa:// scheme, e.g:
exa://sys:exasol@localhost:8563.
Examples
Using the driver for regular database interactions:
use env;
use *;
let pool = connect.await?;
let mut con = pool.acquire.await?;
query
.execute
.await?;
Array-like parameter binding, also featuring the [ExaIter] adapter.
An important thing to note is that the parameter sets must be of equal length,
otherwise an error is thrown:
use ;
use *;
let pool = connect.await?;
let mut con = pool.acquire.await?;
let params1 = vec!;
let params2 = from;
query
.bind
.bind
.execute
.await?;
An EXPORT - IMPORT ETL data pipe.
use env;
use ;
use ;
async
let pool = connect.await?;
let mut con1 = pool.acquire.await?;
let mut con2 = pool.acquire.await?;
// Build EXPORT job
let = new
.build
.await?;
// Build IMPORT job
let = new.build.await?;
// Use readers and writers in some futures
let transport_futs = zip.map;
// Execute the EXPORT and IMPORT query futures along with the worker futures
let = try_join3
.await?;
assert_eq!;
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Contributing
Contributions to this repository, unless explicitly stated otherwise, will be considered dual-licensed under MIT and Apache 2.0.
Bugs/issues encountered can be opened here
Footnotes
1: There is unfortunately no way to automagically choose a crate's feature flags based on its dependencies feature flags, so the TLS backend has
to be manually selected. While nothing prevents you from using, say native-tls with sqlx and rustls with Exasol ETL jobs, it might be best to avoid compiling
two different TLS backends. Therefore, consider choosing the sqlx and sqlx-exasol feature flags in a consistent manner.
2: The sqlx API powering the compile-time query checks and the sqlx-cli tool is not public. Even if it were, the drivers that are incorporated into sqlx are hardcoded in the part of the code that handles the compile-time driver decision logic. The main problem from what I can gather is that there's no easy way of defining a plugin system in Rust at the moment, hence the hardcoding.
3: Exasol has no advisory or database locks and simple, unnested, transactions are unfortunately not enough to define a mechanism so that concurrent migrations do not collide. This does not pose a problem when migrations are run sequentially or do not act on the same database objects.
4: Exasol does not provide the information of whether a column is nullable or not, so the driver cannot implicitly decide whether a NULL value can go into a certain database column or not until it actually tries.
5: I didn't even know this (as I never even thought of doing it), but sqlx allows running multiple queries in a single statement. Due to limitations with the websocket API this driver is based on, sqlx-exasol can only run one query at a time. This is only circumvented in migrations through a somewhat limited, convoluted and possibly costly workaround that tries to split queries by ;, which does not make it applicable for runtime queries at all.