Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support creating a sea_orm::Database from any sqlx::Executor for example from an sqlx::any::AnyPool. #398

Closed
05storm26 opened this issue Dec 22, 2021 · 3 comments

Comments

@05storm26
Copy link

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

  1. This could be something that we could allow the user to specify along with giving an sqlx::Executor.
  2. In the next release sqlx::AnyPool will have an any_kind method for getting the database kind, so that will be usefull and can be used to get the underlying database type.
@billy1624
Copy link
Member

Hey @05storm26, I wonder what is the use case for you to convert any sqlx::Executor into sea_orm::Database?

@billy1624
Copy link
Member

Seems Pool::any_kind() have been released today.
https://github.com/launchbadge/sqlx/releases/tag/v0.5.10

@tyt2y3
Copy link
Member

tyt2y3 commented Feb 21, 2023

SeaORM will not be able to support AnyPool

@tyt2y3 tyt2y3 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants