Open kosayoda opened 2 months ago
@kosayoda while it doesn't directly address the issue you created, there is a workaround. I had to do something similar and used the sqlx::sqlite::SqliteConnectionOptions
and sqlx::sqlite::SqlitePoolOptions
directly to configure and create the pool and then used the sea_orm::SqlxSqliteConnector
to build the sea_orm::DatabaseConnection
.
As an example (I am winging this, so it might not compile, but it is based on what I did):
let mut conn_opts = sqlx::sqlite::SqliteConnectOptions::from_str(connstr)?;
conn_opts = conn_opts.journal_mode(sqlx::sqlite::SqliteJournalMode::Wal);
let pool_opts = sqlx::sqlite::SqlitePoolOptions::new()
.idle_timeout(None)
.max_lifetime(None);
let pool = pool_opts.connect_with(conn_opts).await?;
let connection = sea_orm::SqlxSqliteConnector::from_sqlx_sqlite_pool(pool);
I specifically needed this so that I could hook in an after_connect
hook into the pool and couldn't come up with another way to do it.
Description
When
ConnectOptions
is converted tosqlx::pool::PoolOptions
, themax_lifetime
andidle_timeout
fields are set only if the value provided is notNone
: https://github.com/SeaQL/sea-orm/blob/b68e770f973adea8651420c0865f697bca2f5b9b/src/driver/sqlx_common.rs#L54-L56 https://github.com/SeaQL/sea-orm/blob/b68e770f973adea8651420c0865f697bca2f5b9b/src/driver/sqlx_common.rs#L60-L62However,
None
is a valid field forsqlx
to enable infinite connection lifetime and no idle timeout. By default, the values are set to 30 mins and 10 mins respectively.Use Case
I'm using an SQLite in-memory database and the data will be wiped if connections to it are closed. Therefore I want to keep a connection to the database indefinitely.