|
14 | 14 | True |
15 | 15 |
|
16 | 16 | The class breakdown in this module is intended to reflect a *repository pattern*, where |
17 | | -query/data transformation logic is defined in :py:class:`~cool_seq_tool.uta_database.UtaRepository`, |
18 | | -and connection management/state/etc is defined in :py:class:`~cool_seq_tool.uta_database.UtaDatabase`. |
| 17 | +query/data transformation logic is defined in :py:class:`~cool_seq_tool.sources.uta_database.UtaRepository`, |
| 18 | +and connection management/state/etc is constructed with :py:meth:`~cool_seq_tool.sources.uta_database.create_uta_connection_pool`. |
19 | 19 |
|
20 | 20 | The following is an example of how you might employ this in a FastAPI app: |
21 | 21 |
|
@@ -54,14 +54,30 @@ async def check_gene_exists( |
54 | 54 | ): |
55 | 55 | return await uta.gene_exists(gene) |
56 | 56 |
|
57 | | -The connection class also provides a ``repository()`` method, which returns a context |
58 | | -manager, for convenience: |
| 57 | +To reflect the old pattern of constructing/managing connection state, the :py:class:`~cool_seq_tool.sources.uta_database.UtaDatabase` |
| 58 | +class is provided. Its construction will look more like our previous UTA access patterns did, |
| 59 | +but individual queries should still be issued within a context manager. The |
| 60 | +:py:meth:`~cool_seq_tool.sources.uta_database.UtaDatabase.repository` method is provided as |
| 61 | +a convenient means of doing so. |
59 | 62 |
|
60 | 63 | .. code-block:: python |
61 | 64 |
|
62 | | - uta_db: UtaDatabase # assume this exists |
63 | | - async with uta_db.repository() as uta: |
64 | | - print(await uta.gene_exists("BRAF")) |
| 65 | + import asyncio |
| 66 | +
|
| 67 | + from cool_seq_tool.sources.uta_database import ( |
| 68 | + create_uta_connection_pool, |
| 69 | + UtaDatabase, |
| 70 | + ) |
| 71 | +
|
| 72 | +
|
| 73 | + async def example(gene: str): |
| 74 | + uta_db = UtaDatabase(connection) |
| 75 | + async with uta_db.repository() as uta: |
| 76 | + print(await uta.gene_exists("BRAF")) |
| 77 | + await uta_db.close() |
| 78 | +
|
| 79 | +
|
| 80 | + asyncio.run(example("BRAF")) |
65 | 81 |
|
66 | 82 | """ |
67 | 83 |
|
|
0 commit comments