Skip to content

Commit 24fbafd

Browse files
authored
add async to setup_db (#7)
2 parents d9667ce + ca81f07 commit 24fbafd

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

backend/src/db/init.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use redb::{Database, DatabaseError};
22
use thiserror::Error;
3-
use std::{fs, path::PathBuf, sync::Arc};
3+
use std::{path::PathBuf, sync::Arc};
4+
use tokio::fs;
45

56
#[derive(Clone)]
67
pub struct DbState {
@@ -22,11 +23,11 @@ pub enum DbSetupError {
2223
Redb(#[from] DatabaseError),
2324
}
2425

25-
pub fn setup_db() -> Result<DbState, DbSetupError> {
26+
pub async fn setup_db() -> Result<DbState, DbSetupError> {
2627
let data_dir = PathBuf::from("data");
2728

2829
if !data_dir.exists() {
29-
fs::create_dir_all(&data_dir)?;
30+
fs::create_dir_all(&data_dir).await?;
3031
}
3132

3233
let db_path = data_dir.join("rk_site.redb");

backend/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
2525
)
2626
});
2727

28-
let db_state = setup_db().expect("Failed to set up Database");
28+
let db_state = setup_db().await?;
2929

3030
let app = Router::new()
3131
.fallback_service(frontend_dir) // serve frontend build directory

0 commit comments

Comments
 (0)