Skip to content

Commit

Permalink
fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Micheal Gendy committed Feb 22, 2022
1 parent 2871fdb commit 2107de3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
11 changes: 7 additions & 4 deletions databases/backends/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,13 @@ def _compile_many(
compiled = queries[0].compile(
dialect=self._dialect, compile_kwargs={"render_postcompile": True}
)
for args in values:
for key, val in args.items():
if key in compiled._bind_processors:
args[key] = compiled._bind_processors[key](val)
if not isinstance(queries[0], DDLElement):
for args in values:
for key, val in args.items():
if key in compiled._bind_processors:
args[key] = compiled._bind_processors[key](val)
else:
values = []
return compiled.string, values

@property
Expand Down
22 changes: 17 additions & 5 deletions databases/backends/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,23 @@ def _compile_many(
compiled = queries[0].compile(
dialect=self._dialect, compile_kwargs={"render_postcompile": True}
)
for args in values:
for key, val in args.items():
if key in compiled._bind_processors:
args[key] = compiled._bind_processors[key](val)
return compiled.string, values
new_values = []
if not isinstance(queries[0], DDLElement):
for args in values:
sorted_args = sorted(args.items())
mapping = {
key: "$" + str(i) for i, (key, _) in enumerate(sorted_args, start=1)
}
compiled_query = compiled.string % mapping
processors = compiled._bind_processors
values = [
processors[key](val) if key in processors else val
for key, val in sorted_args
]
new_values.append(values)
else:
compiled_query = compiled.string
return compiled_query, new_values

@staticmethod
def _create_column_maps(
Expand Down
18 changes: 13 additions & 5 deletions databases/backends/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,19 @@ def _compile_many(
compiled = queries[0].compile(
dialect=self._dialect, compile_kwargs={"render_postcompile": True}
)
for args in values:
for key, val in args.items():
if key in compiled._bind_processors:
args[key] = compiled._bind_processors[key](val)
return compiled.string, values
new_values = []
if not isinstance(queries[0], DDLElement):
for args in values:
temp_arr = []
for key in compiled.positiontup:
raw_val = args[key]
if key in compiled._bind_processors:
val = compiled._bind_processors[key](raw_val)
else:
val = raw_val
temp_arr.append(val)
new_values.append(temp_arr)
return compiled.string, new_values

@property
def raw_connection(self) -> aiosqlite.core.Connection:
Expand Down

0 comments on commit 2107de3

Please sign in to comment.