= None;
let conn = DbConn::new(memory_db);
- conn.save_user(None, "admin", "aoeu", true, true).await.unwrap();
- conn.save_user(None, "gm_1", "aoeu", false, true).await.unwrap();
+ conn.save_user(None, "admin", "aoeu", true, true)
+ .await
+ .unwrap();
+ conn.save_user(None, "gm_1", "aoeu", false, true)
+ .await
+ .unwrap();
Core::new(assets, conn)
}
@@ -362,7 +370,7 @@ mod test {
Ok(None) => panic!("no matching user row for the session id"),
Err(err) => panic!("{}", err),
}
- },
+ }
ResultExt::Err(err) => panic!("{}", err),
ResultExt::Fatal(err) => panic!("{}", err),
}
diff --git a/visions/server/src/database/disk_db.rs b/visions/server/src/database/disk_db.rs
new file mode 100644
index 0000000..5b41a28
--- /dev/null
+++ b/visions/server/src/database/disk_db.rs
@@ -0,0 +1,338 @@
+use std::path::Path;
+
+use async_std::channel::{bounded, Receiver, Sender};
+use include_dir::{include_dir, Dir};
+use lazy_static::lazy_static;
+use rusqlite::Connection;
+use rusqlite_migration::Migrations;
+
+use crate::{database::{DatabaseResponse, Request}, types::FatalError};
+
+use super::{types::GameId, CharacterId, CharsheetRow, DatabaseRequest, SessionId, UserId, UserRow};
+
+static MIGRATIONS_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/migrations");
+
+lazy_static! {
+ static ref MIGRATIONS: Migrations<'static> =
+ Migrations::from_directory(&MIGRATIONS_DIR).unwrap();
+}
+
+pub struct DiskDb {
+ conn: Connection,
+}
+
+impl DiskDb {
+ pub fn new(path: Option
) -> Result
+ where
+ P: AsRef,
+ {
+ let mut conn = match path {
+ None => Connection::open(":memory:").expect("to create a memory connection"),
+ Some(path) => Connection::open(path).expect("to create connection"),
+ };
+
+ MIGRATIONS
+ .to_latest(&mut conn)
+ .map_err(|err| FatalError::DatabaseMigrationFailure(format!("{}", err)))?;
+
+ // setup_test_database(&conn)?;
+
+ Ok(DiskDb { conn })
+ }
+
+ pub fn user(&self, id: &UserId) -> Result