diff --git a/README.md b/README.md index f790b98..6e21a0c 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ transactions - Not a wrapper around SQLAlchemy - Convenient for testing - Runtime host switching -- Supports multiple databases and multiple sessions per database +- Supports multiple databases and sessions per database - Provides tools for running concurrent SQL queries - Fully lazy initialization @@ -37,25 +37,25 @@ from context_async_sqlalchemy import db_session from sqlalchemy import insert from database import connection # your configured connection to the database -from models import ExampleTable # just some model for example +from models import ExampleTable # a model for example async def some_func() -> None: - # Created a session (no connection to the database yet) + # Creates a session with no connection to the database yet session = await db_session(connection) stmt = insert(ExampleTable).values(text="example_with_db_session") - # On the first request, a connection and transaction were opened + # A connection and transaction open in the first request. await session.execute(stmt) - # If you call db_session again, it will return the same session + # If you call db_session again, it returns the same session # even in child coroutines. session = await db_session(connection) - # The second request will use the same connection and the same transaction + # The second request uses the same connection and the same transaction await session.execute(stmt) - # The commit and closing of the session will occur automatically + # The commit and closing of the session occurs automatically ``` ## How it works @@ -70,5 +70,4 @@ existing ones. 3. The middleware automatically commits or rolls back open transactions. It also closes open sessions and clears the context. -The library also provides the ability to commit, roll back, and close at any -time without waiting for the end of the request. \ No newline at end of file +The library provides the ability to commit, roll back, and close at any \ No newline at end of file diff --git a/context_async_sqlalchemy/session.py b/context_async_sqlalchemy/session.py index 1603a4e..f7181ed 100644 --- a/context_async_sqlalchemy/session.py +++ b/context_async_sqlalchemy/session.py @@ -40,12 +40,12 @@ async def atomic_db_session( current_transaction: _current_transaction_choices = "commit", ) -> AsyncGenerator[AsyncSession, None]: """ - A context manager that can be used to wrap another function which - uses a context session, making that call isolated within its + A context manager that you can use to wrap another function which + uses a context session, isolating the call within its own transaction. - There are several options that define how the function will handle - an already open transaction. + There are several options that define how the function handles + an open transaction. current_transaction: "commit" - commits the open transaction and starts a new one "rollback" - rolls back the open transaction and starts a new one @@ -80,7 +80,7 @@ async def atomic_db_session( async def commit_db_session(connect: DBConnect) -> None: """ - Commits the active session, if there is one. + Commits the active session. example of use: await your_function_with_db_session() @@ -93,7 +93,7 @@ async def commit_db_session(connect: DBConnect) -> None: async def rollback_db_session(connect: DBConnect) -> None: """ - Rollbacks the active session, if there is one. + Rolls back the active session. example of use: await your_function_with_db_session() @@ -108,9 +108,7 @@ async def close_db_session(connect: DBConnect) -> None: """ Closes the active session (and connection), if there is one. - This is useful if, for example, at the beginning of the handle a - database query is needed, and then there is some other long-term work - and you don't want to keep the connection opened. + Use if you have more work you need to complete without keeping the connection open. example of use: await your_function_with_db_session() diff --git a/context_async_sqlalchemy/test_utils.py b/context_async_sqlalchemy/test_utils.py index 047c35e..0cc6a68 100644 --- a/context_async_sqlalchemy/test_utils.py +++ b/context_async_sqlalchemy/test_utils.py @@ -64,7 +64,7 @@ async def put_savepoint_session_in_ctx( a transaction. You need to pass the session you're using inside your tests to attach a new session to the same connection. - It is important to use this function inside set_test_context. + Use this function inside set_test_context. """ session_maker = await connection.session_maker() async with session_maker( diff --git a/docs/api/index.html b/docs/api/index.html index d72bcd8..f9df919 100644 --- a/docs/api/index.html +++ b/docs/api/index.html @@ -76,7 +76,7 @@
  • Middlewares