sea-orm
sea-orm copied to clipboard
Allow user to retrieve connection from underlining pool
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
- Add a crate feature (
i-hop-in-breaking-changesor something like that) - Add a method under this feature flag to get the raw sqlx connection from the database pool
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
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.
I think we should allow this (https://github.com/SeaQL/sea-query/discussions/437#discussioncomment-3614048).
Could do. Although the original design is: you create a SQLx pool first and then create a SeaORM pool from it.
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!