-
Notifications
You must be signed in to change notification settings - Fork 0
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
Integration of MongoDB #8
Conversation
…ed up dependencies
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.
looks pretty good, mostly just needs error handling
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.
The store module needs some refactoring, please take a look at my comment below for more details.
The store should be completely transparent to the endpoints, and they should know nothing about its implementation details, only its API. The store could be a file, a MySQL, or just an interface with another HTTP API... the endpoints wouldn't tell the difference.
For that, we should keep all the dependencies and business logic related to the DB in store.rs
.
I have drafted a solution with that approach, which you can see in this diff https://github.com/ideal-lab5/murmur-api/compare/juan/draft-store-approach
The solution proposed is to create a new Store
struct that holds the db connection as a property. It implements three methods: init
, load
and write
, they are what main.rs
knows about.
Ideally, we should go a step forward and make this a Trait, then we could have multiple Store implementations of that trait... but it looks like State<>
doesn't support traits.
Keep in mind that it is just a draft and it needs to be finished off: the new
endpoint isn't ready (and it is commented out), there might be some warnings to clean up and the hardcoded const needs to be moved to environment variables
I intend to add error handling and then will raise another PR. I'm afraid that trying to do generic support will need a lot of custom code. An example of using multiple databases is given here: https://github.com/rwf2/Rocket/blob/v0.5/examples/databases/src/main.rs. It appears (at first glance) that rocket hard couples your database to your API. Notice that they mount each database to a different URL as well. |
…severe issues such as having no records
We don't need multiple concurrent databases like in that example, we only need one at a time. You can decouple the database to your API in Rocket, and that is what I have done in the example that I shared with you earlier, please take a look at it https://github.com/ideal-lab5/murmur-api/compare/juan/draft-store-approach#diff-42cb6807ad74b3e201c5a7ca98b911c5fa08380e942be6e4ac5807f8377f87fcR162-R164 |
Requested changes have been implemented. |
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.
We should be good after addressing the open comments
This looks ready to be merged, but there's a DB connection error, I guess the MongoDB is down?
|
Closing in favour of #17 |
In this branch we have introduced integration with MongoDB to store MMRs. There is a toggle that is introduced that allows storage in local files or in MongoDB. There are two functions implemented: write_to_db and load_from_db. Write to DB can take in any generic object and store it in MongoDB after being give the db name, collection name, and a connection. After an object is written into the DB, the corresponding (unique) object ID will be stored in the cookies for retrieval in a later session. load_from_db can load any generic object so long as you provide the db name, collection name, object id, and connection.
This is related to issue #2