Skip to content

Commit 170ee36

Browse files
committed
Gate databases behind features #28
1 parent 6cbe5d0 commit 170ee36

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

Cargo.toml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ edition = "2021"
55
authors = ["Sudo Dios"]
66
description = "Rust backend for LibreSpeed"
77

8+
[features]
9+
default = ["sqlite","mysql","postgres"]
10+
11+
sqlite = ["dep:rusqlite"]
12+
mysql = ["dep:mysql"]
13+
postgres = ["dep:postgres"]
14+
815
[dependencies]
916
#async net
10-
tokio = {version = "1.48.0", features = ["net","io-util","rt","macros","rt-multi-thread"]}
17+
tokio = {version = "1.48.0", features = ["net","io-util","rt","macros","rt-multi-thread","sync"]}
1118
tokio-rustls = {version = "0.26.4", features = ["tls12","ring"], default-features = false}
1219
webpki-roots = "1.0.3"
1320
rustls-pemfile = "2.2.0"
@@ -25,9 +32,9 @@ serde = { version = "1.0.228", features = ["derive"] }
2532
#databases
2633
uuid = { version = "1.18.1", features = ["v4"] }
2734
chrono = "0.4.42"
28-
mysql = { version = "26.0.1",default-features = false }
29-
postgres = "0.19.12"
30-
rusqlite = { version = "0.37.0",features = ["bundled"] }
35+
mysql = { version = "26.0.1",default-features = false, optional = true }
36+
postgres = { version = "0.19.12", optional = true }
37+
rusqlite = { version = "0.37.0",features = ["bundled"], optional = true }
3138
#conf
3239
clap = { version = "4.5.49",features = ["std","color","help","usage"],default-features = false }
3340
toml = "0.9.8"

src/database/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@ use tokio::sync::Mutex;
55
use uuid::Uuid;
66
use crate::config::SERVER_CONFIG;
77
use crate::database::memory::MemoryDB;
8+
#[cfg(feature = "mysql")]
89
use crate::database::mysql::MySql;
910
use crate::database::none::NoneDB;
11+
#[cfg(feature = "postgres")]
1012
use crate::database::postgres::Postgres;
13+
#[cfg(feature = "sqlite")]
1114
use crate::database::sqlite::SQLite;
1215
use crate::results::TelemetryData;
1316

17+
#[cfg(feature = "mysql")]
1418
mod mysql;
1519
mod none;
20+
#[cfg(feature = "postgres")]
1621
mod postgres;
22+
#[cfg(feature = "sqlite")]
1723
mod sqlite;
1824
mod memory;
1925

@@ -34,16 +40,19 @@ pub fn generate_uuid () -> String {
3440
pub fn init () -> std::io::Result<Arc<Mutex<dyn Database + Send>>> {
3541
let config = SERVER_CONFIG.get().unwrap();
3642
match config.database_type.as_str() {
43+
#[cfg(feature = "mysql")]
3744
"mysql" => {
3845
let mysql_setup = mysql::init(&config.database_username,&config.database_password,&config.database_hostname,&config.database_name)?;
3946
info!("Database {} initialized successfully","Mysql");
4047
Ok(Arc::new(Mutex::new(MySql{connection : mysql_setup})))
4148
}
49+
#[cfg(feature = "postgres")]
4250
"postgres" => {
4351
let postgres_setup = postgres::init(&config.database_username,&config.database_password,&config.database_hostname,&config.database_name)?;
4452
info!("Database {} initialized successfully","Postgres");
4553
Ok(Arc::new(Mutex::new(Postgres {connection : postgres_setup})))
4654
}
55+
#[cfg(feature = "sqlite")]
4756
"sqlite" => {
4857
let sqlite_setup = sqlite::init(&config.database_file)?;
4958
info!("Database {} initialized successfully","Sqlite");

0 commit comments

Comments
 (0)