From e7b73040d72e86f6e47136700f02a70c26e0ce94 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Fri, 18 Feb 2022 02:32:44 +0000 Subject: [PATCH] fix diesel example --- .github/workflows/linux.yml | 3 +-- Cargo.toml | 6 ++++-- databases/diesel/Cargo.toml | 1 + databases/diesel/README.md | 2 +- databases/diesel/src/main.rs | 13 +++++-------- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 3beb9ca..2b3ae97 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -70,5 +70,4 @@ jobs: timeout-minutes: 30 with: command: test - # TODO: remove exclude protobuf-example when upgraded; currently fails on nightly - args: --workspace --all-features --no-fail-fast --exclude protobuf-example -- --nocapture + args: --workspace --all-features --no-fail-fast -- --nocapture diff --git a/Cargo.toml b/Cargo.toml index c50ecec..df9c7cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,6 @@ members = [ "basics/todo", "cors/backend", "data-factory", - # example uses incompatible libsqlite-sys to other examples - # "databases/diesel", "databases/mongodb", "databases/postgres", "databases/redis", @@ -58,3 +56,7 @@ members = [ "websockets/chat", "websockets/echo", ] +exclude = [ + # uses incompatible libsqlite-sys to other examples + "databases/diesel", +] diff --git a/databases/diesel/Cargo.toml b/databases/diesel/Cargo.toml index 578afe2..c583d9d 100644 --- a/databases/diesel/Cargo.toml +++ b/databases/diesel/Cargo.toml @@ -10,6 +10,7 @@ dotenv = "0.15" env_logger = "0.9.0" failure = "0.1.8" futures = "0.3.1" +log = "0.4" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" uuid = { version = "0.8", features = ["serde", "v4"] } diff --git a/databases/diesel/README.md b/databases/diesel/README.md index 2368fac..e56f937 100644 --- a/databases/diesel/README.md +++ b/databases/diesel/README.md @@ -36,7 +36,7 @@ There will now be a database file at `./test.db`. ```sh cd databases/diesel -cargo run (or ``cargo watch -x run``) +cargo run # Started http server: 127.0.0.1:8080 ``` diff --git a/databases/diesel/src/main.rs b/databases/diesel/src/main.rs index 05f5ac6..0211a8e 100644 --- a/databases/diesel/src/main.rs +++ b/databases/diesel/src/main.rs @@ -61,20 +61,17 @@ async fn add_user( #[actix_web::main] async fn main() -> std::io::Result<()> { - std::env::set_var("RUST_LOG", "actix_web=info"); - env_logger::init(); dotenv::dotenv().ok(); + env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); // set up database connection pool - let connspec = std::env::var("DATABASE_URL").expect("DATABASE_URL"); - let manager = ConnectionManager::::new(connspec); + let conn_spec = std::env::var("DATABASE_URL").expect("DATABASE_URL"); + let manager = ConnectionManager::::new(conn_spec); let pool = r2d2::Pool::builder() .build(manager) .expect("Failed to create pool."); - let bind = ("127.0.0.1", 8080); - - println!("Starting server at: {}", &bind); + log::info!("starting HTTP server at http://localhost:8080"); // Start HTTP server HttpServer::new(move || { @@ -85,7 +82,7 @@ async fn main() -> std::io::Result<()> { .service(get_user) .service(add_user) }) - .bind(&bind)? + .bind(("127.0.0.1", 8080))? .run() .await }