digital-society-coop / axum-sqlx-tx

Request-scoped sqlx transactions for axum
MIT License
45 stars 11 forks source link

Switch to sqlx::any following Sqlx 0.7 release #39

Open dave42w opened 5 months ago

dave42w commented 5 months ago

It seems that Sqlx 0.7 included sorting out the sqlx::any module so that it works usefully. See this comment last comment on Compiling with QueryBuilder::push_values based on AnyPool reports an error #1978

I have tested this on the example.rs and it works (I had to do some updates to cargo.toml versions).

If this is correct then my hope is that neither the Tx type nor the pool have to be database specific

We should be able to replace

type Tx = axum_sqlx_tx::Tx<sqlx::Sqlite>;
``
with

type Tx = axum_sqlx_tx::Tx;


and
let pool = sqlx::SqlitePool::connect("sqlite::memory:").await?;
with
let db_url = "sqlite::memory:";
let pool = sqlx::AnyPool::connect(db_url).await?;


This would significantly simplify my code.
connec commented 2 months ago

I've never worked with sqlx::Any, I'll try to explore that at some point. It might be a sensible "quickstart" default.

I would still want it to be possible to specify the generic for the database, since there are sometimes driver-specific methods (e.g. PgConnection::copy_in_raw) which would be impossible to access from an AnyConnection, as far as I can tell.