-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Feature request: add_many method #34
Comments
Thanks, glad you find it interesting! Sometimes I think things are more complex than I would like them to be. If I want this thing in my database, I don't know why I would need to create complex ORM objects or write insertion queries just for that. Sort of highlights the philosophy of actually most of my open-source projects. But to the topic, I think there could be as it's common across almost every datastore, even in a CSV file (you just append the file without closing in-between). Not sure what would be the most Pythonic: repo.add_many([Item(...), Item(...)]) repo.add(Item(...), Item(...)) Not sure which I prefer more. I think I have also been thinking of adding some sort of sessions that are in every repo. Actually this is already there but there is no formal support for transactions. Perhaps at some point you could create transactions yourself and insert them however the repo does that, like: with repo:
# In a transaction. When exited, things are commited
repo.add(Item(...))
repo.add(Item(...)) However, this would require quite a bit of work. We probably need some sort of operation objects as Python lists/CSV files/etc. don't have built-in transaction mechanisms obviously, so it requires some amount of work. |
I don't know if it's more pythonic, but I like the To quote the zen of python:
Looking at other libraries, it seems the consensus to have a separate method:
I think it also helps write less code (no need to check As for the transactions: I'm focusing on a project that doesn't leverage mongo transactions (I started the project before transactions in mongodb were a thing), so I cannot speak of it, but it would be quite handy! |
First of all, kudos for making this library! I'm evaluating the usages in one of my project, it can use a better separation between the data layer and the logic!
I think that one thing that is missing is the
add_many
method to leverage the (often more performant) backend methods.The base implementation can be simply a series of calls to the
add
method.The text was updated successfully, but these errors were encountered: