diff --git a/.gitignore b/.gitignore index e63b1ee..f4214eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ back/target/ front/dist/ back/public/ +back/data/ +back/Cargo.lock -back/Cargo.lock \ No newline at end of file diff --git a/back/data/data.db b/back/data/data.db index e69de29..df4b1ba 100644 Binary files a/back/data/data.db and b/back/data/data.db differ diff --git a/back/src/creat_db.rs b/back/src/create_db.rs similarity index 52% rename from back/src/creat_db.rs rename to back/src/create_db.rs index ec5a2ed..60140e1 100644 --- a/back/src/creat_db.rs +++ b/back/src/create_db.rs @@ -1,15 +1,16 @@ -use sqlite::{Connection, State}; +use sqlite::{Connection, State, Error}; -fn main() -> sqlite::Result<()> { +pub fn init() -> sqlite::Result<()> { let conn = Connection::open("./data/data.db")?; conn.execute( - "CREATE TABLE articles ( + "CREATE TABLE IF NOT EXISTS articles ( id INTEGER PRIMARY KEY, title TEXT NOT NULL, subTitle TEXT, - content TEXT NOT NULL, + content TEXT NOT NULL )", - [], )?; -} \ No newline at end of file + + Ok(()) +} diff --git a/back/src/main.rs b/back/src/main.rs index a91bc15..e090ab8 100644 --- a/back/src/main.rs +++ b/back/src/main.rs @@ -3,6 +3,9 @@ use actix_files::Files; use serde_json::json; use sqlite::{Connection, State, Error}; +mod create_db; +use create_db::init; + #[get("/api/hello")] async fn hello() -> impl Responder { HttpResponse::Ok().body("Hello world!") @@ -45,7 +48,7 @@ async fn api() -> impl Responder { #[actix_web::main] async fn main() -> Result<(), std::io::Error> { - let conn = Connection::open("./data/data.db"); + init(); HttpServer::new(|| { App::new()