mirror of https://github.com/rwf2/Rocket.git
Use static path to database file in todo example.
This commit is contained in:
parent
d17b392538
commit
b12058110d
|
@ -9,33 +9,20 @@ a result, you'll need to have `sqlite3` and its headers installed:
|
||||||
|
|
||||||
## Running
|
## Running
|
||||||
|
|
||||||
**Before running, building, or testing this example, you'll need to ensure the
|
**Before running, building, or testing this example, you'll need to ensure that
|
||||||
following:**
|
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
|
You can also install the Diesel CLI and run the migrations manually with the
|
||||||
`boostrap.sh` script to create the database. The script installs the
|
following commands:
|
||||||
`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
|
```sh
|
||||||
the following commands:
|
# install Diesel CLI tools
|
||||||
|
cargo install diesel_cli --no-default-features --features sqlite
|
||||||
|
|
||||||
```
|
# create db/db.sql
|
||||||
# install Diesel CLI tools
|
diesel migration run --database-url="db/db.sql"
|
||||||
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`
|
|
||||||
|
|
|
@ -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");
|
|
|
@ -9,7 +9,7 @@ use rocket::{Request, State, Outcome};
|
||||||
|
|
||||||
pub type SqlitePool = Pool<ConnectionManager<SqliteConnection>>;
|
pub type SqlitePool = Pool<ConnectionManager<SqliteConnection>>;
|
||||||
|
|
||||||
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 {
|
pub fn init_pool() -> SqlitePool {
|
||||||
let manager = ConnectionManager::<SqliteConnection>::new(DATABASE_URL);
|
let manager = ConnectionManager::<SqliteConnection>::new(DATABASE_URL);
|
||||||
|
|
Loading…
Reference in New Issue