2222from .misc .crud_model import CRUDModel
2323from .misc .memory_sql import async_memory_db , sync_memory_db
2424from .misc .type import CrudMethods , SqlType
25- from .misc .utils import convert_table_to_model
25+ from .misc .utils import convert_table_to_model , Base
2626
2727CRUDModelType = TypeVar ("CRUDModelType" , bound = BaseModel )
2828CompulsoryQueryModelType = TypeVar ("CompulsoryQueryModelType" , bound = BaseModel )
@@ -39,34 +39,20 @@ def crud_router_builder(
3939 dependencies : Optional [List [callable ]] = None ,
4040 crud_models : Optional [CRUDModel ] = None ,
4141 async_mode : Optional [bool ] = None ,
42- foreign_include : Optional [any ] = None ,
42+ foreign_include : Optional [Base ] = None ,
4343 sql_type : Optional [SqlType ] = None ,
4444 ** router_kwargs : Any ) -> APIRouter :
4545 """
46- :param db_session: Callable function
47- db_session should be a callable function, and return a session generator.
48- Also you can handle commit by yourelf or othe business logic
49-
50- SQLAlchemy based example(SQLAlchemy was supported async since 1.4 version):
51- async:
52- async def get_transaction_session() -> AsyncSession:
53- async with async_session() as session:
54- async with session.begin():
55- yield session
56- sync:
57- def get_transaction_session():
58- try:
59- db = sync_session()
60- yield db
61- db.commit()
62- except Exception as e:
63- db.rollback()
64- raise e
65- finally:
66- db.close()
67-
68-
69- :param crud_methods: List[CrudMethods]
46+ @param db_model:
47+ The Sqlalchemy Base model/Table you want to use it to build api.
48+
49+ @param db_session:
50+ The callable variable and return a session generator that will be used to get database connection session for fastapi.
51+
52+ @param autocommit:
53+ set False if you handle commit in your db_session.
54+
55+ @param crud_methods:
7056 Fastapi Quick CRUD supports a few of crud methods, and they save into the Enum class,
7157 get it by : from fastapi_quickcrud import CrudMethods
7258 example:
@@ -76,21 +62,33 @@ def get_transaction_session():
7662 specific resource, such as GET_ONE, UPDATE_ONE, DELETE_ONE, PATCH_ONE AND POST_REDIRECT_GET
7763 this is because POST_REDIRECT_GET need to redirect to GET_ONE api
7864
79- : param exclude_columns: List[str]
65+ @ param exclude_columns:
8066 Fastapi Quick CRUD will get all the columns in you table to generate a CRUD router,
8167 it is allow you exclude some columns you dont want it expose to operated by API
8268 note:
8369 if the column in exclude list but is it not nullable or no default_value, it may throw error
8470 when you do insert
8571
86- :param crud_models:
87- :param db_model:
88- SQLAlchemy model,
89- :param dependencies:
90- :param async_mode:
91- :param autocommit:
92- :param router_kwargs: Optional arguments that ``APIRouter().include_router`` takes.
93- :return:
72+ @param dependencies:
73+ A variable that will be added to the path operation decorators.
74+
75+ @param crud_models:
76+ You can use the sqlalchemy_to_pydantic() to build your own Pydantic model CRUD set
77+
78+ @param async_mode:
79+ As your database connection
80+
81+ @param foreign_include: BaseModel
82+ Used to build foreign tree api
83+
84+ @param sql_type:
85+ You sql database type
86+
87+ @param router_kwargs:
88+ other argument for FastApi's views
89+
90+ @return:
91+ APIRouter for fastapi
9492 """
9593
9694 db_model , NO_PRIMARY_KEY = convert_table_to_model (db_model )
0 commit comments