From 8f8fc0c46e1bbdaa3a15c1856e4f320adddb4b34 Mon Sep 17 00:00:00 2001 From: Lukian Date: Fri, 6 Dec 2024 01:30:34 +0100 Subject: [PATCH] Fixed databse init function --- back/data/data.db | Bin 8192 -> 0 bytes back/src/create_db.rs | 11 ++++++++--- back/src/main.rs | 10 +++++----- 3 files changed, 13 insertions(+), 8 deletions(-) delete mode 100644 back/data/data.db diff --git a/back/data/data.db b/back/data/data.db deleted file mode 100644 index df4b1bae9776ddcf50b6e841d543c37499ff8c0c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8192 zcmeI#F$=;l5Cz~w1VIqpoP-+{#Kl>#N|0i$8Y9@TYJ@;luyGaimzxePc5+tUBS*OQ zlHuF3SqH{yI$dw)*wT=-80TzE#2DkQDz5TmeKl{~p7r0t+29d1+!Sw)m|F-0AOHaf zKmY;|fB*y_009U<;P(WcV_s`_I{dY<@jlV<&6-1^(|oT?rSOy>WeL(E^hB-Z*%wP bM<4(J2tWV=5P$##AOHafKmY;|_+x=LoZL9g diff --git a/back/src/create_db.rs b/back/src/create_db.rs index 60140e1..06e2663 100644 --- a/back/src/create_db.rs +++ b/back/src/create_db.rs @@ -1,9 +1,14 @@ -use sqlite::{Connection, State, Error}; +use sqlite::{Connection, OpenFlags}; pub fn init() -> sqlite::Result<()> { - let conn = Connection::open("./data/data.db")?; + let conn = Connection::open_with_flags( + "./data/data.db", + OpenFlags::new() + .with_create() + .with_read_write() + ); - conn.execute( + conn?.execute( "CREATE TABLE IF NOT EXISTS articles ( id INTEGER PRIMARY KEY, title TEXT NOT NULL, diff --git a/back/src/main.rs b/back/src/main.rs index e090ab8..320c18f 100644 --- a/back/src/main.rs +++ b/back/src/main.rs @@ -1,10 +1,10 @@ +mod create_db; +use create_db::init; + use actix_web::{App, HttpServer, get, Responder, HttpResponse, http::header::ContentType}; use actix_files::Files; use serde_json::json; -use sqlite::{Connection, State, Error}; - -mod create_db; -use create_db::init; +use sqlite::{Connection, State}; #[get("/api/hello")] async fn hello() -> impl Responder { @@ -48,7 +48,7 @@ async fn api() -> impl Responder { #[actix_web::main] async fn main() -> Result<(), std::io::Error> { - init(); + let _ = init(); HttpServer::new(|| { App::new()