Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Dynamic Datasource Providers #800

Merged
merged 17 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bring back MSSQL connector
  • Loading branch information
mavilein committed Jun 29, 2020
commit 9ef26b8e3d90746a4d6809d77bd2c95165473d15
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub const SQLITE_SOURCE_NAME: &str = "sqlite";
pub const POSTGRES_SOURCE_NAME: &str = "postgresql";
const POSTGRES_SOURCE_NAME_HEROKU: &str = "postgres";
pub const MYSQL_SOURCE_NAME: &str = "mysql";
pub const MSSQL_SOURCE_NAME: &str = "sqlserver";

pub struct SqliteDatasourceProvider {}

Expand Down Expand Up @@ -118,3 +119,34 @@ fn validate_url(name: &str, expected_protocol: &str, url: StringFromEnvVar) -> R
))
}
}

pub struct MsSqlDatasourceProvider {}
impl MsSqlDatasourceProvider {
pub fn new() -> Self {
Self {}
}
}

impl DatasourceProvider for MsSqlDatasourceProvider {
fn is_provider(&self, provider: &str) -> bool {
provider == MSSQL_SOURCE_NAME
}

fn create(
&self,
name: &str,
provider: Vec<String>,
url: StringFromEnvVar,
documentation: &Option<String>,
connector: Box<dyn Connector>,
) -> Result<Datasource, String> {
Ok(Datasource {
name: String::from(name),
provider,
active_provider: MSSQL_SOURCE_NAME.to_owned(),
url: validate_url(name, "sqlserver://", url)?,
documentation: documentation.clone(),
connector,
})
}
}
4 changes: 4 additions & 0 deletions libs/datamodel/core/src/configuration/source/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ impl SourceLoader {
"mysql" => Some(Box::new(ExampleConnector::mysql())),
"postgres" | "postgresql" => Some(Box::new(ExampleConnector::postgres())),
"sqlite" => Some(Box::new(ExampleConnector::sqlite())),
#[cfg(feature = "mssql")]
"sqlserver" => Some(Box::new(ExampleConnector::mssql())),
_ => None, // if a connector is not known this is handled by the following code
};
connector
Expand All @@ -174,5 +176,7 @@ fn get_builtin_datasource_providers() -> Vec<Box<dyn DatasourceProvider>> {
Box::new(MySqlDatasourceProvider::new()),
Box::new(PostgresDatasourceProvider::new()),
Box::new(SqliteDatasourceProvider::new()),
#[cfg(feature = "mssql")]
Box::new(MsSqlSourceDefinition::new()),
]
}
4 changes: 0 additions & 4 deletions libs/datamodel/core/src/configuration/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ mod datasource_provider;
mod loader;
mod serializer;

//pub mod builtin;

#[cfg(feature = "mssql")]
pub use builtin::MSSQL_SOURCE_NAME;
// TODO: i think these constants should move to a more central place.
//pub use builtin::{MYSQL_SOURCE_NAME, POSTGRES_SOURCE_NAME, SQLITE_SOURCE_NAME};
pub use builtin_datasource_providers::*;
pub use datasource::*;
pub use datasource_provider::*;
Expand Down