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

Merge pull request #141 from pka/diesel-sqlite-fix

Read SQLite path from .env and fix DATABASE_URL
This commit is contained in:
Nikolay Kim 2019-06-16 08:44:13 +06:00 committed by GitHub
commit c8467d1ffd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View File

@ -1 +1 @@
DATABASE_URL=file:test.db
DATABASE_URL=test.db

View File

@ -9,7 +9,7 @@ Diesel's `Getting Started` guide using SQLite for Actix web
```bash
cargo install diesel_cli --no-default-features --features sqlite
cd examples/diesel
echo "DATABASE_URL=file:test.db" > .env
echo "DATABASE_URL=test.db" > .env
diesel migration run
```

View File

@ -13,6 +13,7 @@ use actix_web::{error, middleware, web, App, Error, HttpResponse, HttpServer};
use bytes::BytesMut;
use diesel::prelude::*;
use diesel::r2d2::{self, ConnectionManager};
use dotenv;
use futures::future::{err, Either};
use futures::{Future, Stream};
@ -120,8 +121,10 @@ fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix_web=info");
env_logger::init();
// Start 3 db executor actors
let manager = ConnectionManager::<SqliteConnection>::new("test.db");
dotenv::dotenv().ok();
let connspec = std::env::var("DATABASE_URL").expect("DATABASE_URL");
let manager = ConnectionManager::<SqliteConnection>::new(connspec);
let pool = r2d2::Pool::builder()
.build(manager)
.expect("Failed to create pool.");