Skip to content

Commit

Permalink
implemet unique index for sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
omidekz committed Jun 8, 2024
1 parent faf0475 commit 9c8e553
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tortoise/contrib/sqlite/indexes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import Sequence
from tortoise.indexes import UniqueIndexABC


class UniqueIndex(UniqueIndexABC[Sequence[str]]):
def nulls(self, null_fields: Sequence[str]):
conditions = tuple(
map(
lambda field_name: f"{field_name} is not null",
null_fields or [],
)
)
result = " and ".join(conditions)
return f"where {result}" if result else result

0 comments on commit 9c8e553

Please sign in to comment.