adding feature flags

This commit is contained in:
neil 2020-11-01 18:00:55 +01:00
parent a69642ac11
commit cab8136e1e
1 changed files with 25 additions and 3 deletions

View File

@ -26,9 +26,28 @@ mod forward;
mod sniff;
mod templates;
type DbPool = r2d2::Pool<ConnectionManager<SqliteConnection>>;
// default to postgres
#[cfg(feature = "default")]
type DbConn = PgConnection;
#[cfg(feature = "default")]
embed_migrations!("migrations/postgres");
embed_migrations!();
#[cfg(feature = "postgres")]
type DbConn = PgConnection;
#[cfg(feature = "postgres")]
embed_migrations!("migrations/postgres");
#[cfg(feature = "sqlite")]
type DbConn = SqliteConnection;
#[cfg(feature = "sqlite")]
embed_migrations!("migrations/sqlite");
#[cfg(feature = "mysql")]
type DbConn = MysqlConnection;
#[cfg(feature = "mysql")]
embed_migrations!("migrations/mysql");
type DbPool = r2d2::Pool<ConnectionManager<DbConn>>;
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
@ -40,8 +59,11 @@ async fn main() -> std::io::Result<()> {
println!("Checking configuration file...");
CONFIG.check_version();
if CONFIG.database_path.len() == 0 {
println!("No database specified. Please enter a MySQL, PostgreSQL or SQLite connection string in config.toml.");
}
println!("Opening database {}", CONFIG.database_path);
let manager = ConnectionManager::<SqliteConnection>::new(&CONFIG.database_path);
let manager = ConnectionManager::<DbConn>::new(&CONFIG.database_path);
let pool = r2d2::Pool::builder()
.build(manager)
.expect("ERROR: main: Failed to create the database pool.");