generated from daniil-berg/boilerplate-py
Rename main function
This commit is contained in:
parent
ee9a0de334
commit
ed519fd9f0
@ -1 +1 @@
|
||||
from .sqla import from_sqla
|
||||
from .sqla import sqla2pydantic
|
||||
|
@ -34,7 +34,7 @@ from .utils import resolve_dotted_path
|
||||
__all__ = [
|
||||
'field_from_column',
|
||||
'field_from_relationship',
|
||||
'from_sqla'
|
||||
'sqla2pydantic'
|
||||
]
|
||||
|
||||
|
||||
@ -104,9 +104,9 @@ def field_from_relationship(rel_prop: RelationshipProperty) -> FieldDef:
|
||||
return list[rel_prop.mapper.class_.__name__], Field(default=None)
|
||||
|
||||
|
||||
def from_sqla(db_model: Type[DeclarativeMeta], config: Type[BaseConfig] = OrmConfig, exclude: Container[str] = (),
|
||||
incl_relationships: bool = True, add_fields: dict[str, FieldDef] = None,
|
||||
add_local_ns: dict[str, BaseModel] = None):
|
||||
def sqla2pydantic(db_model: Type[DeclarativeMeta], config: Type[BaseConfig] = OrmConfig, exclude: Container[str] = (),
|
||||
incl_relationships: bool = True, add_fields: dict[str, FieldDef] = None,
|
||||
add_local_ns: dict[str, BaseModel] = None):
|
||||
"""
|
||||
Takes an SQLAlchemy ORM model class and returns a matching Pydantic model class.
|
||||
|
||||
|
@ -5,7 +5,7 @@ from sqlalchemy.sql.functions import now as db_now
|
||||
from sqlalchemy.sql.schema import Column, ForeignKey as FKey
|
||||
from sqlalchemy.sql.sqltypes import Integer, String, TIMESTAMP, Unicode
|
||||
|
||||
from orm2pydantic.sqla import from_sqla
|
||||
from orm2pydantic.sqla import sqla2pydantic
|
||||
|
||||
|
||||
ORMBase = declarative_base()
|
||||
@ -65,10 +65,10 @@ def main_test() -> None:
|
||||
engine = create_engine("sqlite://")
|
||||
AbstractBase.metadata.create_all(engine)
|
||||
|
||||
_PydanticStateProvince = from_sqla(StateProvince, exclude=['cities'])
|
||||
_PydanticCity = from_sqla(City, exclude=['streets'])
|
||||
_PydanticStreet = from_sqla(Street, exclude=['addresses'])
|
||||
_PydanticAddress = from_sqla(Address)
|
||||
_PydanticStateProvince = sqla2pydantic(StateProvince, exclude=['cities'])
|
||||
_PydanticCity = sqla2pydantic(City, exclude=['streets'])
|
||||
_PydanticStreet = sqla2pydantic(Street, exclude=['addresses'])
|
||||
_PydanticAddress = sqla2pydantic(Address)
|
||||
|
||||
with Session(engine) as session:
|
||||
bavaria = StateProvince(country="de", name="Bavaria")
|
||||
|
Loading…
Reference in New Issue
Block a user