1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-30 03:50:42 +00:00

update examples/diesel readme

This commit is contained in:
ami44 2017-12-31 08:12:26 +01:00
parent 5741b8b372
commit d8548ad83b
3 changed files with 38 additions and 7 deletions

View file

@ -5,8 +5,8 @@ authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
[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"] }

View file

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

View file

@ -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::<ProcessSignals>();
signals.send(Subscribe(_addr.subscriber()));
}
println!("Started http server: 127.0.0.1:8080");
let _ = sys.run();
}