agent0.chainsync.db.hyperdrive.import_export_data

Helper functions to export data to csv from the db and to load csv to dataframes.

Functions

export_db_to_file(→ None)

Export all tables from the database and write as parquet files, one per table.

import_to_pandas(→ dict[str, pandas.DataFrame])

Helper function to load data from parquet

import_to_db(→ None)

Helper function to load data from parquet into the db

Module Contents

agent0.chainsync.db.hyperdrive.import_export_data.export_db_to_file(out_dir: pathlib.Path, db_session: sqlalchemy.orm.Session | None = None) None

Export all tables from the database and write as parquet files, one per table. We use parquet since it’s type aware, so all original types (including Decimals) are preserved when read

Parameters:
  • out_dir (Path) – The directory to write the parquet files to. It’s assumed this directory already exists.

  • db_session (Session | None, optional) – The initialized session object. If none, will read credentials from .env

agent0.chainsync.db.hyperdrive.import_export_data.import_to_pandas(in_dir: pathlib.Path) dict[str, pandas.DataFrame]

Helper function to load data from parquet

Parameters:

in_dir (Path) – The directory to read the parquet files from that matches the out_dir passed into export_db_to_file

Returns:

A dictionary of pandas dataframes keyed by the original table name in the db

Return type:

dict[str, pd.DataFrame]

agent0.chainsync.db.hyperdrive.import_export_data.import_to_db(db_session: sqlalchemy.orm.Session, in_dir: pathlib.Path, drop=True) None

Helper function to load data from parquet into the db

Parameters:
  • db_session (Session) – The sqlalchemy session object

  • in_dir (Path) – The directory to read the parquet files from that matches the out_dir passed into export_db_to_file

  • drop (bool, optional) – Whether to drop the existing data in the db before importing