This repository has been archived by the owner on Jan 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
Implement CollectionName
enum to store db collection names
#935
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
greged93
reviewed
Apr 9, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea, but what do you think of the following:
- Add a trait which allows to convert a type to string (as a static function, not a method).
pub trait ToStringType {
fn to_string() -> String;
}
- Implement this on the
StoredXXX
types. - Update the Mongo wrapper to take
pub async fn get_one<T>(
&self,
filter: impl Into<Option<Document>>,
sort: impl Into<Option<Document>>,
) -> DatabaseResult<Option<T>>
where
T: DeserializeOwned + ToStringType + Unpin + Send + Sync,
Then we can just do in the body of the function
let find_one_option = FindOneOptions::builder().sort(sort).build();
let collection = self.0.collection::<T>(T::to_string());
let result = collection.find_one(filter, find_one_option).await?;
Ok(result)
Nice, I just took up this idea almost completely. I just called the trait a little differently so as not to cause confusion with the many |
greged93
approved these changes
Apr 10, 2024
anukkrit149
pushed a commit
to karnotxyz/kakarot-rpc
that referenced
this pull request
Aug 9, 2024
<!--- Please provide a general summary of your changes in the title above --> <!-- Give an estimate of the time you spent on this PR in terms of work days. Did you spend 0.5 days on this PR or rather 2 days? --> Time spent on this PR: ## Pull request type <!-- Please try to limit your pull request to one type, submit multiple pull requests if needed. --> Please check the type of change your PR introduces: - [ ] Bugfix - [ ] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no api changes) - [ ] Build related changes - [ ] Documentation content changes - [ ] Other (please describe): ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> Resolves #<Issue number> ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - - - <!-- Reviewable:start --> - - - This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/kkrt-labs/kakarot/935) <!-- Reviewable:end -->
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Time spent on this PR: 20 min
Pull Request type
Please check the type of change your PR introduces:
What is the new behavior?
To avoid any typos or errors when writing the names of the collections in the Mongo DB database, a
CollectionName
enum is created and it contains anas_str
method in its implementation which allows you to find the name of all collections in a Rust idiomatic way.Does this introduce a breaking change?