refactor: Improve db inspection

- Add support to postgresql numeric type.
- Improve field configuration handling for numeric and decimal types
This commit is contained in:
Isaque Alves 2022-06-17 01:34:55 -03:00
parent 4abc464ce0
commit 1ac16188fc
2 changed files with 8 additions and 2 deletions

View File

@ -30,8 +30,13 @@ class Column(BaseModel):
index = "index=True, "
if self.data_type in ["varchar", "VARCHAR"]:
length = f"max_length={self.length}, "
if self.data_type == "decimal":
length = f"max_digits={self.max_digits}, decimal_places={self.decimal_places}, "
if self.data_type in ["decimal", "numeric"]:
length_parts = []
if self.max_digits:
length_parts.append(f"max_digits={self.max_digits}")
if self.decimal_places:
length_parts.append(f"decimal_places={self.decimal_places}")
length = "".join(length_parts)
if self.null:
null = "null=True, "
if self.default is not None:

View File

@ -25,6 +25,7 @@ class InspectPostgres(Inspect):
"date": self.date_field,
"time": self.time_field,
"decimal": self.decimal_field,
"numeric": self.decimal_field,
"uuid": self.uuid_field,
"jsonb": self.json_field,
"bytea": self.binary_field,