From 31f6d1f4fc988edecf85d51709ea321b36ddf0c1 Mon Sep 17 00:00:00 2001 From: Waket Zheng Date: Sun, 8 Dec 2024 13:46:05 +0800 Subject: [PATCH] refactor: remove duplicated code in postgres indexes --- tortoise/contrib/postgres/indexes.py | 20 -------------------- tortoise/indexes.py | 4 +--- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/tortoise/contrib/postgres/indexes.py b/tortoise/contrib/postgres/indexes.py index c02f4f2e0..3346d4a68 100644 --- a/tortoise/contrib/postgres/indexes.py +++ b/tortoise/contrib/postgres/indexes.py @@ -1,7 +1,3 @@ -from typing import Optional, Tuple - -from pypika.terms import Term, ValueWrapper - from tortoise.indexes import PartialIndex @@ -10,22 +6,6 @@ class PostgreSQLIndex(PartialIndex): "CREATE INDEX {exists}{index_name} ON {table_name} USING{index_type}({fields}){extra};" ) - def __init__( - self, - *expressions: Term, - fields: Optional[Tuple[str, ...]] = None, - name: Optional[str] = None, - condition: Optional[dict] = None, - ) -> None: - super().__init__(*expressions, fields=fields, name=name) - if condition: - cond = " WHERE " - items = [] - for k, v in condition.items(): - items.append(f"{k} = {ValueWrapper(v)}") - cond += " AND ".join(items) - self.extra = cond - class BloomIndex(PostgreSQLIndex): INDEX_TYPE = "BLOOM" diff --git a/tortoise/indexes.py b/tortoise/indexes.py index 6561b76f2..fafde0790 100644 --- a/tortoise/indexes.py +++ b/tortoise/indexes.py @@ -71,8 +71,6 @@ def __init__( super().__init__(*expressions, fields=fields, name=name) if condition: cond = " WHERE " - items = [] - for k, v in condition.items(): - items.append(f"{k} = {ValueWrapper(v)}") + items = [f"{k} = {ValueWrapper(v)}" for k, v in condition.items()] cond += " AND ".join(items) self.extra = cond