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

Provide a way to start an SQLite `IMMEDIATE` transaction

Open Huliiiiii opened this issue 4 months ago • 2 comments

Discussed in https://github.com/SeaQL/sea-orm/discussions/2691

Originally posted by raffomania August 12, 2025 One of the recommended best practices when running SQLite for a web application is to start write transactions as IMMEDIATE so SQLite will respect the busy_timeout setting.

Looking at the TransactionTrait::begin_with_config function, it doesn't seem like this is currently supported. I'd be interested in working on a PR for this if we can work out a good API for this. Would anybody be interested in talking about the API design and/or reviewing a PR?

Huliiiiii avatar Aug 11 '25 18:08 Huliiiiii

enum Config {
    Postgres(PostgresConfig),
    Sqlite(SqliteConfig),
    Mysql(MysqlConfig)
}

// or

struct Config {
  // Controlled by feature flag
}

// If multiple backend features are enabled, check the backend of connection here or simply ignore that.
async fn begin_with_config(
    &self,
    conf: Config
) -> Result<DatabaseTransaction, DbErr>;

@Expurple @tyt2y3 What do you think?

Huliiiiii avatar Aug 11 '25 22:08 Huliiiiii

Hey is there any updates on this? We run into problems when we get a lot of requests at the same time and it appears that Sqlite does not respect the busy_timeout setting

Gulianrdgd avatar Oct 15 '25 11:10 Gulianrdgd