https://github.com/thejacksonlaboratory/geneweaver-db
The GeneWeaver database interaction code.
https://github.com/thejacksonlaboratory/geneweaver-db
functional-genomics geneweaver genomic-data-science genomics sql
Last synced: 8 months ago
JSON representation
The GeneWeaver database interaction code.
- Host: GitHub
- URL: https://github.com/thejacksonlaboratory/geneweaver-db
- Owner: TheJacksonLaboratory
- License: apache-2.0
- Created: 2023-11-13T14:15:57.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-28T16:26:28.000Z (almost 2 years ago)
- Last Synced: 2024-05-29T07:36:00.678Z (almost 2 years ago)
- Topics: functional-genomics, geneweaver, genomic-data-science, genomics, sql
- Language: Python
- Homepage: https://geneweaver.org
- Size: 413 KB
- Stars: 2
- Watchers: 5
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Geneweaver DB
[](https://github.com/TheJacksonLaboratory/geneweaver-db/actions/workflows/tests.yml)
[](https://github.com/TheJacksonLaboratory/geneweaver-db/actions/workflows/style.yml)
[](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
```