Support creating a `sea_orm::Database` from any `sqlx::Executor` for example from an `sqlx::any::AnyPool`.
Currently sqlx allows you to create a connection pool with custom pool options based on e.g.: the kind of database (extracted from the url) or anything else.
e.g.:
let mut connect_options = sqlx::any::AnyConnectOptions::from_str(&database_url).expect("Incorrect database url!");
let mut pool_options = sqlx::any::AnyPoolOptions::new();
if std::matches!(connect_options.kind(), AnyKind::Sqlite) {
let sqlite_connect_options = SqliteConnectOptions::from_str(&database_url).unwrap()
.create_if_missing(true);
connect_options = sqlite_connect_options.into();
pool_options = pool_options.max_connections(1);
}
let kind = connect_options.kind();
log::info!("Connecting to the database...");
let mut pool = pool_options.connect_with(connect_options).await.expect("Unable to connect to the database!");
(I know that the sqlite create_if_missing option could be configured from the database url as well).
The user should have the ability to create and setup their own connection using sqlx. SeaQL should allow creating sea_orm::Database not just from a database url string but also from any sqlx::Executor.
I understand that SeaQL needs to know the kind of database to know which flavor of SQL to generate, but
- This could be something that we could allow the user to specify along with giving an
sqlx::Executor. - In the next release
sqlx::AnyPoolwill have anany_kindmethod for getting the database kind, so that will be usefull and can be used to get the underlying database type.
Hey @05storm26, I wonder what is the use case for you to convert any sqlx::Executor into sea_orm::Database?
Seems Pool::any_kind() have been released today.
https://github.com/launchbadge/sqlx/releases/tag/v0.5.10
SeaORM will not be able to support AnyPool