launchbadge / sqlx

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite.
Apache License 2.0
13.24k stars 1.25k forks source link

AnyKind is an empty enum #2582

Open lovasoa opened 1 year ago

lovasoa commented 1 year ago

Hi ! I use sqlx in sqlpage, and was trying out sqlx v0.7, but I'm running into errors.

It is not mentioned in the changelog, but it looks like AnyKind is now the empty enum, and AnyConnectOptions has lost its kind method.

Given an AnyConnectOptions, how do I now which database driver it will use ?

abonander commented 1 year ago

AnyKind should have been deleted as sqlx-core no longer has hardcoded knowledge of the exact set of drivers that are available. This is to allow our planned SQLx Pro offering to inject additional drivers without sqlx-core needing to know about them.

AnyConnectOptions exposes the database URL: https://docs.rs/sqlx/latest/sqlx/any/struct.AnyConnectOptions.html#structfield.database_url

You can match on the .scheme() using Database::URL_SCHEMES: https://docs.rs/sqlx/latest/sqlx/trait.Database.html#associatedconstant.URL_SCHEMES

lovasoa commented 1 year ago

I understand the need to monetize, but this makes the developer experience significantly worse for no added benefit :disappointed: And there isn't a single scheme string for each database to easily match against.

Maybe we could reinstate the kind method and the AnyKind enum (avoiding a new breaking change to delete it), and just add an Other(String) variant to it, to make it possible to support arbitrary additional runtime drivers ?

abonander commented 1 year ago

This feedback would have been much more actionable during the nearly six months that 0.7 was in alpha.

lovasoa commented 1 year ago

Yes, I understand how annoying it must be to get this feedback now.

I did quickly try 0.7 before, but seeing how many updates it required in client code, I decided not to invest time in it, prioritizing other things that added more value to my project.

iamsauravsharma commented 1 year ago

Another solution is to use AnyConnection .backend_name() https://docs.rs/sqlx/latest/sqlx/struct.AnyConnection.html#method.backend_name which only returns &str. For sqlx provided database driver they are equal to Database::NAME const https://docs.rs/sqlx/latest/sqlx/trait.Database.html#associatedconstant.NAME. I was also facing same issue so I decided to use backend name &str to determine database type. You can easily create AnyConnection from AnyConnectOptions

lovasoa commented 1 year ago

Thanks, that sounds useful ! However, that requires opening an actual connection to the database, right?

iamsauravsharma commented 1 year ago

Yes, It requires opening actual connection to database. I am using connection later so I have no issue.

lovasoa commented 1 year ago

This does not enchant me, but I forked sqlx 0.6 as sqlx-oldapi, and updated all dependencies, in order to be able to keep using the sqlx 0.6 API safely without deprecated subdependencies.