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:
parent
c43e15e2cd
commit
563562d325
1
.github/workflows/rust.yml
vendored
1
.github/workflows/rust.yml
vendored
@ -260,6 +260,7 @@ jobs:
|
|||||||
components: rustfmt
|
components: rustfmt
|
||||||
- run: find ${{ matrix.path }} -type f -name 'Cargo.toml' -print0 | xargs -t -0 -I {} cargo fmt --manifest-path {} -- --check
|
- run: find ${{ matrix.path }} -type f -name 'Cargo.toml' -print0 | xargs -t -0 -I {} cargo fmt --manifest-path {} -- --check
|
||||||
- uses: dtolnay/rust-toolchain@stable
|
- 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 build --manifest-path {}
|
||||||
- run: find ${{ matrix.path }} -type f -name 'Cargo.toml' -print0 | xargs -t -0 -I {} cargo test --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
|
- 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
|
||||||
|
10
Cargo.toml
10
Cargo.toml
@ -32,14 +32,14 @@ futures = { version = "0.3", default-features = false, features = ["std"] }
|
|||||||
log = { version = "0.4", default-features = false }
|
log = { version = "0.4", default-features = false }
|
||||||
tracing = { version = "0.1", default-features = false, features = ["attributes", "log"] }
|
tracing = { version = "0.1", default-features = false, features = ["attributes", "log"] }
|
||||||
rust_decimal = { version = "1", default-features = false, optional = true }
|
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-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 = { 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.6.0", default-features = false, optional = true }
|
sea-query-binder = { version = "0.7.0-rc.1", default-features = false, optional = true }
|
||||||
strum = { version = "0.26", default-features = false }
|
strum = { version = "0.26", default-features = false }
|
||||||
serde = { version = "1.0", default-features = false }
|
serde = { version = "1.0", default-features = false }
|
||||||
serde_json = { version = "1.0", default-features = false, optional = true }
|
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 }
|
uuid = { version = "1", default-features = false, optional = true }
|
||||||
ouroboros = { version = "0.17", default-features = false }
|
ouroboros = { version = "0.17", default-features = false }
|
||||||
url = { version = "2.2", default-features = false }
|
url = { version = "2.2", default-features = false }
|
||||||
@ -76,7 +76,7 @@ default = [
|
|||||||
macros = ["sea-orm-macros/derive"]
|
macros = ["sea-orm-macros/derive"]
|
||||||
mock = []
|
mock = []
|
||||||
proxy = ["serde_json", "serde/derive"]
|
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-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-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"]
|
with-bigdecimal = ["bigdecimal", "sea-query/with-bigdecimal", "sea-query-binder?/with-bigdecimal", "sqlx?/bigdecimal"]
|
||||||
|
@ -38,8 +38,8 @@ clap = { version = "4.3", features = ["env", "derive"], optional = true }
|
|||||||
dotenvy = { version = "0.15", default-features = false, optional = true }
|
dotenvy = { version = "0.15", default-features = false, optional = true }
|
||||||
async-std = { version = "1.9", default-features = false, features = ["attributes", "tokio1"], 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-orm-codegen = { version = "=1.0.0", path = "../sea-orm-codegen", default-features = false, optional = true }
|
||||||
sea-schema = { version = "0.15.0" }
|
sea-schema = { version = "0.16.0-rc.1" }
|
||||||
sqlx = { version = "0.7", default-features = false, features = ["mysql", "postgres"], optional = true }
|
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-subscriber = { version = "0.3.17", default-features = false, features = ["env-filter", "fmt"] }
|
||||||
tracing = { version = "0.1", default-features = false }
|
tracing = { version = "0.1", default-features = false }
|
||||||
url = { version = "2.2", default-features = false }
|
url = { version = "2.2", default-features = false }
|
||||||
|
@ -17,7 +17,7 @@ name = "sea_orm_codegen"
|
|||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[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"] }
|
syn = { version = "2", default-features = false, features = ["parsing", "proc-macro", "derive", "printing"] }
|
||||||
quote = { version = "1", default-features = false }
|
quote = { version = "1", default-features = false }
|
||||||
heck = { version = "0.4", default-features = false }
|
heck = { version = "0.4", default-features = false }
|
||||||
|
@ -25,7 +25,7 @@ clap = { version = "4.3", features = ["env", "derive"], optional = true }
|
|||||||
dotenvy = { version = "0.15", default-features = false, 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 = { 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-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 = { version = "0.1", default-features = false, features = ["log"] }
|
||||||
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["env-filter", "fmt"] }
|
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["env-filter", "fmt"] }
|
||||||
futures = { version = "0.3", default-features = false, features = ["std"] }
|
futures = { version = "0.3", default-features = false, features = ["std"] }
|
||||||
|
@ -463,7 +463,6 @@ try_getable_unsigned!(u16);
|
|||||||
try_getable_mysql!(u64);
|
try_getable_mysql!(u64);
|
||||||
try_getable_all!(f32);
|
try_getable_all!(f32);
|
||||||
try_getable_all!(f64);
|
try_getable_all!(f64);
|
||||||
try_getable_all!(String);
|
|
||||||
try_getable_all!(Vec<u8>);
|
try_getable_all!(Vec<u8>);
|
||||||
|
|
||||||
#[cfg(feature = "with-json")]
|
#[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)]
|
#[allow(dead_code)]
|
||||||
fn err_null_idx_col<I: ColIdx>(idx: I) -> TryGetError {
|
fn err_null_idx_col<I: ColIdx>(idx: I) -> TryGetError {
|
||||||
TryGetError::Null(format!("{idx:?}"))
|
TryGetError::Null(format!("{idx:?}"))
|
||||||
|
@ -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!(bool);
|
||||||
match_mysql_type!(i8);
|
match_mysql_type!(i8);
|
||||||
match_mysql_type!(i16);
|
match_mysql_type!(i16);
|
||||||
@ -64,9 +71,9 @@ impl FromQueryResult for JsonValue {
|
|||||||
match_mysql_type!(time::OffsetDateTime);
|
match_mysql_type!(time::OffsetDateTime);
|
||||||
#[cfg(feature = "with-rust_decimal")]
|
#[cfg(feature = "with-rust_decimal")]
|
||||||
match_mysql_type!(rust_decimal::Decimal);
|
match_mysql_type!(rust_decimal::Decimal);
|
||||||
|
match_mysql_compatible_type!(String);
|
||||||
#[cfg(feature = "with-json")]
|
#[cfg(feature = "with-json")]
|
||||||
try_get_type!(serde_json::Value, col);
|
try_get_type!(serde_json::Value, col);
|
||||||
try_get_type!(String, col);
|
|
||||||
#[cfg(feature = "with-uuid")]
|
#[cfg(feature = "with-uuid")]
|
||||||
try_get_type!(uuid::Uuid, col);
|
try_get_type!(uuid::Uuid, col);
|
||||||
try_get_type!(Vec<u8>, col);
|
try_get_type!(Vec<u8>, col);
|
||||||
|
@ -18,33 +18,45 @@ async fn main() -> Result<(), DbErr> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_and_update_pi(db: &DatabaseConnection) -> 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,
|
id: 1,
|
||||||
decimal: rust_dec(3.1415926536),
|
decimal: rust_dec(3.1415926536),
|
||||||
big_decimal: BigDecimal::from_str("3.1415926536").unwrap(),
|
big_decimal: BigDecimal::from_str("3.1415926536").unwrap(),
|
||||||
decimal_opt: None,
|
decimal_opt: None,
|
||||||
big_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?;
|
let model = trunc_dec_scale(Pi::find().one(db).await?.unwrap());
|
||||||
assert_eq!(model, Some(res));
|
assert_eq!(model, res);
|
||||||
assert_eq!(model, Some(pi.clone()));
|
assert_eq!(model, pi.clone());
|
||||||
|
|
||||||
let res = pi::ActiveModel {
|
let res = trunc_dec_scale(
|
||||||
decimal_opt: Set(Some(rust_dec(3.1415926536))),
|
pi::ActiveModel {
|
||||||
big_decimal_opt: Set(Some(BigDecimal::from_str("3.1415926536").unwrap())),
|
decimal_opt: Set(Some(rust_dec(3.1415926536))),
|
||||||
..pi.clone().into_active_model()
|
big_decimal_opt: Set(Some(BigDecimal::from_str("3.1415926536").unwrap())),
|
||||||
}
|
..pi.clone().into_active_model()
|
||||||
.update(db)
|
}
|
||||||
.await?;
|
.update(db)
|
||||||
|
.await?,
|
||||||
|
);
|
||||||
|
|
||||||
let model = Pi::find().one(db).await?;
|
let model = trunc_dec_scale(Pi::find().one(db).await?.unwrap());
|
||||||
assert_eq!(model, Some(res));
|
assert_eq!(model, res);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
model,
|
model,
|
||||||
Some(pi::Model {
|
trunc_dec_scale(pi::Model {
|
||||||
id: 1,
|
id: 1,
|
||||||
decimal: rust_dec(3.1415926536),
|
decimal: rust_dec(3.1415926536),
|
||||||
big_decimal: BigDecimal::from_str("3.1415926536").unwrap(),
|
big_decimal: BigDecimal::from_str("3.1415926536").unwrap(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user