fix in mysql

This commit is contained in:
Mateusz Gruszczyński
2026-08-05 10:29:31 +02:00
parent a9911da9a3
commit 73286d921b
7 changed files with 27 additions and 7 deletions
+12 -4
View File
@@ -29,10 +29,18 @@ impl Database {
sqlx::any::install_default_drivers();
let kind = DatabaseKind::from_url(url)?;
debug!(?kind, max_connections, "initializing database pool");
let pool = AnyPoolOptions::new()
.max_connections(max_connections)
.connect(url)
.await?;
let mut options = AnyPoolOptions::new().max_connections(max_connections);
if kind == DatabaseKind::MySql {
options = options.after_connect(|connection, _metadata| {
Box::pin(async move {
sqlx::query("SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci")
.execute(connection)
.await?;
Ok(())
})
});
}
let pool = options.connect(url).await?;
if kind == DatabaseKind::Sqlite {
debug!("applying SQLite connection pragmas");
sqlx::query(queries::get(kind, queries::SQLITE_FOREIGN_KEYS_ON))