Rename main function

This commit is contained in:
Daniil Fajnberg 2022-08-06 11:01:12 +02:00
parent ee9a0de334
commit ed519fd9f0
3 changed files with 10 additions and 10 deletions

View File

@ -1 +1 @@
from .sqla import from_sqla
from .sqla import sqla2pydantic

View File

@ -34,7 +34,7 @@ from .utils import resolve_dotted_path
__all__ = [
'field_from_column',
'field_from_relationship',
'from_sqla'
'sqla2pydantic'
]
@ -104,7 +104,7 @@ 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] = (),
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):
"""

View File

@ -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")