diff --git a/examples/diesel/Cargo.toml b/examples/diesel/Cargo.toml index 40e78e307..e5bf2bb4d 100644 --- a/examples/diesel/Cargo.toml +++ b/examples/diesel/Cargo.toml @@ -5,8 +5,8 @@ authors = ["Nikolay Kim "] [dependencies] env_logger = "0.4" -actix = "^0.3.1" -actix-web = { git = "https://github.com/actix/actix-web.git" } +actix = "^0.3.5" +actix-web = { git = "https://github.com/actix/actix-web", features=["signal"] } futures = "0.1" uuid = { version = "0.5", features = ["serde", "v4"] } diff --git a/examples/diesel/README.md b/examples/diesel/README.md index 2aa30c5db..922ba1e3b 100644 --- a/examples/diesel/README.md +++ b/examples/diesel/README.md @@ -4,17 +4,40 @@ Diesel's `Getting Started` guide using SQLite for Actix web ## Usage -install `diesel_cli` +### init database sqlite ```bash cargo install diesel_cli --no-default-features --features sqlite -``` - -```bash +cd actix-web/examples/diesel echo "DATABASE_URL=file:test.db" > .env diesel migration run ``` +### server + +```bash +# if ubuntu : sudo apt-get install libsqlite3-dev +# if fedora : sudo dnf install libsqlite3x-devel +cd actix-web/examples/diesel +cargo run (or ``cargo watch -x run``) +# Started http server: 127.0.0.1:8080 +``` + +### web client + +[http://127.0.0.1:8080/NAME](http://127.0.0.1:8080/NAME) + +### sqlite client + +```bash +# if ubuntu : sudo apt-get install sqlite3 +# if fedora : sudo dnf install sqlite3x +sqlite3 test.db +sqlite> .tables +sqlite> select * from users; +``` + + ## Postgresql You will also find another complete example of diesel+postgresql on [https://github.com/TechEmpower/FrameworkBenchmarks/tree/master/frameworks/Rust/actix](https://github.com/TechEmpower/FrameworkBenchmarks/tree/master/frameworks/Rust/actix) \ No newline at end of file diff --git a/examples/diesel/src/main.rs b/examples/diesel/src/main.rs index 350a9ee5a..7303690e6 100644 --- a/examples/diesel/src/main.rs +++ b/examples/diesel/src/main.rs @@ -16,8 +16,11 @@ extern crate actix; extern crate actix_web; extern crate env_logger; +use actix::*; use actix_web::*; use actix::prelude::*; +#[cfg(target_os = "linux")] use actix::actors::signal::{ProcessSignals, Subscribe}; + use diesel::prelude::*; use futures::future::Future; @@ -59,7 +62,7 @@ fn main() { }); // Start http server - HttpServer::new(move || { + let _addr = HttpServer::new(move || { Application::with_state(State{db: addr.clone()}) // enable logger .middleware(middleware::Logger::default()) @@ -67,6 +70,11 @@ fn main() { .bind("127.0.0.1:8080").unwrap() .start(); + if cfg!(target_os = "linux") { // Subscribe to unix signals + let signals = Arbiter::system_registry().get::(); + signals.send(Subscribe(_addr.subscriber())); + } + println!("Started http server: 127.0.0.1:8080"); let _ = sys.run(); }