feat(model): Proxy model support count token (#996)

This commit is contained in:
Fangyin Cheng
2023-12-29 12:01:31 +08:00
committed by GitHub
parent ba0599ebf4
commit 0cdc77abb2
16 changed files with 366 additions and 248 deletions

View File

@@ -51,7 +51,9 @@ class BaseDao(Generic[T, REQ, RES]):
Example:
.. code-block:: python
user = User(name="Edward Snowden")
session = self.get_raw_session()
session.add(user)
@@ -61,7 +63,7 @@ class BaseDao(Generic[T, REQ, RES]):
return self._db_manager._session()
@contextmanager
def session(self) -> Session:
def session(self, commit: Optional[bool] = True) -> Session:
"""Provide a transactional scope around a series of operations.
If raise an exception, the session will be roll back automatically, otherwise it will be committed.
@@ -71,13 +73,16 @@ class BaseDao(Generic[T, REQ, RES]):
with self.session() as session:
session.query(User).filter(User.name == 'Edward Snowden').first()
Args:
commit (Optional[bool], optional): Whether to commit the session. Defaults to True.
Returns:
Session: A session object.
Raises:
Exception: Any exception will be raised.
"""
with self._db_manager.session() as session:
with self._db_manager.session(commit=commit) as session:
yield session
def from_request(self, request: QUERY_SPEC) -> T: