-
Notifications
You must be signed in to change notification settings - Fork 99
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
add support for bulk_update #148
base: master
Are you sure you want to change the base?
Conversation
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.
Thanks for the PR. I had a look and could see a few points.
I have to admit I'm not sure how the API should look like. I'll probably take a look at a few examples in other projects. Maybe you can update the PR to show the current signature of the bulk update. |
https://github.com/collerek/ormar/blob/1ffb28d7b06f3f7989a6219c900e2fd441cbea42/ormar/queryset/queryset.py#L1064 I think that ormar do the same thing here. |
It is also standard bulk update as Django: https://docs.djangoproject.com/en/4.0/ref/models/querysets/#bulk-update |
orm/models.py
Outdated
] | ||
expr = ( | ||
self.table.update() | ||
.where(self.table.c.id == sqlalchemy.bindparam(self.pkname)) |
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.
Need to get primary key column dynamically. The id
is hard-coded.
orm/models.py
Outdated
@@ -20,6 +22,8 @@ | |||
"lte": "__le__", | |||
} | |||
|
|||
MODEL = typing.TypeVar("MODEL", bound="Model") |
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.
What value does this bring? I mean we could call bulk_update with Model
itself. right?
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.
What do you mean? We use it as a type annotation for obj
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.
Yeah I understand. I mean you've done this:
def bulk_update(self, objects: typing.List[MODEL], ...):
....
What would be the difference if we did:
def bulk_update(self, objects: typing.List[Model], ...):
....
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.
In this case Model will be undefined because it has been defined after bulk_update
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.
Maybe "Model" ?
@@ -454,6 +467,43 @@ async def update(self, **kwargs) -> None: | |||
|
|||
await self.database.execute(expr) | |||
|
|||
async def bulk_update( |
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.
Sorry I should've noticed this earlier, apologies for that.
But maybe a general refactor would be useful here?
There's a lot of nested code here and it's not very readable. What do you think?
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.
Yeah I agree with you it needs to be more readable
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.
@aminalaee Any updates ?
9f4e83d
to
daf5b5e
Compare
daf5b5e
to
6f79635
Compare
TBH I think this is really good and useful but as long as the We can keep it until then. |
So, maybe we need to add it to |
yes, I have an old PR which is doing it but It's not really the best way but it can give you some ideas. Feel free to take a look at that and start your own. |
Yeah sure, I will take a look at it. |
* The bulk_update is an adaptation of encode/orm#148
No description provided.