1
0
mirror of https://github.com/actix/examples synced 2025-06-26 17:17:42 +02:00

fix diesel example

This commit is contained in:
Rob Ede
2022-02-18 02:32:44 +00:00
parent 09e3318ebf
commit e7b73040d7
5 changed files with 12 additions and 13 deletions

View File

@ -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"] }

View File

@ -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
```

View File

@ -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::<SqliteConnection>::new(connspec);
let conn_spec = std::env::var("DATABASE_URL").expect("DATABASE_URL");
let manager = ConnectionManager::<SqliteConnection>::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
}