Skip to content

Commit

Permalink
updated comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rvosa committed Sep 8, 2024
1 parent 365ba3e commit 78cfb9e
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions bactria/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,21 @@ class Database:
schema provided by BOLD's BCDM packages, creation of database tables based on these ORM classes, and the
ingestion of data. Usage:
# First time use:
db = Database('db.sqlite', '/path/to/BOLD_Public.18-Dec-2023')
db.make_schema() # instantiates the database tables
db.load_bcdm() # loads TSV data into the database
# To merge the megatree:
db = Database('db.sqlite', '/path/to/BOLD_Public.18-Dec-2023')
db.merge_megatree('node.sqlite')
# All subsequent times:
db = Database('db.sqlite', '/path/to/BOLD_Public.18-Dec-2023')
node = db.get_node({'id':'ott34728'})
barcode = db.get_barcode(...)
taxon = db.get_taxon(...)
Examples:
>>> # First time use:
>>> db = Database(Path('db.sqlite'), Path('/path/to/BOLD_Public.18-Dec-2023'))
>>> db.make_schema() # instantiates the database tables
>>> db.load_bcdm() # loads TSV data into the database
>>> # To merge the megatree:
>>> db = Database(Path('db.sqlite'), Path('/path/to/BOLD_Public.18-Dec-2023'))
>>> db.merge_megatree(Path('node.sqlite'))
>>> # All subsequent times:
>>> db = Database(Path('db.sqlite'), Path('/path/to/BOLD_Public.18-Dec-2023'))
>>> node = db.get_node({'id':'ott34728'})
>>> barcode = db.get_barcode(...)
>>> taxon = db.get_taxon(...)
"""

def __init__(self, db_file: Path, data_package: Path):
Expand All @@ -81,14 +82,20 @@ def __init__(self, db_file: Path, data_package: Path):
self.make_orm()

def start_session(self):
"""Start a new session."""
"""
Start a new session.
:return: A new session object
"""
if self.current_session is not None:
raise RuntimeError("A session is already in progress")
self.current_session = self.Session()
return self.current_session

def end_session(self):
"""End the current session."""
def end_session(self) -> None:
"""
End the current session.
:return: None
"""
if self.current_session is None:
raise RuntimeError("No session is currently in progress")
self.current_session.close()
Expand Down

0 comments on commit 78cfb9e

Please sign in to comment.