Skip to content

Commit

Permalink
inputs.ramp: iterate one table from sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
deeenes committed Oct 24, 2024
1 parent cd1b838 commit 7937d56
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pypath/inputs/ramp/_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from __future__ import annotations

from collections.abc import Generator, Any
import os
import sqlite3

Expand All @@ -33,6 +34,7 @@


__all__ = [
'ramp_iter',
'ramp_sqlite',
'ramp_show_tables',
'ramp_list_tables',
Expand Down Expand Up @@ -180,3 +182,35 @@ def ramp_raw(

return result


def ramp_iter(table: str) -> Generator[tuple[Any]]:
"""
Retrieve RaMP database contents from its SQLite build.
Args:
tables:
One or more tables to retrieve. If None, all tables are retrieved.
sqlite:
Return an SQLite database instead of a pandas DataFrame.
return_df:
Return a pandas data frame.
kwargs:
Options for the SQLite database: this way you can point to a new
or existing database, while by default, an in-memory, temporary
database is used.
Returns:
Either a dictionary with the table names as keys and pandas dataframes
as values, or an SQLite database connection.
"""

con = ramp_sqlite()
cur = con.cursor()

cur.execute(f'SELECT * FROM {table}')

for row in cur:

yield row

con.close()

0 comments on commit 7937d56

Please sign in to comment.