mirror of
https://github.com/actix/examples
synced 2025-02-17 07:23:29 +01:00
fix diesel example
This commit is contained in:
parent
09e3318ebf
commit
e7b73040d7
3
.github/workflows/linux.yml
vendored
3
.github/workflows/linux.yml
vendored
@ -70,5 +70,4 @@ jobs:
|
|||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
with:
|
with:
|
||||||
command: test
|
command: test
|
||||||
# TODO: remove exclude protobuf-example when upgraded; currently fails on nightly
|
args: --workspace --all-features --no-fail-fast -- --nocapture
|
||||||
args: --workspace --all-features --no-fail-fast --exclude protobuf-example -- --nocapture
|
|
||||||
|
@ -14,8 +14,6 @@ members = [
|
|||||||
"basics/todo",
|
"basics/todo",
|
||||||
"cors/backend",
|
"cors/backend",
|
||||||
"data-factory",
|
"data-factory",
|
||||||
# example uses incompatible libsqlite-sys to other examples
|
|
||||||
# "databases/diesel",
|
|
||||||
"databases/mongodb",
|
"databases/mongodb",
|
||||||
"databases/postgres",
|
"databases/postgres",
|
||||||
"databases/redis",
|
"databases/redis",
|
||||||
@ -58,3 +56,7 @@ members = [
|
|||||||
"websockets/chat",
|
"websockets/chat",
|
||||||
"websockets/echo",
|
"websockets/echo",
|
||||||
]
|
]
|
||||||
|
exclude = [
|
||||||
|
# uses incompatible libsqlite-sys to other examples
|
||||||
|
"databases/diesel",
|
||||||
|
]
|
||||||
|
@ -10,6 +10,7 @@ dotenv = "0.15"
|
|||||||
env_logger = "0.9.0"
|
env_logger = "0.9.0"
|
||||||
failure = "0.1.8"
|
failure = "0.1.8"
|
||||||
futures = "0.3.1"
|
futures = "0.3.1"
|
||||||
|
log = "0.4"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
uuid = { version = "0.8", features = ["serde", "v4"] }
|
uuid = { version = "0.8", features = ["serde", "v4"] }
|
||||||
|
@ -36,7 +36,7 @@ There will now be a database file at `./test.db`.
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
cd databases/diesel
|
cd databases/diesel
|
||||||
cargo run (or ``cargo watch -x run``)
|
cargo run
|
||||||
|
|
||||||
# Started http server: 127.0.0.1:8080
|
# Started http server: 127.0.0.1:8080
|
||||||
```
|
```
|
||||||
|
@ -61,20 +61,17 @@ async fn add_user(
|
|||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
std::env::set_var("RUST_LOG", "actix_web=info");
|
|
||||||
env_logger::init();
|
|
||||||
dotenv::dotenv().ok();
|
dotenv::dotenv().ok();
|
||||||
|
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||||
|
|
||||||
// set up database connection pool
|
// set up database connection pool
|
||||||
let connspec = std::env::var("DATABASE_URL").expect("DATABASE_URL");
|
let conn_spec = std::env::var("DATABASE_URL").expect("DATABASE_URL");
|
||||||
let manager = ConnectionManager::<SqliteConnection>::new(connspec);
|
let manager = ConnectionManager::<SqliteConnection>::new(conn_spec);
|
||||||
let pool = r2d2::Pool::builder()
|
let pool = r2d2::Pool::builder()
|
||||||
.build(manager)
|
.build(manager)
|
||||||
.expect("Failed to create pool.");
|
.expect("Failed to create pool.");
|
||||||
|
|
||||||
let bind = ("127.0.0.1", 8080);
|
log::info!("starting HTTP server at http://localhost:8080");
|
||||||
|
|
||||||
println!("Starting server at: {}", &bind);
|
|
||||||
|
|
||||||
// Start HTTP server
|
// Start HTTP server
|
||||||
HttpServer::new(move || {
|
HttpServer::new(move || {
|
||||||
@ -85,7 +82,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
.service(get_user)
|
.service(get_user)
|
||||||
.service(add_user)
|
.service(add_user)
|
||||||
})
|
})
|
||||||
.bind(&bind)?
|
.bind(("127.0.0.1", 8080))?
|
||||||
.run()
|
.run()
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user