1
0
mirror of https://github.com/actix/examples synced 2024-11-23 22:41:07 +01:00

fix diesel example

This commit is contained in:
Rob Ede 2022-02-18 02:32:44 +00:00
parent 09e3318ebf
commit e7b73040d7
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
5 changed files with 12 additions and 13 deletions

View File

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

View File

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

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
}