watcher.db package

watcher.db.init_db_with_csv(data_source: str, max_workers: int = 1, schema='public', delete_existing=False)[source]

Initialize a PostgreSQL database using CSV files.

This function sets up a PostgreSQL schema and populates it with tables from the specified CSV directory. It can optionally drop all existing tables before import.

Warning

  • If delete_existing is True, all tables in the schema will be dropped. This action is irreversible.

Note

  • Prepare source clinical records as separated CSV files in accordance with Clinical Records.

Example

from watcher.db import init_db_with_csv

init_db_with_csv(
    data_source="path/to/csv_files",
    max_workers=4,
    schema="public,
    delete_existing=True,
)
Parameters:
  • data_source (str) – Absolute path to the directory containing source CSV files.

  • max_workers (int) – Number of parallel workers for uploading. Defaults to 1.

  • schema (str) – Target PostgreSQL schema. Defaults to “public”.

  • delete_existing (bool) – Whether to drop all existing tables before creation.

Returns:

None