feat: support urlbased config for sqlite#3853
Conversation
5716dd6 to
8697fa7
Compare
support journal_mode and busy_timeout on sqlite url config Signed-off-by: xujihui1985 <xujihui1985@gmail.com>
8697fa7 to
82390b5
Compare
|
I'm not overly comfortable with making the journal mode a URL parameter. The application should be aware of what journal mode it's using because different modes can have very different semantics regarding locking and durability. For example, setting the journal mode to
IMHO, if these parameters aren't exposed in SeaORM's API, that's a SeaORM issue. The connection URL is not meant to be a catch-all for configuration. |
|
@abonander Thanks for your reply. I totally agree that the application should be aware of these settings. In real-world use cases, PRAGMAs like journal_mode should be set when the database is first opened—it doesn’t make sense to open the database with one mode and then operate with another. My understanding is that setting it in the URL acts more like a default configuration—similar to a shortcut for calling the journal_mode() function. It gives the application an easier way to set the initial configuration and also makes it explicit that the database is opened in WAL mode. Apologies for bringing up SeaORM as a bad example. I really appreciate your insights and thoughtful explanation. |
|
The problem is that the application could just decide that the default is acceptable and not explicitly set I don't like that this makes it possible for the user to (potentially) significantly change the behavior of the application (or make it possible to invoke undefined behavior and corrupt the database file) just by changing a single URL parameter. There is I also don't find it sufficiently compelling that a driver in a different language decided to expose this. Looking through their issue tracker, they've had some problems caused by the exact implementation of it and how it can go wrong when used inconsistently: mattn/go-sqlite3#607 |
|
@abonander ok, I understand what you concerned. Again, thanks for your time to explain me |
Does your PR solve an issue?
This PR introduces support for configuring journal_mode and busy_timeout via the SQLite database URL, improving ergonomics and aligning with behavior in other ecosystems.
Currently, libraries like SeaORM do not expose journal_mode and busy_timeout through DatabaseConfig, which requires users to manually run PRAGMA commands after establishing a connection. This adds complexity and boilerplate. By allowing these settings to be specified in the URL itself, usage becomes much simpler and declarative.
This feature mirrors existing functionality in other SQLite libraries such as the Go SQLite driver mattn/go-sqlite3, which supports these parameters in the DSN.
Example usage:
Is this a breaking change?
No, this is not a breaking change. Existing URLs will continue to work as before, and the new configuration options are optional and additive.
Additional context
This change improves developer experience by eliminating the need to execute manual PRAGMA statements by using sea-orm and allows consistent configuration via connection string.
Unit and/or integration tests have been added to verify that journal_mode and busy_timeout are correctly parsed and applied from the URL configuration.