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

Conversation

mavilein
Copy link
Contributor

@mavilein mavilein commented Jun 11, 2020

implementation of prisma/prisma#1487

followup PR to address comments: #863

@mavilein mavilein added this to the 2.1.0 milestone Jun 12, 2020
@mavilein mavilein modified the milestones: 2.1.0, 2.2.0 Jun 26, 2020
@mavilein mavilein changed the title [WIP] Dynamic Datasource Providers Dynamic Datasource Providers Jun 29, 2020
@mavilein mavilein changed the title Dynamic Datasource Providers Implement Dynamic Datasource Providers Jun 29, 2020
@mavilein mavilein merged commit 0789ed6 into master Jun 29, 2020
@mavilein mavilein deleted the datamodel-parser/dynamic-datasource-providers branch June 29, 2020 17:02
@pantharshit00
Copy link
Contributor

🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉

Comment on lines +4 to +12
pub trait DatasourceProvider {
/// Passes the provider arg from the datasource. Must return true for all provider names it can handle.
fn is_provider(&self, provider: &str) -> bool;

fn canonical_name(&self) -> &str;

fn can_handle_url(&self, name: &str, url: &StringFromEnvVar) -> Result<(), String>;

fn connector(&self) -> Box<dyn Connector>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add documentation here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you want to document in this case? It's returning the connector for this DataSourceProvider. And this is already stated in the signature.

Comment on lines +20 to +25
pub fn set_url(&mut self, url: &str) {
self.url = StringFromEnvVar {
from_env_var: None,
value: url.to_string(),
};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite follow what's going on in here; could we add documentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you add here? Don't know what to document in this case. I added some documentation to StringFromEnvVar in the followup PR. Check this one out if it helps.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you add here?

Haa, trick question! If I knew I would tell you.

I guess I'm unsure in general how StringFromEnvVar relates to the rest of the system. Judging by name I'm wondering why it's not just a String. Some pointers on what the intent of this construct would be helpful for anyone trying to understand what's going on here.

))
let validated_providers: Vec<_> = all_datasource_providers
.iter()
.map(|sd| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does sd stand for here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That stood for SourceDefinition which was the old name for DatasourceProvider. Changing this to provider.

Comment on lines +9 to +11
pub use builtin_datasource_providers::*;
pub use datasource::*;
pub use datasource_provider::*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the things I've struggled with when onboarding is tracking down where variables come from. It makes it hard to understand how the separate modules relate to each other and create a mental model of the crates. I'm not a fan of switching from explicit imports to globs here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you think this is a switch? I kept the same pattern for reexport that was present before as well.

Copy link
Contributor

@yoshuawuyts yoshuawuyts Jun 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot_2020-06-30 Implement Dynamic Datasource Providers by mavilein · Pull Request #800 · prisma prisma-engines

Why do you think this is a switch?

I might be mistaken, but to me this reads as named imports being replaced with globs. There weren't any globs before, but after this patch there are.


I kept the same pattern for reexport that was present before as well.

I know? Like I mentioned earlier in this thread: this is one of the patterns that makes the codebase hard to navigate. To me it comes off as convenient to author, but it trades away legibility. We don't have to change all instances of this pattern in a single go, but as a baseline I would like us to not introduce more of these and think it's worth bringing up in review.

libs/datamodel/core/tests/capabilities/mod.rs Show resolved Hide resolved
libs/datamodel/core/tests/common.rs Show resolved Hide resolved
libs/datamodel/core/tests/config/sources.rs Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants