forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdriver.rs
More file actions
30 lines (25 loc) · 788 Bytes
/
driver.rs
File metadata and controls
30 lines (25 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use serde::{Deserialize, Serialize};
use super::error::Error;
use super::mysql::Mysql;
use super::sqlite::Sqlite;
use super::{Builder, Database};
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, derive_more::Display, Clone)]
pub enum Driver {
Sqlite3,
MySQL,
}
impl Driver {
/// .
///
/// # Errors
///
/// This function will return an error if unable to connect to the database.
pub fn build(&self, db_path: &str) -> Result<Box<dyn Database>, Error> {
let database = match self {
Driver::Sqlite3 => Builder::<Sqlite>::build(db_path),
Driver::MySQL => Builder::<Mysql>::build(db_path),
}?;
database.create_database_tables().expect("Could not create database tables.");
Ok(database)
}
}