generated from daniil-berg/boilerplate-py
Minor changes
This commit is contained in:
parent
a64708dedd
commit
20272c4b4a
@ -54,7 +54,7 @@ def from_sqla(db_model: Type[DeclarativeMeta], incl_many_to_one: bool = True, in
|
|||||||
config: Type[BaseConfig] = OrmConfig, exclude: Container[str] = (),
|
config: Type[BaseConfig] = OrmConfig, exclude: Container[str] = (),
|
||||||
add_fields: dict[str, FieldDef] = None):
|
add_fields: dict[str, FieldDef] = None):
|
||||||
assert isinstance(db_model, DeclarativeMeta)
|
assert isinstance(db_model, DeclarativeMeta)
|
||||||
assert not (incl_one_to_many and incl_many_to_one)
|
assert not (incl_one_to_many and incl_many_to_one), "Pydantic is unable to handle the circular relationship"
|
||||||
fields = {}
|
fields = {}
|
||||||
for attr in inspect(db_model).attrs:
|
for attr in inspect(db_model).attrs:
|
||||||
if attr.key in exclude:
|
if attr.key in exclude:
|
||||||
|
@ -9,7 +9,6 @@ from orm2pydantic.sqla import from_sqla
|
|||||||
|
|
||||||
|
|
||||||
ORMBase = declarative_base()
|
ORMBase = declarative_base()
|
||||||
engine = create_engine("sqlite://")
|
|
||||||
|
|
||||||
|
|
||||||
def default_factory() -> str: return '1'
|
def default_factory() -> str: return '1'
|
||||||
@ -65,11 +64,12 @@ class Address(AbstractBase):
|
|||||||
|
|
||||||
|
|
||||||
def main_test() -> None:
|
def main_test() -> None:
|
||||||
|
engine = create_engine("sqlite://")
|
||||||
AbstractBase.metadata.create_all(engine)
|
AbstractBase.metadata.create_all(engine)
|
||||||
|
|
||||||
from_sqla(StateProvince)
|
_PydanticStateProvince = from_sqla(StateProvince)
|
||||||
from_sqla(City)
|
_PydanticCity = from_sqla(City)
|
||||||
from_sqla(Street)
|
_PydanticStreet = from_sqla(Street)
|
||||||
_PydanticAddress = from_sqla(Address)
|
_PydanticAddress = from_sqla(Address)
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
|
Loading…
Reference in New Issue
Block a user