use url::{Url};
use errors::{Result, ResultExt};
#[cfg(feature = "mysql_support")]
pub mod mysql;
#[cfg(feature = "postgres_support")]
pub mod postgres;
#[cfg(feature = "sqlite_support")]
pub mod sqlite;
pub trait Driver {
fn ensure_migration_table_exists(&mut self);
fn remove_migration_table(&mut self);
fn get_current_number(&mut self) -> i32;
fn set_current_number(&mut self, number: i32);
fn migrate(&mut self, migration: String, number: i32) -> Result<()>;
}
pub fn get_driver(url: &str) -> Result<Box<Driver>> {
let parsed_url = Url::parse(url)
.chain_err(|| format!("Invalid URL: {}", url))?;
match parsed_url.scheme() {
#[cfg(feature = "postgres_support")]
"postgres" => postgres::Postgres::new(url).map(|d| Box::new(d) as Box<Driver>),
#[cfg(feature = "mysql_support")]
"mysql" => mysql::Mysql::new(url).map(|d| Box::new(d) as Box<Driver>),
#[cfg(feature = "sqlite_support")]
"sqlite" => sqlite::Sqlite::new(url).map(|d| Box::new(d) as Box<Driver>),
_ => bail!("Invalid URL: {}", url)
}
}