diff --git a/examples/todo/README.md b/examples/todo/README.md index 72070fd0..bb0c9263 100644 --- a/examples/todo/README.md +++ b/examples/todo/README.md @@ -9,33 +9,20 @@ a result, you'll need to have `sqlite3` and its headers installed: ## Running -**Before running, building, or testing this example, you'll need to ensure the -following:** +**Before running, building, or testing this example, you'll need to ensure that +a SQLite database file with the proper schema is present.** - 1. A SQLite database file with the proper schema is present. +On a Unix machine or with bash installed, you can simply run the `boostrap.sh` +script to create the database. The script installs the `diesel_cli` tools if +they're not already installed and runs the migrations. - On a Unix machine or with bash installed, you can simply run the - `boostrap.sh` script to create the database. The script installs the - `diesel_cli` tools if they're not already installed and runs the - migrations. The script will output a `DATABASE_URL` variable. +You can also install the Diesel CLI and run the migrations manually with the +following commands: - You can also install the Diesel CLI and run the migrations manually with - the following commands: +```sh +# install Diesel CLI tools +cargo install diesel_cli --no-default-features --features sqlite - ``` - # install Diesel CLI tools - cargo install diesel_cli --no-default-features --features sqlite - - # create db/db.sql - DATABASE_URL=db/db.sql diesel migration run - ``` - - 2. A `DATABASE_URL` environment variable is set that points to the SQLite - database file. - - Use the `DATABASE_URL` variable emitted from the `bootstrap.sh` script, or - enter it manually, as follows: - - * `DATABASE_URL=db/db.sql cargo build` - * `DATABASE_URL=db/db.sql cargo test` - * `DATABASE_URL=db/db.sql cargo run` +# create db/db.sql +diesel migration run --database-url="db/db.sql" +``` diff --git a/examples/todo/db/seed.sql b/examples/todo/db/seed.sql deleted file mode 100644 index 23f72530..00000000 --- a/examples/todo/db/seed.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE tasks ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - description VARCHAR NOT NULL, - completed BOOLEAN NOT NULL DEFAULT 0 -); - -INSERT INTO tasks (description) VALUES ("demo task"); diff --git a/examples/todo/src/db.rs b/examples/todo/src/db.rs index 5362075a..58bb2c37 100644 --- a/examples/todo/src/db.rs +++ b/examples/todo/src/db.rs @@ -9,7 +9,7 @@ use rocket::{Request, State, Outcome}; pub type SqlitePool = Pool>; -pub const DATABASE_URL: &'static str = env!("DATABASE_URL"); +pub const DATABASE_URL: &'static str = concat!(env!("CARGO_MANIFEST_DIR"), "/db/db.sql"); pub fn init_pool() -> SqlitePool { let manager = ConnectionManager::::new(DATABASE_URL);