Skip to content

Commit 07c3e20

Browse files
committed
update docs:
- fix typos - sync changes to md
1 parent 2d795c9 commit 07c3e20

19 files changed

Lines changed: 268 additions & 242 deletions

File tree

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ build:
2222

2323
publish:
2424
uv publish
25+
26+
build_docs:
27+
mkdocs build -f docs_sources/mkdocs.yml -d ../docs

docs/404.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
</li>
4646
</ul>
4747
<ul>
48-
<li class="toctree-l1"><a class="reference internal" href="/examples">Usage Examples</a>
48+
<li class="toctree-l1"><a class="reference internal" href="/examples/">Usage Examples</a>
4949
</li>
5050
</ul>
5151
<ul>

docs/api/index.html

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</script>
1919

2020
<!--[if lt IE 9]>
21-
<script src="../js/html5shiv.min.js"></script>
21+
<script src="../js/html5shiv.min.js"></script>
2222
<![endif]-->
2323
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
2424
<script>hljs.highlightAll();</script>
@@ -44,15 +44,15 @@
4444
</li>
4545
</ul>
4646
<ul>
47-
<li class="toctree-l1"><a class="reference internal" href="../problem">The Problem It Solves</a>
47+
<li class="toctree-l1"><a class="reference internal" href="../problem/">The Problem It Solves</a>
4848
</li>
4949
</ul>
5050
<ul>
51-
<li class="toctree-l1"><a class="reference internal" href="../getting_started">Getting Started</a>
51+
<li class="toctree-l1"><a class="reference internal" href="../getting_started/">Getting Started</a>
5252
</li>
5353
</ul>
5454
<ul>
55-
<li class="toctree-l1"><a class="reference internal" href="../examples">Usage Examples</a>
55+
<li class="toctree-l1"><a class="reference internal" href="../examples/">Usage Examples</a>
5656
</li>
5757
</ul>
5858
<ul class="current">
@@ -122,19 +122,19 @@
122122
</li>
123123
</ul>
124124
<ul>
125-
<li class="toctree-l1"><a class="reference internal" href="../concurrent_queries">Concurrent SQL Queries</a>
125+
<li class="toctree-l1"><a class="reference internal" href="../concurrent_queries/">Concurrent SQL Queries</a>
126126
</li>
127127
</ul>
128128
<ul>
129-
<li class="toctree-l1"><a class="reference internal" href="../master_replica">Master/Replica or several databases at the same time</a>
129+
<li class="toctree-l1"><a class="reference internal" href="../master_replica/">Master/Replica or several databases at the same time</a>
130130
</li>
131131
</ul>
132132
<ul>
133-
<li class="toctree-l1"><a class="reference internal" href="../testing">Testing</a>
133+
<li class="toctree-l1"><a class="reference internal" href="../testing/">Testing</a>
134134
</li>
135135
</ul>
136136
<ul>
137-
<li class="toctree-l1"><a class="reference internal" href="../how_middleware_works">How middleware works</a>
137+
<li class="toctree-l1"><a class="reference internal" href="../how_middleware_works/">How middleware works</a>
138138
</li>
139139
</ul>
140140
</div>
@@ -152,6 +152,9 @@
152152
<ul class="wy-breadcrumbs">
153153
<li><a href=".." class="icon icon-home" aria-label="Docs"></a></li>
154154
<li class="breadcrumb-item active">API Reference</li>
155+
<li class="wy-breadcrumbs-aside">
156+
<a href="https://github.com/krylosov-aa/context-async-sqlalchemy/edit/master/docs/api.md" class="icon icon-github"> Edit on GitHub</a>
157+
</li>
155158
</ul>
156159
<hr/>
157160
</div>
@@ -160,14 +163,13 @@
160163

