Skip to content

Commit

Permalink
fixes over bulk updating method for Model
Browse files Browse the repository at this point in the history
  • Loading branch information
phenobarbital committed Jul 10, 2024
1 parent 9020ab7 commit 3a21a04
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions asyncdb/drivers/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,23 +1010,20 @@ async def _updating_(self, *args, _filter: dict = None, **kwargs):
fields = model.columns(model)
if _filter is None and args:
_filter = args[0]
cols = []
source = {}
new_cond = {}
n = 1
for name, field in fields.items():
try:
val = kwargs[name]
except (KeyError, AttributeError):
continue
## getting the value of column:
value = self._get_value(field, val)
if name in _filter:
new_cond[name] = value
datatype = field.type
value = Entity.escapeLiteral(value, datatype)
source[name] = value
if name in _filter:
new_cond[name] = value
n += 1
try:
set_fields = ", ".join(
[f"{key} = {val}" for key, val in source.items()]
Expand All @@ -1036,6 +1033,8 @@ async def _updating_(self, *args, _filter: dict = None, **kwargs):
self._logger.debug(f"UPDATE: {_update}")
job = self._connection.query(_update)
job.result() # Waits for the query to finish
num_affected_rows = job.num_dml_affected_rows
print(f'UPDATED rows: {num_affected_rows}')
new_conditions = {**_filter, **new_cond}
condition = self._where(fields, **new_conditions)
_all = f"SELECT * FROM {table} {condition}"
Expand Down

0 comments on commit 3a21a04

Please sign in to comment.