Bump SQLx to 0.8 (#2305)

* Bump SQLx to 0.8

* Bump bigdecimal to 0.4

* Bump sea-query

* Bump sea-schema

* Fix clippy warnings

* Patch for examples

* Fix: enable serde feature on dependent crates

* `TryGetable` for MySQL String

* Fix pi_tests

* Fix uuid_tests

* Handle MySQL into_json

* examples CI

* Fix

* Drop Git override

* Bump to RC version

* revert
This commit is contained in:
Billy Chan 2024-08-09 18:32:14 +08:00 committed by GitHub
parent c43e15e2cd
commit 563562d325
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 91 additions and 27 deletions

View File

@ -260,6 +260,7 @@ jobs:
components: rustfmt
- run: find ${{ matrix.path }} -type f -name 'Cargo.toml' -print0 | xargs -t -0 -I {} cargo fmt --manifest-path {} -- --check
- uses: dtolnay/rust-toolchain@stable
- run: find ${{ matrix.path }} -type f -name 'Cargo.toml' -print0 | xargs -t -0 -I {} cargo update --manifest-path {}
- run: find ${{ matrix.path }} -type f -name 'Cargo.toml' -print0 | xargs -t -0 -I {} cargo build --manifest-path {}
- run: find ${{ matrix.path }} -type f -name 'Cargo.toml' -print0 | xargs -t -0 -I {} cargo test --manifest-path {}
- run: ${{'! '}}${{ '[ -d "' }}${{ matrix.path }}${{ '/service" ]' }} || find ${{ matrix.path }}/service -type f -name 'Cargo.toml' -print0 | xargs -t -0 -I {} cargo test --manifest-path {} --features mock

View File

@ -32,14 +32,14 @@ futures = { version = "0.3", default-features = false, features = ["std"] }
log = { version = "0.4", default-features = false }
tracing = { version = "0.1", default-features = false, features = ["attributes", "log"] }
rust_decimal = { version = "1", default-features = false, optional = true }
bigdecimal = { version = "0.3", default-features = false, optional = true }
bigdecimal = { version = "0.4", default-features = false, optional = true }
sea-orm-macros = { version = "~1.0.0", path = "sea-orm-macros", default-features = false, features = ["strum"] }
sea-query = { version = "0.31.0", default-features = false, features = ["thread-safe", "hashable-value", "backend-mysql", "backend-postgres", "backend-sqlite"] }
sea-query-binder = { version = "0.6.0", default-features = false, optional = true }
sea-query = { version = "0.32.0-rc.1", default-features = false, features = ["thread-safe", "hashable-value", "backend-mysql", "backend-postgres", "backend-sqlite"] }
sea-query-binder = { version = "0.7.0-rc.1", default-features = false, optional = true }
strum = { version = "0.26", default-features = false }
serde = { version = "1.0", default-features = false }
serde_json = { version = "1.0", default-features = false, optional = true }
sqlx = { version = "0.7", default-features = false, optional = true }
sqlx = { version = "0.8", default-features = false, optional = true }
uuid = { version = "1", default-features = false, optional = true }
ouroboros = { version = "0.17", default-features = false }
url = { version = "2.2", default-features = false }
@ -76,7 +76,7 @@ default = [
macros = ["sea-orm-macros/derive"]
mock = []
proxy = ["serde_json", "serde/derive"]
with-json = ["serde_json", "sea-query/with-json", "chrono?/serde", "time?/serde", "uuid?/serde", "sea-query-binder?/with-json", "sqlx?/json"]
with-json = ["serde_json", "sea-query/with-json", "chrono?/serde", "rust_decimal?/serde", "bigdecimal?/serde", "uuid?/serde", "time?/serde", "sea-query-binder?/with-json", "sqlx?/json"]
with-chrono = ["chrono", "sea-query/with-chrono", "sea-query-binder?/with-chrono", "sqlx?/chrono"]
with-rust_decimal = ["rust_decimal", "sea-query/with-rust_decimal", "sea-query-binder?/with-rust_decimal", "sqlx?/rust_decimal"]
with-bigdecimal = ["bigdecimal", "sea-query/with-bigdecimal", "sea-query-binder?/with-bigdecimal", "sqlx?/bigdecimal"]

View File

@ -38,8 +38,8 @@ clap = { version = "4.3", features = ["env", "derive"], optional = true }
dotenvy = { version = "0.15", default-features = false, optional = true }
async-std = { version = "1.9", default-features = false, features = ["attributes", "tokio1"], optional = true }
sea-orm-codegen = { version = "=1.0.0", path = "../sea-orm-codegen", default-features = false, optional = true }
sea-schema = { version = "0.15.0" }
sqlx = { version = "0.7", default-features = false, features = ["mysql", "postgres"], optional = true }
sea-schema = { version = "0.16.0-rc.1" }
sqlx = { version = "0.8", default-features = false, features = ["mysql", "postgres"], optional = true }
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["env-filter", "fmt"] }
tracing = { version = "0.1", default-features = false }
url = { version = "2.2", default-features = false }

View File

@ -17,7 +17,7 @@ name = "sea_orm_codegen"
path = "src/lib.rs"
[dependencies]
sea-query = { version = "0.31.0", default-features = false, features = ["thread-safe"] }
sea-query = { version = "0.32.0-rc.1", default-features = false, features = ["thread-safe"] }
syn = { version = "2", default-features = false, features = ["parsing", "proc-macro", "derive", "printing"] }
quote = { version = "1", default-features = false }
heck = { version = "0.4", default-features = false }

View File

@ -25,7 +25,7 @@ clap = { version = "4.3", features = ["env", "derive"], optional = true }
dotenvy = { version = "0.15", default-features = false, optional = true }
sea-orm = { version = "~1.0.0", path = "../", default-features = false, features = ["macros"] }
sea-orm-cli = { version = "~1.0.0", path = "../sea-orm-cli", default-features = false, optional = true }
sea-schema = { version = "0.15.0" }
sea-schema = { version = "0.16.0-rc.1" }
tracing = { version = "0.1", default-features = false, features = ["log"] }
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["env-filter", "fmt"] }
futures = { version = "0.3", default-features = false, features = ["std"] }

