Restructuring, prepare for room, Discord support
This commit is contained in:
parent
1fbb0ede50
commit
ed11799bf5
8 changed files with 492 additions and 239 deletions
|
@ -1,4 +1,4 @@
|
|||
use crate::Word;
|
||||
use crate::word::Word;
|
||||
|
||||
use derive_more::From;
|
||||
use std::path::PathBuf;
|
||||
|
@ -15,16 +15,23 @@ pub enum DatabaseCreationError {
|
|||
IoError(std::io::Error),
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub enum DatabaseType {
|
||||
#[default]
|
||||
InMemory,
|
||||
OnDisk(String),
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct DatabaseSettings {
|
||||
pub db_type: DatabaseType,
|
||||
}
|
||||
|
||||
impl Database {
|
||||
pub fn new(
|
||||
testing: bool,
|
||||
) -> Result<Self, DatabaseCreationError> {
|
||||
let conn = if testing {
|
||||
Connection::open_in_memory()
|
||||
} else {
|
||||
let path = PathBuf::from("shiritori.db");
|
||||
//fs::create_dir_all(path.parent().unwrap())?;
|
||||
Connection::open(path)
|
||||
pub fn new(settings: DatabaseSettings) -> Result<Self, DatabaseCreationError> {
|
||||
let conn = match settings.db_type {
|
||||
DatabaseType::InMemory => Connection::open_in_memory(),
|
||||
DatabaseType::OnDisk(path) => Connection::open(PathBuf::from(path)),
|
||||
}?;
|
||||
conn.execute(
|
||||
"CREATE TABLE IF NOT EXISTS word (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue