The Geneweaver DB library provides database access functionality for the Geneweaver project. The library contains SQL queries wrapped in standard python functions, as well as a database connection manager.
To install the Geneweaver DB library, run one of the following commands:
pip install geneweaver-db
poetry add geneweaver-db
The Geneweaver DB library is intended to be used as a dependency for other Geneweaver packages, but can also be used as a stand-alone pacakge.
The package has three main sections:
geneweaver.db
- contains non-async database functions.geneweaver.db.aio
- contains async database functions.geneweaver.db.query
- contains SQL queries and SQL generation functions.
Database functions usually take a Cursor
or AsyncCursor
object as their first
argument.
import psycopg
import geneweaver
from geneweaver.db.core.settings import settings
def get_my_gene():
with psycopg.connect(settings.URI) as conn:
with conn.cursor() as cur:
result = geneweaver.db.gene.get(cur, 'my_gene')
return result
import psycopg
import geneweaver
from geneweaver.db.core.settings import settings
async def get_my_gene():
async with psycopg.AsyncConnection.connect(settings.URI) as conn:
async with conn.cursor() as cur:
result = await geneweaver.db.aio.gene.get(cur, 'my_gene')
return result