View File

@ -463,7 +463,6 @@ try_getable_unsigned!(u16);
try_getable_mysql!(u64);
try_getable_all!(f32);
try_getable_all!(f64);
try_getable_all!(String);
try_getable_all!(Vec<u8>);
#[cfg(feature = "with-json")]
@ -705,6 +704,51 @@ impl TryGetable for u32 {
}
}
impl TryGetable for String {
#[allow(unused_variables)]
fn try_get_by<I: ColIdx>(res: &QueryResult, idx: I) -> Result<Self, TryGetError> {
match &res.row {
#[cfg(feature = "sqlx-mysql")]
QueryResultRow::SqlxMySql(row) => row
.try_get::<Option<Vec<u8>>, _>(idx.as_sqlx_mysql_index())
.map_err(|e| sqlx_error_to_query_err(e).into())
.and_then(|opt| opt.ok_or_else(|| err_null_idx_col(idx)))
.map(|bytes| {
String::from_utf8(bytes).map_err(|e| {
DbErr::TryIntoErr {
from: "Vec<u8>",
into: "String",
source: Box::new(e),
}
.into()
})
})?,
#[cfg(feature = "sqlx-postgres")]
QueryResultRow::SqlxPostgres(row) => row
.try_get::<Option<String>, _>(idx.as_sqlx_postgres_index())
.map_err(|e| sqlx_error_to_query_err(e).into())
.and_then(|opt| opt.ok_or_else(|| err_null_idx_col(idx))),
#[cfg(feature = "sqlx-sqlite")]
QueryResultRow::SqlxSqlite(row) => row
.try_get::<Option<String>, _>(idx.as_sqlx_sqlite_index())
.map_err(|e| sqlx_error_to_query_err(e).into())
.and_then(|opt| opt.ok_or_else(|| err_null_idx_col(idx))),
#[cfg(feature = "mock")]
QueryResultRow::Mock(row) => row.try_get(idx).map_err(|e| {
debug_print!("{:#?}", e.to_string());
err_null_idx_col(idx)
}),
#[cfg(feature = "proxy")]
QueryResultRow::Proxy(row) => row.try_get(idx).map_err(|e| {
debug_print!("{:#?}", e.to_string());
err_null_idx_col(idx)
}),
#[allow(unreachable_patterns)]
_ => unreachable!(),
}
}
}
#[allow(dead_code)]
fn err_null_idx_col<I: ColIdx>(idx: I) -> TryGetError {
TryGetError::Null(format!("{idx:?}"))

View File

@ -34,6 +34,13 @@ impl FromQueryResult for JsonValue {
}
};
}
macro_rules! match_mysql_compatible_type {
( $type: ty ) => {
if <$type as Type<MySql>>::compatible(col_type) {
try_get_type!($type, col)
}
};
}
match_mysql_type!(bool);
match_mysql_type!(i8);
match_mysql_type!(i16);
@ -64,9 +71,9 @@ impl FromQueryResult for JsonValue {
match_mysql_type!(time::OffsetDateTime);
#[cfg(feature = "with-rust_decimal")]
match_mysql_type!(rust_decimal::Decimal);
match_mysql_compatible_type!(String);
#[cfg(feature = "with-json")]
try_get_type!(serde_json::Value, col);
try_get_type!(String, col);
#[cfg(feature = "with-uuid")]
try_get_type!(uuid::Uuid, col);
try_get_type!(Vec<u8>, col);

View File

@ -18,33 +18,45 @@ async fn main() -> Result<(), DbErr> {
}
pub async fn create_and_update_pi(db: &DatabaseConnection) -> Result<(), DbErr> {
let pi = pi::Model {
fn trunc_dec_scale(mut model: pi::Model) -> pi::Model {
model.decimal = model.decimal.trunc_with_scale(3);
model.big_decimal = model.big_decimal.with_scale(3);
model.decimal_opt = model.decimal_opt.map(|decimal| decimal.trunc_with_scale(3));
model.big_decimal_opt = model
.big_decimal_opt
.map(|big_decimal| big_decimal.with_scale(3));
model
}
let pi = trunc_dec_scale(pi::Model {
id: 1,
decimal: rust_dec(3.1415926536),
big_decimal: BigDecimal::from_str("3.1415926536").unwrap(),
decimal_opt: None,
big_decimal_opt: None,
};
});
let res = pi.clone().into_active_model().insert(db).await?;
let res = trunc_dec_scale(pi.clone().into_active_model().insert(db).await?);
let model = Pi::find().one(db).await?;
assert_eq!(model, Some(res));
assert_eq!(model, Some(pi.clone()));
let model = trunc_dec_scale(Pi::find().one(db).await?.unwrap());
assert_eq!(model, res);
assert_eq!(model, pi.clone());
let res = pi::ActiveModel {
decimal_opt: Set(Some(rust_dec(3.1415926536))),
big_decimal_opt: Set(Some(BigDecimal::from_str("3.1415926536").unwrap())),
..pi.clone().into_active_model()
}
.update(db)
.await?;
let res = trunc_dec_scale(
pi::ActiveModel {
decimal_opt: Set(Some(rust_dec(3.1415926536))),
big_decimal_opt: Set(Some(BigDecimal::from_str("3.1415926536").unwrap())),
..pi.clone().into_active_model()
}
.update(db)
.await?,
);
let model = Pi::find().one(db).await?;
assert_eq!(model, Some(res));
let model = trunc_dec_scale(Pi::find().one(db).await?.unwrap());
assert_eq!(model, res);
assert_eq!(
model,
Some(pi::Model {
trunc_dec_scale(pi::Model {
id: 1,
decimal: rust_dec(3.1415926536),
big_decimal: BigDecimal::from_str("3.1415926536").unwrap(),