Skip to content

Commit

Permalink
'Refactored by Sourcery'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourcery AI committed Aug 28, 2023
1 parent 5188209 commit 7d4ed25
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions litestar/contrib/sqlalchemy/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,15 @@ def __repr__(self) -> str:
case_predicate = f" AND {self.predicate!s}" if self.predicate is not None else ""
if self.command == "INSERT":
sets, sets_tos = zip(*self._on_sets.items())
return "WHEN NOT MATCHED{} THEN {} ({}) VALUES ({})".format(
case_predicate,
self.command,
", ".join(sets),
", ".join(map(str, sets_tos)),
)
return f'WHEN NOT MATCHED{case_predicate} THEN {self.command} ({", ".join(sets)}) VALUES ({", ".join(map(str, sets_tos))})'

# WHEN MATCHED clause
sets = (
", ".join([f"{match_set[0]} = {match_set[1]}" for match_set in self._on_sets.items()])
if self._on_sets
else ""
)
return "WHEN MATCHED{} THEN {}{}".format(
case_predicate,
self.command,
f" SET {sets!s}" if self._on_sets else "",
)
return f'WHEN MATCHED{case_predicate} THEN {self.command}{f" SET {sets!s}" if self._on_sets else ""}'

def values(self, **kwargs: Any) -> Self:
self._on_sets = kwargs
Expand Down

0 comments on commit 7d4ed25

Please sign in to comment.