1
0
Fork 0

Fix sqlite error

This commit is contained in:
Florian RICHER 2021-07-08 09:53:19 +02:00
parent c54cdc98ba
commit ee2bfbb769
8 changed files with 29 additions and 4 deletions

2
.gitignore vendored
View file

@ -1 +1,3 @@
/target
db/
!db/.gitkeep

View file

@ -9,5 +9,5 @@ edition = "2018"
rocket = { version = "0.5.0-rc.1", features = ["secrets", "tls", "json"] }
rocket_codegen = "0.5.0-rc.1"
rocket_sync_db_pools = { version = "0.1.0-rc.1", features = ["diesel_sqlite_pool"] }
diesel = { version = "1.3", features = ["sqlite", "r2d2"] }
diesel_migrations = "1.3"
diesel = { version = "1.4.0", features = ["sqlite", "r2d2"] }
diesel_migrations = "1.4.0"

BIN
db/dev.db

Binary file not shown.

0
migrations/.gitkeep Normal file
View file

View file

@ -0,0 +1 @@
DROP TABLE tasks

View file

@ -0,0 +1,8 @@
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");
INSERT INTO tasks (description) VALUES ("demo task2");

View file

@ -1,6 +1,8 @@
#[macro_use] extern crate diesel;
#[macro_use] extern crate diesel_migrations;
use rocket::*;
use rocket::fairing::AdHoc;
use rocket_sync_db_pools::{database};
mod task;
@ -19,7 +21,19 @@ async fn get_log(conn: DbConn, id: i32) -> String {
format!("test {}, {:?}", id, result)
}
async fn run_migrations(rocket: Rocket<Build>) -> Rocket<Build> {
embed_migrations!();
let conn = DbConn::get_one(&rocket).await.expect("database connection");
conn.run(|c| embedded_migrations::run(c)).await.expect("can run migrations");
rocket
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![index, get_log]).attach(DbConn::fairing())
rocket::build()
.mount("/", routes![index, get_log])
.attach(DbConn::fairing())
.attach(AdHoc::on_ignite("Run Migrations", run_migrations))
}

View file

@ -12,7 +12,7 @@ mod schema {
}
use schema::tasks;
use schema::tasks::dsl::{tasks as all_tasks, completed as task_completed};
use schema::tasks::dsl::{tasks as all_tasks};
use crate::DbConn;