Replies: 5 comments 4 replies
-
I imagine the |
Beta Was this translation helpful? Give feedback.
-
Ah I apologize, I looked through the issues but not the discussions. If that's the case then that's a workaround. As mentioned in the discussion, it would be helpful if it's explicitly documented somewhere. |
Beta Was this translation helpful? Give feedback.
-
Hm. It seems like This would make sense as /// The total number of connections opened is <code>min(1, [min_connections][Self::min_connections])</code>.
|
Beta Was this translation helpful? Give feedback.
-
We can merge into #1523 |
Beta Was this translation helpful? Give feedback.
-
I also would like this feature but I don't feel confident writing the PR to implement the connect_lazy wrapper. For anyone interested in a workaround you can achieve this today by creating a db connection with sqlx and then converting that to a sea-orm DatabaseConnection: let db_url = "your postgres database url here";
// create a sqlx PgPool
let pg_pool = PgPoolOptions::new()
.acquire_timeout(Duration::from_secs(8))
.max_connections(50)
.min_connections(2)
.max_lifetime(hours(2))
.idle_timeout(minutes(10))
.connect_lazy(db_url)?;
// Convert that to a sea_orm DatabaseConnection with this line:
let db_conn = sea_orm::SqlxPostgresConnector::from_sqlx_postgres_pool(pg_pool); |
Beta Was this translation helpful? Give feedback.
-
Motivation
When starting a service, a database could be temporarily unavailable. Some services may choose to continue running and deal with that when a query is made instead. This makes the service overall more robust as it doesn't have to be repeatedly restarted until the database becomes available again. It also simplifies setups with docker compose.
Proposed Solutions
Connecting lazily to the database can already be done in
sqlx
viaPool::connect_lazy()
. A new functionDatabase::connect_lazy()
could be added that just swaps out the underlyingPool::connect()
call. Alternatively, this could be toggled via a boolean inConnectOptions
.Current Workarounds
I don't think there is a way to achieve this behavior at the current moment unless there is a way to create a
DatabaseConnection
from an underlyingsqlx::Pool
with public functions.Beta Was this translation helpful? Give feedback.
All reactions