sea-orm icon indicating copy to clipboard operation
sea-orm copied to clipboard

Allow user to retrieve connection from underlining pool

Open Sytten opened this issue 3 years ago • 5 comments

Motivation

For some specific reason (related to us still using sqlx migrations), I happen to need an sqlx connection from the pool which I don't seem to be able to get. It would be nice to have a feature that allows us to get it.

Proposed Solutions

  1. Add a crate feature (i-hop-in-breaking-changes or something like that)
  2. Add a method under this feature flag to get the raw sqlx connection from the database pool

Sytten avatar May 19 '22 21:05 Sytten

Hey @Sytten, sorry for the delay. I think it's rather more of a design choice to include such unstable features. As SeaORM is designed in a way that's agnostic to both database and database connector. Later, we might swap the connector / introduce more connector and not solely rely on sqlx, so I consider the proposed feature as unstable.

We could introduce unstable/get_sqlx_connect_pool feature and offer the get_sqlx_connect_pool method under that feature.

Thoughts? @tyt2y3

billy1624 avatar Jul 06 '22 10:07 billy1624

I think we can have an seaql-internal feature to expose some implementation details under a 'unstable' API, where things may not adhere to the semver convention. It's just a type system thing anyway.

tyt2y3 avatar Jul 10 '22 08:07 tyt2y3

I think we should allow this (https://github.com/SeaQL/sea-query/discussions/437#discussioncomment-3614048).

frederikhors avatar Sep 10 '22 11:09 frederikhors

Could do. Although the original design is: you create a SQLx pool first and then create a SeaORM pool from it.

tyt2y3 avatar Sep 10 '22 11:09 tyt2y3

Yeah, I know it's strange! 😄

I'm using this code right now:

use sea_orm_migration::prelude::*;
use sqlx::PgPool;

mod rs;

#[tokio::main]
async fn main() {
    let pool = PgPool::connect("...").await.unwrap();

    sqlx::migrate!("sql").run(&pool).await.unwrap();

    let db_conn = Database::connect("...").await;

    rs::Migrator::up(&db_conn, None).await.unwrap();
}

But I don't care for now because I'm starting and because it's a one-time bin for new demo deployments...

But it would be awesome to not repeat the connection for sqlx.

Or maybe we can have something like migrate! in Sea too!

frederikhors avatar Sep 10 '22 11:09 frederikhors