mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 16:02:59 +01:00
update examples/diesel readme
This commit is contained in:
parent
5741b8b372
commit
d8548ad83b
@ -5,8 +5,8 @@ authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
env_logger = "0.4"
|
env_logger = "0.4"
|
||||||
actix = "^0.3.1"
|
actix = "^0.3.5"
|
||||||
actix-web = { git = "https://github.com/actix/actix-web.git" }
|
actix-web = { git = "https://github.com/actix/actix-web", features=["signal"] }
|
||||||
|
|
||||||
futures = "0.1"
|
futures = "0.1"
|
||||||
uuid = { version = "0.5", features = ["serde", "v4"] }
|
uuid = { version = "0.5", features = ["serde", "v4"] }
|
||||||
|
@ -4,17 +4,40 @@ Diesel's `Getting Started` guide using SQLite for Actix web
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
install `diesel_cli`
|
### init database sqlite
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cargo install diesel_cli --no-default-features --features sqlite
|
cargo install diesel_cli --no-default-features --features sqlite
|
||||||
```
|
cd actix-web/examples/diesel
|
||||||
|
|
||||||
```bash
|
|
||||||
echo "DATABASE_URL=file:test.db" > .env
|
echo "DATABASE_URL=file:test.db" > .env
|
||||||
diesel migration run
|
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
|
## 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)
|
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)
|
@ -16,8 +16,11 @@ extern crate actix;
|
|||||||
extern crate actix_web;
|
extern crate actix_web;
|
||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
|
|
||||||
|
use actix::*;
|
||||||
use actix_web::*;
|
use actix_web::*;
|
||||||
use actix::prelude::*;
|
use actix::prelude::*;
|
||||||
|
#[cfg(target_os = "linux")] use actix::actors::signal::{ProcessSignals, Subscribe};
|
||||||
|
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use futures::future::Future;
|
use futures::future::Future;
|
||||||
|
|
||||||
@ -59,7 +62,7 @@ fn main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Start http server
|
// Start http server
|
||||||
HttpServer::new(move || {
|
let _addr = HttpServer::new(move || {
|
||||||
Application::with_state(State{db: addr.clone()})
|
Application::with_state(State{db: addr.clone()})
|
||||||
// enable logger
|
// enable logger
|
||||||
.middleware(middleware::Logger::default())
|
.middleware(middleware::Logger::default())
|
||||||
@ -67,6 +70,11 @@ fn main() {
|
|||||||
.bind("127.0.0.1:8080").unwrap()
|
.bind("127.0.0.1:8080").unwrap()
|
||||||
.start();
|
.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");
|
println!("Started http server: 127.0.0.1:8080");
|
||||||
let _ = sys.run();
|
let _ = sys.run();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user