A lightweight PostgreSQL operations manager for AWS Lambda
Project description
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
pip install dbops-manager
Usage
Basic Usage
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
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
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
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
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:
SELECT * FROM dbops_manager_logs ORDER BY created_at DESC;
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dbops_manager-0.1.8.tar.gz
(7.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dbops_manager-0.1.8.tar.gz.
File metadata
- Download URL: dbops_manager-0.1.8.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad52788861b8ab7a0821c1593b1f6848034c94af253bb09e8a09e914cc443338
|
|
| MD5 |
bc5fd9ccfce66935b04f93b634e18aa2
|
|
| BLAKE2b-256 |
9ae9ab47943942e0cb0a774e044274952a944b2ca1b7ea9f112122091e884606
|
File details
Details for the file dbops_manager-0.1.8-py3-none-any.whl.
File metadata
- Download URL: dbops_manager-0.1.8-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77625d37cf810665a102246e6ee1a7a1ee2633cd3c75aca7c33d90901b9bc669
|
|
| MD5 |
d1cd94cec3aea121378b4117ce56862e
|
|
| BLAKE2b-256 |
850763d6dc6c651f19dc4042ede38d885620529348b17bd2e7f0229317e7abbf
|