From 53eea6ac5f9b8f930f3ec931773d909afb19cfa5 Mon Sep 17 00:00:00 2001 From: Filip Macek Date: Fri, 2 Aug 2024 12:10:43 +0200 Subject: [PATCH] Bump sqlx to 0.8.0 and refactoring (#1822) --- nautilus_core/Cargo.lock | 104 ++++++++++-------- nautilus_core/infrastructure/Cargo.toml | 4 +- .../infrastructure/src/sql/models/enums.rs | 75 +++++++------ 3 files changed, 100 insertions(+), 83 deletions(-) diff --git a/nautilus_core/Cargo.lock b/nautilus_core/Cargo.lock index a4da243b129a..b439419a56aa 100644 --- a/nautilus_core/Cargo.lock +++ b/nautilus_core/Cargo.lock @@ -237,7 +237,7 @@ dependencies = [ "arrow-schema", "arrow-select", "atoi", - "base64 0.22.1", + "base64", "chrono", "comfy-table", "half", @@ -534,12 +534,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base64" -version = "0.21.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" - [[package]] name = "base64" version = "0.22.1" @@ -933,6 +927,15 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "120133d4db2ec47efe2e26502ee984747630c67f51974fca0b6c1340cf2368d3" +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "const-oid" version = "0.9.6" @@ -1336,7 +1339,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a369332afd0ef5bd565f6db2139fb9f1dfdd0afa75a7f70f000b74208d76994f" dependencies = [ "arrow", - "base64 0.22.1", + "base64", "chrono", "datafusion-common", "datafusion-execution", @@ -1402,7 +1405,7 @@ dependencies = [ "arrow-ord", "arrow-schema", "arrow-string", - "base64 0.22.1", + "base64", "chrono", "datafusion-common", "datafusion-execution", @@ -1667,9 +1670,14 @@ checksum = "63b41cb9dd076076058a4523f009c900c582279536d0b2e45a29aa930e083cc5" [[package]] name = "event-listener" -version = "2.5.3" +version = "5.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" +checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] [[package]] name = "fallible-streaming-iterator" @@ -1955,9 +1963,9 @@ dependencies = [ [[package]] name = "hashlink" -version = "0.8.4" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" +checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" dependencies = [ "hashbrown 0.14.5", ] @@ -1967,9 +1975,6 @@ name = "heck" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] [[package]] name = "heck" @@ -2412,9 +2417,9 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "libsqlite3-sys" -version = "0.27.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4e226dcd58b4be396f7bd3c20da8fdee2911400705297ba7d2d7cc2c30f716" +checksum = "0c10584274047cb335c23d3e61bcef8e323adae7c5c8c760540f73610177fc3f" dependencies = [ "cc", "pkg-config", @@ -3157,6 +3162,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "parking" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" + [[package]] name = "parking_lot" version = "0.12.3" @@ -3194,7 +3205,7 @@ dependencies = [ "arrow-ipc", "arrow-schema", "arrow-select", - "base64 0.22.1", + "base64", "brotli", "bytes", "chrono", @@ -3791,7 +3802,7 @@ version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7d6d2a27d57148378eb5e111173f4276ad26340ecc5c49a4a2152167a2d6a37" dependencies = [ - "base64 0.22.1", + "base64", "bytes", "encoding_rs", "futures-core", @@ -4047,7 +4058,7 @@ version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" dependencies = [ - "base64 0.22.1", + "base64", "rustls-pki-types", ] @@ -4293,6 +4304,9 @@ name = "smallvec" version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +dependencies = [ + "serde", +] [[package]] name = "snafu" @@ -4384,9 +4398,9 @@ dependencies = [ [[package]] name = "sqlx" -version = "0.7.4" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9a2ccff1a000a5a59cd33da541d9f2fdcd9e6e8229cc200565942bff36d0aaa" +checksum = "27144619c6e5802f1380337a209d2ac1c431002dd74c6e60aebff3c506dc4f0c" dependencies = [ "sqlx-core", "sqlx-macros", @@ -4397,11 +4411,10 @@ dependencies = [ [[package]] name = "sqlx-core" -version = "0.7.4" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24ba59a9342a3d9bab6c56c118be528b27c9b60e490080e9711a04dccac83ef6" +checksum = "a999083c1af5b5d6c071d34a708a19ba3e02106ad82ef7bbd69f5e48266b613b" dependencies = [ - "ahash 0.8.11", "atoi", "byteorder", "bytes", @@ -4414,6 +4427,7 @@ dependencies = [ "futures-intrusive", "futures-io", "futures-util", + "hashbrown 0.14.5", "hashlink", "hex", "indexmap 2.3.0", @@ -4436,26 +4450,26 @@ dependencies = [ [[package]] name = "sqlx-macros" -version = "0.7.4" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea40e2345eb2faa9e1e5e326db8c34711317d2b5e08d0d5741619048a803127" +checksum = "a23217eb7d86c584b8cbe0337b9eacf12ab76fe7673c513141ec42565698bb88" dependencies = [ "proc-macro2", "quote", "sqlx-core", "sqlx-macros-core", - "syn 1.0.109", + "syn 2.0.72", ] [[package]] name = "sqlx-macros-core" -version = "0.7.4" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5833ef53aaa16d860e92123292f1f6a3d53c34ba8b1969f152ef1a7bb803f3c8" +checksum = "1a099220ae541c5db479c6424bdf1b200987934033c2584f79a0e1693601e776" dependencies = [ "dotenvy", "either", - "heck 0.4.1", + "heck 0.5.0", "hex", "once_cell", "proc-macro2", @@ -4467,7 +4481,7 @@ dependencies = [ "sqlx-mysql", "sqlx-postgres", "sqlx-sqlite", - "syn 1.0.109", + "syn 2.0.72", "tempfile", "tokio", "url", @@ -4475,12 +4489,12 @@ dependencies = [ [[package]] name = "sqlx-mysql" -version = "0.7.4" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ed31390216d20e538e447a7a9b959e06ed9fc51c37b514b46eb758016ecd418" +checksum = "5afe4c38a9b417b6a9a5eeffe7235d0a106716495536e7727d1c7f4b1ff3eba6" dependencies = [ "atoi", - "base64 0.21.7", + "base64", "bitflags 2.6.0", "byteorder", "bytes", @@ -4517,12 +4531,12 @@ dependencies = [ [[package]] name = "sqlx-postgres" -version = "0.7.4" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c824eb80b894f926f89a0b9da0c7f435d27cdd35b8c655b114e58223918577e" +checksum = "b1dbb157e65f10dbe01f729339c06d239120221c9ad9fa0ba8408c4cc18ecf21" dependencies = [ "atoi", - "base64 0.21.7", + "base64", "bitflags 2.6.0", "byteorder", "crc", @@ -4555,9 +4569,9 @@ dependencies = [ [[package]] name = "sqlx-sqlite" -version = "0.7.4" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b244ef0a8414da0bed4bb1910426e890b19e5e9bccc27ada6b797d05c55ae0aa" +checksum = "9b2cdd83c008a622d94499c0006d8ee5f821f36c89b7d625c900e5dc30b5c5ee" dependencies = [ "atoi", "flume", @@ -4570,10 +4584,10 @@ dependencies = [ "log", "percent-encoding", "serde", + "serde_urlencoded", "sqlx-core", "tracing", "url", - "urlencoding", ] [[package]] @@ -5273,12 +5287,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "urlencoding" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" - [[package]] name = "ustr" version = "1.0.0" diff --git a/nautilus_core/infrastructure/Cargo.toml b/nautilus_core/infrastructure/Cargo.toml index 87ecab5fc981..acad9814d149 100644 --- a/nautilus_core/infrastructure/Cargo.toml +++ b/nautilus_core/infrastructure/Cargo.toml @@ -39,10 +39,8 @@ redis = { version = "0.26.1", features = [ "tls-rustls", "tls-rustls-webpki-roots", ], optional = true } -sqlx = { version = "0.7.4", features = [ - "sqlite", +sqlx = { version = "0.8.0", features = [ "postgres", - "any", "runtime-tokio", "json" ], optional = true } diff --git a/nautilus_core/infrastructure/src/sql/models/enums.rs b/nautilus_core/infrastructure/src/sql/models/enums.rs index f7578474ea92..defa452f35c5 100644 --- a/nautilus_core/infrastructure/src/sql/models/enums.rs +++ b/nautilus_core/infrastructure/src/sql/models/enums.rs @@ -20,18 +20,23 @@ use nautilus_model::enums::{ TrailingOffsetType, }; use sqlx::{ - database::{HasArguments, HasValueRef}, - encode::IsNull, - error::BoxDynError, - postgres::PgTypeInfo, - types::Type, - Decode, Postgres, + encode::IsNull, error::BoxDynError, postgres::PgTypeInfo, types::Type, Database, Decode, + Postgres, }; pub struct CurrencyTypeModel(pub CurrencyType); +pub struct PriceTypeModel(pub PriceType); +pub struct BarAggregationModel(pub BarAggregation); +pub struct AssetClassModel(pub AssetClass); +pub struct TrailingOffsetTypeModel(pub TrailingOffsetType); +pub struct AggressorSideModel(pub AggressorSide); +pub struct AggregationSourceModel(pub AggregationSource); impl sqlx::Encode<'_, sqlx::Postgres> for CurrencyTypeModel { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref( + &self, + buf: &mut ::ArgumentBuffer<'_>, + ) -> Result { let currency_type_str = match self.0 { CurrencyType::Crypto => "CRYPTO", CurrencyType::Fiat => "FIAT", @@ -42,7 +47,7 @@ impl sqlx::Encode<'_, sqlx::Postgres> for CurrencyTypeModel { } impl<'r> sqlx::Decode<'r, sqlx::Postgres> for CurrencyTypeModel { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { let currency_type_str: &str = <&str as Decode>::decode(value)?; let currency_type = CurrencyType::from_str(currency_type_str).map_err(|_| { sqlx::Error::Decode(format!("Invalid currency type: {}", currency_type_str).into()) @@ -61,10 +66,11 @@ impl sqlx::Type for CurrencyTypeModel { } } -pub struct AssetClassModel(pub AssetClass); - impl sqlx::Encode<'_, sqlx::Postgres> for AssetClassModel { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref( + &self, + buf: &mut ::ArgumentBuffer<'_>, + ) -> Result { let asset_type_str = match self.0 { AssetClass::FX => "FX", AssetClass::Equity => "EQUITY", @@ -79,7 +85,7 @@ impl sqlx::Encode<'_, sqlx::Postgres> for AssetClassModel { } impl<'r> sqlx::Decode<'r, sqlx::Postgres> for AssetClassModel { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { let asset_class_str: &str = <&str as Decode>::decode(value)?; let asset_class = AssetClass::from_str(asset_class_str).map_err(|_| { sqlx::Error::Decode(format!("Invalid asset class: {}", asset_class_str).into()) @@ -98,10 +104,11 @@ impl sqlx::Type for AssetClassModel { } } -pub struct TrailingOffsetTypeModel(pub TrailingOffsetType); - impl sqlx::Encode<'_, sqlx::Postgres> for TrailingOffsetTypeModel { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref( + &self, + buf: &mut ::ArgumentBuffer<'_>, + ) -> Result { let trailing_offset_type_str = match self.0 { TrailingOffsetType::NoTrailingOffset => "NO_TRAILING_OFFSET", TrailingOffsetType::Price => "PRICE", @@ -114,7 +121,7 @@ impl sqlx::Encode<'_, sqlx::Postgres> for TrailingOffsetTypeModel { } impl<'r> sqlx::Decode<'r, sqlx::Postgres> for TrailingOffsetTypeModel { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { let trailing_offset_type_str: &str = <&str as Decode>::decode(value)?; let trailing_offset_type = TrailingOffsetType::from_str(trailing_offset_type_str).map_err(|_| { @@ -136,10 +143,11 @@ impl sqlx::Type for TrailingOffsetTypeModel { } } -pub struct AggressorSideModel(pub AggressorSide); - impl sqlx::Encode<'_, sqlx::Postgres> for AggressorSideModel { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref( + &self, + buf: &mut ::ArgumentBuffer<'_>, + ) -> Result { let aggressor_side_str = match self.0 { AggressorSide::NoAggressor => "NO_AGGRESSOR", AggressorSide::Buyer => "BUYER", @@ -150,7 +158,7 @@ impl sqlx::Encode<'_, sqlx::Postgres> for AggressorSideModel { } impl<'r> sqlx::Decode<'r, sqlx::Postgres> for AggressorSideModel { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { let aggressor_side_str: &str = <&str as Decode>::decode(value)?; let aggressor_side = AggressorSide::from_str(aggressor_side_str).map_err(|_| { sqlx::Error::Decode(format!("Invalid aggressor side: {}", aggressor_side_str).into()) @@ -169,10 +177,11 @@ impl sqlx::Type for AggressorSideModel { } } -pub struct AggregationSourceModel(pub AggregationSource); - impl sqlx::Encode<'_, sqlx::Postgres> for AggregationSourceModel { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref( + &self, + buf: &mut ::ArgumentBuffer<'_>, + ) -> Result { let aggregation_source_str = match self.0 { AggregationSource::Internal => "INTERNAL", AggregationSource::External => "EXTERNAL", @@ -182,7 +191,7 @@ impl sqlx::Encode<'_, sqlx::Postgres> for AggregationSourceModel { } impl<'r> sqlx::Decode<'r, sqlx::Postgres> for AggregationSourceModel { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { let aggregation_source_str: &str = <&str as Decode>::decode(value)?; let aggregation_source = AggregationSource::from_str(aggregation_source_str).map_err(|_| { @@ -204,10 +213,11 @@ impl sqlx::Type for AggregationSourceModel { } } -pub struct BarAggregationModel(pub BarAggregation); - impl sqlx::Encode<'_, sqlx::Postgres> for BarAggregationModel { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref( + &self, + buf: &mut ::ArgumentBuffer<'_>, + ) -> Result { let bar_aggregation_str = match self.0 { BarAggregation::Tick => "TICK", BarAggregation::TickImbalance => "TICK_IMBALANCE", @@ -231,7 +241,7 @@ impl sqlx::Encode<'_, sqlx::Postgres> for BarAggregationModel { } impl<'r> sqlx::Decode<'r, sqlx::Postgres> for BarAggregationModel { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { let bar_aggregation_str: &str = <&str as Decode>::decode(value)?; let bar_aggregation = BarAggregation::from_str(bar_aggregation_str).map_err(|_| { sqlx::Error::Decode(format!("Invalid bar aggregation: {}", bar_aggregation_str).into()) @@ -250,10 +260,11 @@ impl sqlx::Type for BarAggregationModel { } } -pub struct PriceTypeModel(pub PriceType); - impl sqlx::Encode<'_, sqlx::Postgres> for PriceTypeModel { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref( + &self, + buf: &mut ::ArgumentBuffer<'_>, + ) -> Result { let price_type_str = match self.0 { PriceType::Bid => "BID", PriceType::Ask => "ASK", @@ -265,7 +276,7 @@ impl sqlx::Encode<'_, sqlx::Postgres> for PriceTypeModel { } impl<'r> sqlx::Decode<'r, sqlx::Postgres> for PriceTypeModel { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { let price_type_str: &str = <&str as Decode>::decode(value)?; let price_type = PriceType::from_str(price_type_str).map_err(|_| { sqlx::Error::Decode(format!("Invalid price type: {}", price_type_str).into())