mirror of https://github.com/rwf2/Rocket.git
Use static path to database file in todo example.
This commit is contained in:
parent
a13a4e258a
commit
e6a77c1573
|
@ -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
|
||||
|
||||
# create db/db.sql
|
||||
DATABASE_URL=db/db.sql diesel migration run
|
||||
diesel migration run --database-url="db/db.sql"
|
||||
```
|
||||
|
||||
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 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::<SqliteConnection>::new(DATABASE_URL);
|
||||
|
|
Loading…
Reference in New Issue