Metadata-Version: 2.4
Name: ticrobe.pgsql
Version: 26.4.2
Summary: tX.tDataStore PostgreSQL helper package for common database operations.
Author: techist
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Database
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: psycopg[binary]<4.0,>=3.1
Requires-Dist: typing-extensions>=4.0; python_version < "3.11"

# ticrobe.pgsql

Python package for PostgreSQL database operations.

Published package name: `ticrobe.pgsql`

Version: `26.4.2`

## Install

```bash
pip install ticrobe.pgsql
```

For local development from this workspace:

```bash
pip install -e .
```

## Build and upload to PyPI

Build from inside `src/tX.tPgSql`:

```bash
python -m pip install --upgrade pip build twine
python -m build
python -m twine check dist/*
```

Upload using a PyPI API token:

```bash
python -m twine upload -u __token__ -p pypi-YOUR_API_TOKEN dist/*
```

Important:

- In `twine`, the "password" is your PyPI API token
- The username should be exactly `__token__`
- The package files are generated in `src/tX.tPgSql/dist/`

## Quick start

```python
import asyncio

from ticrobe.pgsql import DatabaseConfig, PostgresDB

async def main() -> None:
    config = DatabaseConfig(
        host="localhost",
        port=5432,
        database="mydb",
        schema="public",
        user="postgres",
        password="secret",
    )

    db = PostgresDB()
    await db.connect(config)
    await db.create_table(
        {
            "table_name": "users",
            "columns": {
            "id": "SERIAL PRIMARY KEY",
            "name": "VARCHAR(100) NOT NULL",
            "email": "VARCHAR(255) UNIQUE NOT NULL",
            "created_at": "TIMESTAMP DEFAULT CURRENT_TIMESTAMP",
        },
        },
    )

    user = await db.insert(
        {
            "name": "Asha",
            "email": "asha@example.com",
        },
        returning=("id", "name", "email"),
    )
    if user is None:
        raise RuntimeError("Insert failed")

    await db.update(
        user["id"],
        {"name": "Asha R"},
        returning=("id", "name", "email"),
    )
    rows = await db.fetch_all("SELECT * FROM users ORDER BY id")
    await db.delete(user["id"])
    await db.disconnect(config)


asyncio.run(main())
```

You can also load connection settings from PostgreSQL environment variables:

```python
config = DatabaseConfig.from_env()
```

Supported environment variables include `PGHOST`, `PGPORT`, `PGDATABASE`, `PGSCHEMA`,
`PGUSER`, `PGPASSWORD`, and `PGCONNECT_TIMEOUT`.
