Skip to content

Commit

Permalink
fix for code analys
Browse files Browse the repository at this point in the history
  • Loading branch information
omidekz committed Jun 8, 2024
1 parent 6c02d74 commit b1e4b8e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 5 additions & 1 deletion tortoise/contrib/postgres/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,9 @@ class SpGistIndex(PostgreSQLIndex):


class UniqueIndex(UniqueIndexABC[Literal["distinct", "not distinct"]]):
def nulls(self, distinct_status: Literal["distinct", "not distinct"]):
@staticmethod
def _nulls(distinct_status: Literal["distinct", "not distinct"]):
return f"nulls {distinct_status}"

def nulls(self, distinct_status: Literal["distinct", "not distinct"]):
return self._nulls(distinct_status)
11 changes: 8 additions & 3 deletions tortoise/contrib/sqlite/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@


class UniqueIndex(UniqueIndexABC[Sequence[str]]):
def nulls(self, null_fields: Sequence[str]):

@staticmethod
def get_conditions(fields: Sequence[str]):
conditions = tuple(
map(
lambda field_name: f"{field_name} is not null",
null_fields or [],
fields or [],
)
)
result = " and ".join(conditions)
return " and ".join(conditions)

def nulls(self, null_fields: Sequence[str]):
result = self.get_conditions(null_fields)
return f"where {result}" if result else result
3 changes: 2 additions & 1 deletion tortoise/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,5 @@ def __init__(
self.extra += f" {self.nulls(nulls)}"

@abc.abstractmethod
def nulls(cls, distinct: T): ...
def nulls(self, distinct: T):
raise NotImplementedError(self, distinct, 'no handler found')

0 comments on commit b1e4b8e

Please sign in to comment.