Skip to main content

A Python package for managing database operations with a focus on logging and simple CRUD operations.

Project description

DB Operations Manager

A Python package for managing database operations with a focus on logging and simple CRUD operations.

Features

  • Simple CRUD Operations: Insert, update, delete, and fetch data from your database.
  • Logging: Automatically log database operations to a dbops_manager_logs table.
  • Concurrency Support: Use multiple workers to perform concurrent database operations.

Installation

pip install dbops-manager

Usage

Basic Usage

from dbops_manager import PostgresOps

# Initialize the database connection
db = PostgresOps({
    'dbname': 'your_db',
    'user': 'your_user',
    'password': 'your_password',
    'host': 'localhost',
    'port': '5432'
}, logging_enabled=True)

# Insert a row
db.execute(
    "INSERT INTO your_table (name, age) VALUES (%s, %s)",
    ["Alice", 30]
)

# Fetch data
data = db.fetch("SELECT * FROM your_table")
print(data)

# Close the connection
db.close()

Concurrent Operations

import concurrent.futures

def insert_row(db, worker_id):
    db.execute(
        "INSERT INTO your_table (name, age) VALUES (%s, %s)",
        [f"Worker-{worker_id}", 20 + worker_id]
    )

# Use ThreadPoolExecutor to insert rows concurrently
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor:
    futures = [executor.submit(insert_row, db, i) for i in range(10)]
    concurrent.futures.wait(futures)

Logging

The package automatically logs database operations to a dbops_manager_logs table. You can query this table to see the history of operations.

logs = db.fetch("SELECT * FROM dbops_manager_logs ORDER BY created_at DESC LIMIT 10")
print(logs)

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


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.5.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dbops_manager-0.1.5-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file dbops_manager-0.1.5.tar.gz.

File metadata

  • Download URL: dbops_manager-0.1.5.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for dbops_manager-0.1.5.tar.gz
Algorithm Hash digest
SHA256 86269502cc114c20499dff0c73060916937d41b3a7cf0f687092d477ba15e541
MD5 ec2aa4db0b7c02d18816e31b1b31214b
BLAKE2b-256 1f85d002c840935393590f8fe1f114a1712f64174a413e511edfe3099ca1bc98

See more details on using hashes here.

File details

Details for the file dbops_manager-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: dbops_manager-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for dbops_manager-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 46a3f93f21970b7eff4cbcbd738da7fbc72a44c8dead01835c33672b49bf6fa1
MD5 37a12f2f306ed27fd3a22cb9eebee402
BLAKE2b-256 27165ce98e3df35671499e6f7c9e5deaf339753a53d8dc27f3bc79cba92a2539

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page