Metadata-Version: 2.4
Name: dbops-manager
Version: 0.1.8
Summary: A lightweight PostgreSQL operations manager for AWS Lambda
Author-email: Your Name <your.email@example.com>
License: MIT License
        
        Copyright (c) 2024 Ahmad Mujtaba (amz)
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE. 
Project-URL: Homepage, https://github.com/yourusername/dbops-manager
Project-URL: Repository, https://github.com/yourusername/dbops-manager.git
Project-URL: Issues, https://github.com/yourusername/dbops-manager/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: psycopg2-binary>=2.9.9
Requires-Dist: python-dotenv>=1.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: black>=22.0.0; extra == "dev"
Requires-Dist: isort>=5.0.0; extra == "dev"
Requires-Dist: flake8>=4.0.0; extra == "dev"
Dynamic: license-file

# dbops-manager

A lightweight PostgreSQL operations manager for AWS Lambda.

## Features

- **CRUD Operations**: Execute, fetch, and manage PostgreSQL queries with ease.
- **Batch Operations**: Execute multiple queries in a single batch.
- **Transaction Support**: Use context managers for transaction handling with automatic rollback on errors.
- **Bulk Insert**: Efficiently insert multiple records using `execute_values`.
- **Logging**: Automatically log database operations to a dedicated table.
- **Error Handling**: Comprehensive exception handling for database operations.

## Installation

```bash
pip install dbops-manager
```

## Usage

### Basic Usage

```python
from dbops_manager import PostgresOps

# Initialize with configuration
config = {
    "dbname": "example",
    "user": "postgres",
    "password": "postgres",
    "host": "localhost",
    "port": "5432"
}
db = PostgresOps.from_config(config)

# Execute a query
db.execute("INSERT INTO users (name) VALUES (%s)", ("John",))

# Fetch results
results = db.fetch("SELECT * FROM users")
print(results)

# Close the connection
db.close()
```

### Using Environment Variables

```python
from dbops_manager import PostgresOps

# Initialize using environment variables
db = PostgresOps.from_env()

# Execute a query
db.execute("INSERT INTO users (name) VALUES (%s)", ("Jane",))

# Fetch results
results = db.fetch("SELECT * FROM users")
print(results)

# Close the connection
db.close()
```

### Batch Operations

```python
from dbops_manager import PostgresOps

db = PostgresOps.from_config(config)

# Execute multiple queries in a batch
queries = [
    ("INSERT INTO users (name) VALUES (%s)", ("Alice",)),
    ("INSERT INTO users (name) VALUES (%s)", ("Bob",))
]
db.execute_batch(queries)

# Close the connection
db.close()
```

### Transaction Support

```python
from dbops_manager import PostgresOps

db = PostgresOps.from_config(config)

# Use a transaction
with db.transaction():
    db.execute("INSERT INTO users (name) VALUES (%s)", ("Charlie",))
    db.execute("UPDATE users SET status = %s WHERE name = %s", ("active", "Charlie"))

# Close the connection
db.close()
```

### Bulk Insert

```python
from dbops_manager import PostgresOps

db = PostgresOps.from_config(config)

# Bulk insert
values = [("David",), ("Eve",)]
db.execute_values("INSERT INTO users (name) VALUES %s", values)

# Close the connection
db.close()
```

### Logging

Logs are automatically stored in the `dbops_manager_logs` table. You can view them using:

```sql
SELECT * FROM dbops_manager_logs ORDER BY created_at DESC;
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. 
