Metadata-Version: 2.5
Name: pmdb_utils
Version: 0.5.61
Summary: A utilities package for poorman-dataplatform
Author-email: saebod <saebod@hotmail.com>
Requires-Python: >=3.9
Requires-Dist: azure-identity>=1.25.0
Requires-Dist: azure-keyvault>=4.2.0
Requires-Dist: bump-my-version>=1.2.5
Requires-Dist: minio>=7.2.16
Requires-Dist: polars[rtcompat]>=1.36.1
Requires-Dist: psycopg2-binary>=2.9.12
Requires-Dist: python-dotenv>=1.1.1
Description-Content-Type: text/markdown

# pmdb_utils

Shared utilities for the Poorman Data Platform.

## PostgreSQL writes

`PostgresDB` reads the application connection from `DATABASE_URL` by default.
Select `DATABASE_URL_LOG` explicitly when writing to the separate log database.

```python
from pmdb_utils.dataacceslayer import PostgresDB

with PostgresDB.from_env("DATABASE_URL_LOG") as db:
    db.create_table(
        "public.worker_log",
        {
            "id": "BIGSERIAL PRIMARY KEY",
            "job_id": "TEXT NOT NULL",
            "status": "TEXT NOT NULL",
            "details": "JSONB",
        },
    )

    db.insert(
        "public.worker_log",
        {"job_id": "job-123", "status": "started", "details": {}},
    )
    changed = db.update(
        "public.worker_log",
        values={"status": "complete"},
        where={"job_id": "job-123"},
    )
    deleted = db.delete(
        "public.worker_log",
        where={"job_id": "job-123"},
    )
```

The `update` and `delete` methods require at least one equality condition and
return the affected row count. Values are parameterized, table and column names
are quoted, and dictionaries/lists are adapted for PostgreSQL JSON columns.
Use `bulk_insert` for multiple rows and `execute` or `transaction` for complex
SQL.
