Skip to content

Commit

Permalink
Merge pull request #60 from Jupeyy/pr_sqlx_str_workaround
Browse files Browse the repository at this point in the history
Add workaround for sqlx binary collation bug.
  • Loading branch information
Jupeyy authored Jan 13, 2025
2 parents 9dc5440 + 0c121b0 commit 78c29f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/game-database-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ game-database = { path = "../../lib/game-database", default-features = false }

ddnet-account-sql = { version = "0.3.0", default-features = false }

# when updating to the next major version check if
# https://github.com/launchbadge/sqlx/issues/3387 is fixed
# and remove the workaround in the code
sqlx = { version = "0.8.2", features = ["runtime-tokio-rustls", "chrono"] }
anyhow = { version = "1.0.95", features = ["backtrace"] }
async-trait = "0.1.83"
Expand Down
10 changes: 9 additions & 1 deletion lib/game-database-backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,15 @@ impl GameDbBackend {
DbType::F64(_) => DbType::F64(row.try_get::<f64, _>(name.as_str())?),
DbType::Bool(_) => DbType::Bool(row.try_get::<bool, _>(name.as_str())?),
DbType::String(_) => {
DbType::String(row.try_get::<String, _>(name.as_str())?)
DbType::String(row.try_get::<String, _>(name.as_str()).or_else(
|_| {
// workaround for strings with binary collation
// https://github.com/launchbadge/sqlx/issues/3387
anyhow::Ok(String::from_utf8(
row.try_get::<Vec<u8>, _>(name.as_str())?,
)?)
},
)?)
}
DbType::Vec(_) => {
DbType::Vec(row.try_get::<Vec<u8>, _>(name.as_str())?)
Expand Down

0 comments on commit 78c29f4

Please sign in to comment.