refs #0 The root commit.
This commit is contained in:
27
back/core/field.py
Normal file
27
back/core/field.py
Normal file
@@ -0,0 +1,27 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user