161164
<h1 id="api-reference">API Reference</h1>
162165
<h2 id="dbconnect">DBConnect</h2>
163-
<p>DBConnect is responsible for managing the engine and <code>session_maker</code>.
164-
You need to define two factories:
165-
<ul>
166-
<li>Specify host to which you want to connect (optional).</li>
167-
<li>Specify a handler that runs before a session is created. It be used to connect to the host for the first time or
168-
to reconnect to a new one.</li>
169-
</ul>
170-
</p>
166+
<p>DBConnect is responsible for managing the engine and <code>session_maker</code>
167+
You need to define two factories:</p>
168+
<ul>
169+
<li>Specify host to which you want to connect (optional).</li>
170+
<li>Specify a handler that runs before a session is created.
171+
It will be used to connect to the host for the first time or to reconnect to a new one (optional).</li>
172+
</ul>
171173
<h3 id="init">init</h3>
172174
<pre><code class="language-python">def __init__(
173175
self: DBConnect,
@@ -211,20 +213,20 @@ <h3 id="connect">connect</h3>
211213
</code></pre>
212214
<p>Establishes a connection to the specified host.
213215
It doesn’t need to be called explicitly.
214-
The first session request automatically
216+
If you don't use the call, the first session request will automatically
215217
establishes the connection.</p>
216218
<hr />
217219
<h3 id="change_host">change_host</h3>
218220
<pre><code class="language-python">async def change_host(self: DBConnect, host: str) -&gt; None:
219221
</code></pre>
220-
Establishes a connection to the specified host. It validates that the currently connected host is different
222+
<p>Establishes a connection to the specified host. It then validates that the currently connected host is different
221223
from the target host.</p>
222224
<hr />
223225
<h3 id="create_session">create_session</h3>
224226
<pre><code class="language-python">async def create_session(self: DBConnect) -&gt; AsyncSession:
225227
</code></pre>
226228
<p>Creates a new session the library uses internally.
227-
You never need to call it directly.</p>
229+
You never need to call it directly. (Only maybe in some special cases.)</p>
228230
<hr />
229231
<h3 id="session_maker">session_maker</h3>
230232
<pre><code class="language-python">async def session_maker(self: DBConnect) -&gt; async_sessionmaker[AsyncSession]:
@@ -237,8 +239,8 @@ <h3 id="close">close</h3>
237239
<p>Closes and cleans up all resources, freeing the connection pool.
238240
Use this call at the end of your application’s life cycle.</p>
239241
<h2 id="middlewares">Middlewares</h2>
240-
<p>Most of the work the “magic” happens inside the middleware. Check out <a href="../how_middleware_works">how it works</a> and implement your
241-
own.</p>
242+
<p>Most of the work the “magic” happens inside the middleware. Check out
243+
<a href="../how_middleware_works/">how it works</a> and implement your own if the ready-made ones don't fit.</p>
242244
<h3 id="fastapi">FastAPI</h3>
243245
<pre><code class="language-python">from context_async_sqlalchemy.fastapi_utils import (
244246
fastapi_http_db_session_middleware,
@@ -290,7 +292,7 @@ <h3 id="db_session">db_session</h3>
290292
<pre><code class="language-python">async def db_session(connect: DBConnect) -&gt; AsyncSession:
291293
</code></pre>
292294
<p>The most important function for obtaining a session in your code.
293-
When called for the first time, it returns a new session; subsequent
295+
Returns a new session when you call it for the first time; subsequent
294296
calls return the same session.</p>
295297
<hr />
296298
<h3 id="atomic_db_session">atomic_db_session</h3>
@@ -300,7 +302,7 @@ <h3 id="atomic_db_session">atomic_db_session</h3>
300302
current_transaction: Literal[&quot;commit&quot;, &quot;rollback&quot;, &quot;append&quot;, &quot;raise&quot;] = &quot;commit&quot;,
301303
) -&gt; AsyncGenerator[AsyncSession, None]:
302304
</code></pre>
303-
<p>A context manager that can be used to wrap another function which
305+
<p>A context manager you can use to wrap another function which
304306
uses a context session, making that call isolated within its own transaction.</p>
305307
<p>Several options define how a function handles an open transaction.</p>
306308
<p>current_transaction:</p>
@@ -325,27 +327,29 @@ <h3 id="close_db_session">close_db_session</h3>
325327
<pre><code class="language-python">async def close_db_session(connect: DBConnect) -&gt; None:
326328
</code></pre>
327329
<p>Closes the current context session and returns the connection to the pool.
328-
If you close an uncommitted transaction, the connection rolls back.</p>
329-
<p>This is useful if a database querly is needed at the beginning of the handle.</p>
330-
<p>You have have more work you need to complete over time without being able to keep the connection open.</p>
330+
If you close an uncommitted transaction, the connection rolls back</p>
331+
<p>This is useful when you need to run a database query at the start of the
332+
handler, then continue working over time without keeping the connection open.</p>
331333
<hr />
332334
<h3 id="new_non_ctx_session">new_non_ctx_session</h3>
333335
<pre><code class="language-python">@asynccontextmanager
334336
async def new_non_ctx_session(
335337
connect: DBConnect,
336338
) -&gt; AsyncGenerator[AsyncSession, None]:
337339
</code></pre>
338-
<p>A context manager that allows you to create a new session without placing it in a context.</p>
340+
<p>A context manager that allows you to create a new session without
341+
placing it in a context.</p>
339342
<hr />
340343
<h3 id="new_non_ctx_atomic_session">new_non_ctx_atomic_session</h3>
341344
<pre><code class="language-python">@asynccontextmanager
342345
async def new_non_ctx_atomic_session(
343346
connect: DBConnect,
344347
) -&gt; AsyncGenerator[AsyncSession, None]:
345348
</code></pre>
346-
<p>A context manager that allows you to create a new session with
347-
a new transaction that isn't placed in a context. It's used for manual
348-
session management when you don't want to use a context.</p>
349+
<p>Runs a function in a new context with new session(s) that have a separate connection.</p>
350+
<p>It commits the transaction automatically if <code>callable_func</code> does not
351+
raise exceptions. Otherwise, the transaction rolls back.</p>
352+
<p>It is intended to allow you to run multiple database queries concurrently.</p>
349353
<h2 id="context">Context</h2>
350354
<h3 id="run_in_new_ctx">run_in_new_ctx</h3>
351355
<pre><code class="language-python">async def run_in_new_ctx(
@@ -355,9 +359,9 @@ <h3 id="run_in_new_ctx">run_in_new_ctx</h3>
355359
) -&gt; AsyncCallableResult:
356360
</code></pre>
357361
<p>Runs a function in a new context with new session(s) that have a
358-
separate connection.</p>
362+
separate connection.</p>
359363
<p>It commits the transaction automatically if <code>callable_func</code> does not
360-
raise exceptions. Otherwise, the transaction rolls back.</p>
364+
raise exceptions. Otherwise, the transaction rolls back.</p>
361365
<p>It is intended to allow you to run multiple database queries concurrently.</p>
362366
<p>example of use:</p>
363367
<pre><code class="language-python">await asyncio.gather(
@@ -369,7 +373,6 @@ <h3 id="run_in_new_ctx">run_in_new_ctx</h3>
369373
)
370374
</code></pre>
371375
<h2 id="testing">Testing</h2>
372-
373376
<h3 id="rollback_session">rollback_session</h3>
374377
<pre><code class="language-python">@asynccontextmanager
375378
async def rollback_session(
@@ -388,7 +391,7 @@ <h3 id="set_test_context">set_test_context</h3>
388391
It is intended to test the application when it shares a single transaction.</p>
389392
<p>Use <code>auto_close=False</code> if you’re using a test session and transaction
390393
that you close elsewhere in your code.</p>
391-
<p>Use <code>auto_close=True</code> to call a function
394+
<p>Use <code>auto_close=True</code> if you want to call a function
392395
in a test that uses a context while the middleware is not
393396
active. All sessions close automatically.</p>
394397
<hr />
@@ -401,17 +404,15 @@ <h3 id="put_savepoint_session_in_ctx">put_savepoint_session_in_ctx</h3>
401404
<p>Sets the context to a session that uses a save point instead of creating
402405
a transaction. You need to pass the session you're using inside
403406
your tests to attach a new session to the same connection.</p>
404-
405407
<pre><code>It is important to use this function inside set_test_context.
406408
</code></pre>
407-
408-
<p>Learn more about <a href="../testing">testing</a>.</p>
409+
<p>Learn more about <a href="../testing/">testing</a></p>
409410

410411
</div>
411412
</div><footer>
412413
<div class="rst-footer-buttons" role="navigation" aria-label="Footer Navigation">
413-
<a href="../examples" class="btn btn-neutral float-left" title="Usage Examples"><span class="icon icon-circle-arrow-left"></span> Previous</a>
414-
<a href="../concurrent_queries" class="btn btn-neutral float-right" title="Concurrent SQL Queries">Next <span class="icon icon-circle-arrow-right"></span></a>
414+
<a href="../examples/" class="btn btn-neutral float-left" title="Usage Examples"><span class="icon icon-circle-arrow-left"></span> Previous</a>
415+
<a href="../concurrent_queries/" class="btn btn-neutral float-right" title="Concurrent SQL Queries">Next <span class="icon icon-circle-arrow-right"></span></a>
415416
</div>
416417

417418
<hr/>
@@ -438,10 +439,10 @@ <h3 id="put_savepoint_session_in_ctx">put_savepoint_session_in_ctx</h3>
438439
</span>
439440

440441

441-
<span><a href="../examples" style="color: #fcfcfc">&laquo; Previous</a></span>
442+
<span><a href="../examples/" style="color: #fcfcfc">&laquo; Previous</a></span>
442443

443444

444-
<span><a href="../concurrent_queries" style="color: #fcfcfc">Next &raquo;</a></span>
445+
<span><a href="../concurrent_queries/" style="color: #fcfcfc">Next &raquo;</a></span>
445446

446447
</span>
447448
</div>

docs/concurrent_queries/index.html

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</script>
1919

2020
<!--[if lt IE 9]>
21-
<script src="../js/html5shiv.min.js"></script>
21+
<script src="../js/html5shiv.min.js"></script>
2222
<![endif]-->
2323
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
2424
<script>hljs.highlightAll();</script>
@@ -44,19 +44,19 @@
4444
</li>
4545
</ul>
4646
<ul>
47-
<li class="toctree-l1"><a class="reference internal" href="../problem">The Problem It Solves</a>
47+
<li class="toctree-l1"><a class="reference internal" href="../problem/">The Problem It Solves</a>
4848
</li>
4949
</ul>
5050
<ul>
51-
<li class="toctree-l1"><a class="reference internal" href="../getting_started">Getting Started</a>
51+
<li class="toctree-l1"><a class="reference internal" href="../getting_started/">Getting Started</a>
5252
</li>
5353
</ul>
5454
<ul>
55-
<li class="toctree-l1"><a class="reference internal" href="../examples">Usage Examples</a>
55+
<li class="toctree-l1"><a class="reference internal" href="../examples/">Usage Examples</a>
5656
</li>
5757
</ul>
5858
<ul>
59-
<li class="toctree-l1"><a class="reference internal" href="../api">API Reference</a>
59+
<li class="toctree-l1"><a class="reference internal" href="../api/">API Reference</a>
6060
</li>
6161
</ul>
6262
<ul class="current">
@@ -66,15 +66,15 @@
6666
</li>
6767
</ul>
6868
<ul>
69-
<li class="toctree-l1"><a class="reference internal" href="../master_replica">Master/Replica or several databases at the same time</a>
69+
<li class="toctree-l1"><a class="reference internal" href="../master_replica/">Master/Replica or several databases at the same time</a>
7070
</li>
7171
</ul>
7272
<ul>
73-
<li class="toctree-l1"><a class="reference internal" href="../testing">Testing</a>
73+
<li class="toctree-l1"><a class="reference internal" href="../testing/">Testing</a>
7474
</li>
7575
</ul>
7676
<ul>
77-
<li class="toctree-l1"><a class="reference internal" href="../how_middleware_works">How middleware works</a>
77+
<li class="toctree-l1"><a class="reference internal" href="../how_middleware_works/">How middleware works</a>
7878
</li>
7979
</ul>
8080
</div>
@@ -92,6 +92,9 @@
9292
<ul class="wy-breadcrumbs">
9393
<li><a href=".." class="icon icon-home" aria-label="Docs"></a></li>
9494
<li class="breadcrumb-item active">Concurrent SQL Queries</li>
95+
<li class="wy-breadcrumbs-aside">
96+
<a href="https://github.com/krylosov-aa/context-async-sqlalchemy/edit/master/docs/concurrent_queries.md" class="icon icon-github"> Edit on GitHub</a>
97+
</li>
9598
</ul>
9699
<hr/>
97100
</div>
@@ -126,10 +129,10 @@ <h1 id="concurrent-sql-queries">Concurrent sql queries</h1>
126129

127130
async def handler_multiple_sessions() -&gt; None:
128131
&quot;&quot;&quot;
129-
You may need to to run multiple sessions. For example, to run several queries concurrently.
132+
You may need to run multiple sessions. For example, to run several queries concurrently.
130133

131134
You can also use the same techniques to create new sessions whenever you
132-
need them, ot necessarily because of the concurrent processing.
135+
need them, not necessarily because of the concurrent processing.
133136
&quot;&quot;&quot;
134137
await asyncio.gather(
135138
_insert(), # context session
@@ -182,8 +185,8 @@ <h1 id="concurrent-sql-queries">Concurrent sql queries</h1>
182185
</div>
183186
</div><footer>
184187
<div class="rst-footer-buttons" role="navigation" aria-label="Footer Navigation">
185-
<a href="../api" class="btn btn-neutral float-left" title="API Reference"><span class="icon icon-circle-arrow-left"></span> Previous</a>
186-
<a href="../master_replica" class="btn btn-neutral float-right" title="Master/Replica or several databases at the same time">Next <span class="icon icon-circle-arrow-right"></span></a>
188+
<a href="../api/" class="btn btn-neutral float-left" title="API Reference"><span class="icon icon-circle-arrow-left"></span> Previous</a>
189+
<a href="../master_replica/" class="btn btn-neutral float-right" title="Master/Replica or several databases at the same time">Next <span class="icon icon-circle-arrow-right"></span></a>
187190
</div>
188191

189192
<hr/>
@@ -210,10 +213,10 @@ <h1 id="concurrent-sql-queries">Concurrent sql queries</h1>
210213
</span>
211214

212215

213-
<span><a href="../api" style="color: #fcfcfc">&laquo; Previous</a></span>
216+
<span><a href="../api/" style="color: #fcfcfc">&laquo; Previous</a></span>
214217

215218

216-
<span><a href="../master_replica" style="color: #fcfcfc">Next &raquo;</a></span>
219+
<span><a href="../master_replica/" style="color: #fcfcfc">Next &raquo;</a></span>
217220

218221
</span>
219222
</div>

0 commit comments

Comments
 (0)