Metadata-Version: 2.3
Name: geneweaver-db
Version: 0.6.0a4
Summary: Database Interaction Services for GeneWeaver
License: Apache-2.0
Author: Jax Computational Sciences
Author-email: cssc@jax.org
Requires-Python: >=3.9,<4.0
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: geneweaver-core (>=0.10.0a3,<1.0.0)
Requires-Dist: psycopg[binary] (==3.1.18)
Project-URL: Homepage, https://thejacksonlaboratory.github.io/geneweaver-docs/
Project-URL: Repository, https://github.com/TheJacksonLaboratory/geneweaver-db
Description-Content-Type: text/markdown

# Geneweaver DB

[![Tests](https://github.com/TheJacksonLaboratory/geneweaver-db/actions/workflows/tests.yml/badge.svg?event=push)](https://github.com/TheJacksonLaboratory/geneweaver-db/actions/workflows/tests.yml)
[![Style](https://github.com/TheJacksonLaboratory/geneweaver-db/actions/workflows/style.yml/badge.svg?event=push)](https://github.com/TheJacksonLaboratory/geneweaver-db/actions/workflows/style.yml)
[![Coverage](https://github.com/TheJacksonLaboratory/geneweaver-db/actions/workflows/coverage.yml/badge.svg?event=push)](https://github.com/TheJacksonLaboratory/geneweaver-db/actions/workflows/coverage.yml)

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.


## Installation

To install the Geneweaver DB library, run one of the following commands:

#### Using Pip
```
pip install geneweaver-db
```

#### Using Poetry
```
poetry add geneweaver-db
```

## Usage
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.

### Non-Async Functions
```python
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
```

### Async Functions
```python
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
```
