From 9b7db60af6e082d5340b8dfa8283b8d667d6804b Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Wed, 23 Feb 2022 10:20:05 -0300 Subject: [PATCH] Testing the Any database of SQLx --- sqlxany/Cargo.lock | 47 +++++++++++++++++++++++++++++++++++++++++++ sqlxany/Cargo.toml | 2 +- sqlxany/src/entity.rs | 3 +++ sqlxany/src/main.rs | 7 +++++-- 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/sqlxany/Cargo.lock b/sqlxany/Cargo.lock index 477a354..a59704d 100644 --- a/sqlxany/Cargo.lock +++ b/sqlxany/Cargo.lock @@ -34,6 +34,17 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +[[package]] +name = "bigdecimal" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1e50562e37200edf7c6c43e54a08e64a5553bfb59d9c297d5572512aa517256" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -79,6 +90,18 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "winapi", +] + [[package]] name = "cpufeatures" version = "0.2.1" @@ -499,6 +522,27 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-bigint" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6f7833f2cbf2360a6cfd58cd41a53aa7a90bd4c202f5b1c7dd2ed73c57b2c3" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.14" @@ -852,9 +896,11 @@ dependencies = [ "ahash", "atoi", "base64", + "bigdecimal", "bitflags", "byteorder", "bytes", + "chrono", "crc", "crossbeam-queue", "dirs", @@ -875,6 +921,7 @@ dependencies = [ "log", "md-5", "memchr", + "num-bigint", "once_cell", "paste", "percent-encoding", diff --git a/sqlxany/Cargo.toml b/sqlxany/Cargo.toml index 85344ac..7c7f9b7 100644 --- a/sqlxany/Cargo.toml +++ b/sqlxany/Cargo.toml @@ -6,5 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -sqlx = { version = "0.5.11", features = ["runtime-tokio-rustls", "postgres", "sqlite", "any", "macros", "migrate"] } +sqlx = { version = "0.5.11", features = ["runtime-tokio-rustls", "postgres", "sqlite", "any", "macros", "migrate", "bigdecimal", "chrono"] } tokio = { version = "1.17.0", features = ["rt", "rt-multi-thread", "macros", "time"] } diff --git a/sqlxany/src/entity.rs b/sqlxany/src/entity.rs index 9c90335..75fcd8a 100644 --- a/sqlxany/src/entity.rs +++ b/sqlxany/src/entity.rs @@ -11,7 +11,10 @@ VALUES #[derive(sqlx::FromRow)] pub struct Entity { + #[sqlx(rename = "chave")] id: i64, + + #[sqlx(rename = "descricao")] description: String, } diff --git a/sqlxany/src/main.rs b/sqlxany/src/main.rs index f5fdce9..942dea1 100644 --- a/sqlxany/src/main.rs +++ b/sqlxany/src/main.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use sqlx::{Any, Pool}; mod entity; @@ -5,9 +7,10 @@ mod entity; #[tokio::main] async fn main() { let record = entity::Entity::new(1, "Something"); - let pool = + let pool = Arc::new( Pool::::connect(&std::env::var("DATABASE_URL").expect("I need DATABASE_URL set!")) .await - .expect("Failed to connect to the database"); + .expect("Failed to connect to the database"), + ); record.save(&pool).await.unwrap(); }