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
get rid of MultiProviderConnector and move the logic to the datamod…
…el_connector crate
  • Loading branch information
mavilein committed Jun 29, 2020
commit 5fc11aaf3c7adf381eba8887a4fff65255ea1c79
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
use super::{declarative_connector::*, ScalarType};
use super::{declarative_connector::*, Connector, ScalarType};
use crate::ConnectorCapability;

pub struct BuiltinConnectors {}

impl BuiltinConnectors {
// returns a connector representing the intersection of all provided connectors
pub fn combined(connectors: Vec<Box<dyn Connector>>) -> Box<dyn Connector> {
mavilein marked this conversation as resolved.
Show resolved Hide resolved
// the standard library does not seem to offer an elegant way to do this. Don't want to pull in a dependency for this.
let mut combined_capabilities = vec![];
for connector in &connectors {
for capability in connector.capabilities() {
let supported_by_all_connectors = connectors.iter().all(|c| c.has_capability(*capability));

if supported_by_all_connectors {
combined_capabilities.push(*capability);
}
}
}

Box::new(DeclarativeConnector {
type_aliases: Vec::new(),
field_type_constructors: Vec::new(),
capabilities: combined_capabilities,
})
}

pub fn sqlite() -> DeclarativeConnector {
DeclarativeConnector {
type_aliases: vec![],
Expand Down
2 changes: 0 additions & 2 deletions libs/datamodel/connectors/datamodel-connector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ pub mod scalars;

mod builtin_connectors;
mod declarative_connector;
mod multi_provider_connector;

pub use builtin_connectors::BuiltinConnectors;
pub use declarative_connector::DeclarativeConnector;
pub use multi_provider_connector::MultiProviderConnector;

pub trait Connector: Send + Sync {
fn capabilities(&self) -> &Vec<ConnectorCapability>;
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions libs/datamodel/core/src/configuration/source/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::common::value_validator::ValueListValidator;
use crate::error::{DatamodelError, ErrorCollection};
use crate::StringFromEnvVar;
use crate::{ast, Datasource};
use datamodel_connector::{Connector, MultiProviderConnector};
use datamodel_connector::{BuiltinConnectors, Connector};

/// Helper struct to load and validate source configuration blocks.
pub struct SourceLoader {
Expand Down Expand Up @@ -135,7 +135,7 @@ impl SourceLoader {

let combined_connector: Box<dyn Connector> = {
let connectors = all_datasource_providers.iter().map(|sd| sd.connector()).collect();
Box::new(MultiProviderConnector::new(connectors))
BuiltinConnectors::combined(connectors)
};

// The first provider that can handle the URL is used to construct the Datasource.
Expand Down