Skip to content

Commit

Permalink
refactor: inherit IntField to reduce duplicated code (#1628)
Browse files Browse the repository at this point in the history
  • Loading branch information
waketzheng authored May 25, 2024
1 parent 5768fba commit 7deda88
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions tortoise/fields/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class _db_oracle:
GENERATED_SQL = "INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY NOT NULL"


class BigIntField(Field[int], int):
class BigIntField(IntField):
"""
Big integer field. (64-bit signed)
Expand All @@ -110,12 +110,6 @@ class BigIntField(Field[int], int):
"""

SQL_TYPE = "BIGINT"
allows_generated = True

def __init__(self, primary_key: Optional[bool] = None, **kwargs: Any) -> None:
if primary_key or kwargs.get("pk"):
kwargs["generated"] = bool(kwargs.get("generated", True))
super().__init__(primary_key=primary_key, **kwargs)

@property
def constraints(self) -> dict:
Expand All @@ -127,9 +121,6 @@ def constraints(self) -> dict:
class _db_postgres:
GENERATED_SQL = "BIGSERIAL NOT NULL PRIMARY KEY"

class _db_sqlite:
GENERATED_SQL = "INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL"

class _db_mysql:
GENERATED_SQL = "BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT"

Expand All @@ -141,7 +132,7 @@ class _db_oracle:
GENERATED_SQL = "INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY NOT NULL"


class SmallIntField(Field[int], int):
class SmallIntField(IntField):
"""
Small integer field. (16-bit signed)
Expand All @@ -150,12 +141,6 @@ class SmallIntField(Field[int], int):
"""

SQL_TYPE = "SMALLINT"
allows_generated = True

def __init__(self, primary_key: Optional[bool] = None, **kwargs: Any) -> None:
if primary_key or kwargs.get("pk"):
kwargs["generated"] = bool(kwargs.get("generated", True))
super().__init__(primary_key=primary_key, **kwargs)

@property
def constraints(self) -> dict:
Expand All @@ -167,9 +152,6 @@ def constraints(self) -> dict:
class _db_postgres:
GENERATED_SQL = "SMALLSERIAL NOT NULL PRIMARY KEY"

class _db_sqlite:
GENERATED_SQL = "INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL"

class _db_mysql:
GENERATED_SQL = "SMALLINT NOT NULL PRIMARY KEY AUTO_INCREMENT"

Expand Down

0 comments on commit 7deda88

Please sign in to comment.