Files
library/back/core/field.py
2023-09-13 20:37:14 +03:00

28 lines
748 B
Python

from sqlalchemy import Column, Integer, String
def get_field(field_attrs: dict) -> Column:
"""
Construct sqlalchemy field using dictionary with field attributes.
Returns the sqlalchemy column.
:param field_attrs: The dictionary with field attributes.
"""
column_attrs = {}
for key, value in field_attrs.items():
if key == "type":
match value:
case "str":
column_attrs["type_"] = String
case "int":
column_attrs["type_"] = Integer
case "file":
column_attrs["type_"] = String
elif key == "nullable":
column_attrs["nullable"] = value
return Column(**column_attrs)