-
Notifications
You must be signed in to change notification settings - Fork 258
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
Simplify client usage for CosmosDB #676
Conversation
1cfae56
to
ba6a895
Compare
ba6a895
to
d78e189
Compare
For a good overview of clients and sub-clients, see https://azure.github.io/azure-sdk/dotnet_introduction.html#dotnet-subclients. @annelo-msft drove this effort and while the guidelines above are specific to .NET, in concept they are fairly cross-language. |
@yoshuawuyts In case you aren't aware, the Rust SDK storage crates do currently have sub-clients that are similar to Heath's link above. Example from the let blob_client =
StorageAccountClient::new_access_key(http_client.clone(), &account, &master_key)
.as_container_client(&container)
.as_blob_client(&blob_name); Another example from let http_client = azure_core::new_http_client();
let storage_client =
StorageAccountClient::new_access_key(http_client.clone(), &account, &master_key)
.as_storage_client();
let blob_service = storage_client.as_blob_service_client();
...
let iv = blob_service.list_containers().execute().await?; When I was working on splitting up the storage crates, I did play with a similar change to what you have done here to make the names less verbose by dropping the let blob =
StorageAccountClient::new_access_key(http_client.clone(), &account, &master_key)
.container(&container)
.blob(&blob_name); However, the following code that uses the blob client looks like this... let res = blob_client
.put_block_blob(data.clone())
.content_type("text/plain")
.hash(&hash)
.execute()
.await?; In the end I (slightly reluctantly) decided that this might be less clear if Personally I do find the shorter names more "Rusty", and would be happy to switch to the more concise naming. |
This is why I'm leaning toward keeping the /cc @annelo-msft @tg-msft for their thoughts. Certainly where we can reduce noise / unnecessities like @yoshuawuyts is also suggestion is great. |
We've found tremendous benefit in mirroring the resource hierarchy names in our navigation methods. A lot of customers struggle to make the distinction between simply walking down the resource hierarchy locally vs. doing something on the service that modifies those resources (i.e., am I getting a new container client or creating a container?). Consistent use of |
Closing in favor of #684 |
Per discussion in Azure#676, this renames the various as_X_client to X_client
This PR is an attempt to streamline the usage of Cosmos in Rust. I noticed that compared to for example the mongodb driver our API can at times feel heavy to use. In order to improve our user experience, this PR does two things:
.clone
on generated clients._client
suffix from most operations.I'm rather happy with how this experiment turned out. Though I expect we might want to talk it over in a sync meeting first, so I'm marking this as a "Draft" until we've had a chance to talk this over. Thanks!
Example
Prior Art
I felt reasonably confident that dropping the
.clone
requirement by users was the right way to go. This is a typical Rust API design issue. I was less sure about dropping the_client
suffixes, so I checked our other SDKs before trying this out. Aside from Rust I'm most comfortable reading JavaScript and Golang, and neither of their respective Cosmos SDKs seems to have the_client
convention, making Rust the odd one out.Future Opportunities
We're almost done with the
IntoFuture
conversions, and I'm going to be filing a stabilization PR for this in Rust soon too. No guarantees, though I'm feeling optimistic. Once that comes through our earlier example would be streamlined even further:We can probably streamline this even further by removing the
clone
requirement ondatabase_name
and other APIs where we currently require it. And with in #591 we're discussing ways we could potentially streamline the Cosmos SDK client construction even more.I think now that we're rounding out some of our existing refactors we can start thinking of ways we can streamline the APIs, and I hope this PR feels like a step in the right direction!