Skip to main content

dbLinkPro

dbLinkPro is a versatile Python package designed to simplify database interactions by offering a unified interface for performing CRUD (Create, Read, Update, Delete) operations across Cassandra, MongoDB, and MySQL databases. This package not only supports essential database operations but also enhances the user experience with additional features specific to each database type.

Features

Cassandra-Specific Enhancements

  • Docker Integration: Automatically starts a Cassandra Docker container if it's not running. Handles container creation, volume management, and startup checks.
  • Connection Timeout Handling: Implements retry logic to handle connection delays, ensuring that Cassandra is fully operational before proceeding.
  • Keyspace and Table Management: Create and manage keyspaces and tables with flexible schema definitions. Switch between keyspaces easily.
  • Schema Retrieval: Retrieve and validate table schemas, including checking the compatibility of data types for updates and deletions.
  • Bulk Data Ingestion: Supports bulk insertion of data from CSV and Excel files into Cassandra tables.
  • Custom Query Handling: Construct and execute custom queries for inserting, updating, and deleting records with validation based on schema types.
  • Container Lifecycle Management: Start, stop, and remove Cassandra Docker containers programmatically.

Installation

You can install dbLinkPro using pip:

pip install dbLinkPro

Usage

MySQL

from database_automation import mysql_crud

Create a connection instance

connection = mysql_crud.MySQLConnection(
    host='localhost',
    user='your_username',
    password='your_password',
    database='test_db',
    port=3306
)

Connect to the database

connection.connect()

Create a new database if it does not exist

connection.create_database()

Table operations

columns = {
    'id': 'INT AUTO_INCREMENT PRIMARY KEY',
    'name': 'VARCHAR(100)',
    'age': 'INT'
}
connection.create_table('person', columns)

record = {
    'name': 'Alice',
    'age': 28
}
connection.insert_record('person', record)

records = connection.select_record('person')
print(records)  # Output: [[1, 'Alice', 28]]

update_values = {'age': 29}
connection.update_record('person', update_values, 'name = "Alice"')

connection.delete_record('person', 'name = "Alice"')

Disconnect from the database

connection.disconnect()

MongoDB

from database_automation import mongo_crud

Create an instance of MongoOperation

mongo = mongo_crud.MongoOperation(
    client_url='mongodb://localhost:27017/',
    database_name='test_db',
    collection_name='test_collection'
)

Create a MongoDB client

client = mongo.create_mongo_client()

Create or access the database

database = mongo.create_database()

Create or access the collection

collection = mongo.create_collection()

CRUD operations

single_record = {'name': 'John Doe', 'age': 35}
mongo.insert_record(single_record, 'test_collection')

multiple_records = [
    {'name': 'Jane Smith', 'age': 28},
    {'name': 'Emily Davis', 'age': 40}
]
mongo.insert_record(multiple_records, 'test_collection')

mongo.bulk_insert('data.csv', 'test_collection')

mongo.bulk_insert('data.xlsx', 'test_collection')

Cassandra

from database_automation import cassandra_crud

Create an instance of CassandraOperation

cassandra = cassandra_crud.CassandraOperation(
    contact_points=['127.0.0.1'],
    volume='cassandra_data'
)

Connect to Cassandra

session = cassandra.connect(username='your_username', password='your_password')

Create a keyspace

cassandra.create_keyspace('test_keyspace', strategy='SimpleStrategy', replicas=1)

Use the created keyspace

cassandra.use_keyspace('test_keyspace')

Define table schema

schema = {
    'id': 'int',
    'name': 'text',
    'age': 'int'
    }

Create a table

cassandra.create_table('test_table', schema)

Insert a record

record = {'id': 1, 'name': 'John Doe', 'age': 30}
cassandra.insert_record('test_table', record)

Bulk insert from a CSV file

cassandra.bulk_insert('data.csv', 'test_table')

Fetch Records

rows = cassandra.fetch_records('test_table')
for row in rows:
    print(row)

Update a record

update_values = {'name': 'Jane Doe', 'age': 29}
cassandra.update_record('test_table', 'id', 1, update_values)

Delete a record

cassandra.delete_record('test_table', 'id', 1)

Close the connection

cassandra.close()

Contributing

I welcome contributions to dbLinkPro. If you'd like to contribute, please..

  1. Fork the repository on GitHub.
  2. Create a new branch for your changes.
  3. Make your changes and commit them with descriptive messages.
  4. Push your changes to your fork.
  5. Submit a pull request with a detailed explanation of your changes.

License

dbLinkPro is licensed under the MIT License.

Author/Maintainer

Sneh Pillai

Contact Information

For support or questions, please contact: snehpillai02@gmail.com

Metadata

Release files for dbLinkPro 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dbLinkPro 0.0.2
File Size Uploaded
dblinkpro-0.0.2.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dbLinkPro 0.0.2
File Interpreter ABI Platform
dbLinkPro-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 18.5 kB

Release files / dblinkpro-0.0.2.tar.gz

Download URL dblinkpro-0.0.2.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4c7a841a8fd438a47013705250f1b9bf90a05a30662a627c05e7b3dbac8df40d
BLAKE2b-256 checksum
How to use checksums
0a573220098c61fe81e91c2c97a7f82c9febf6d599e26af25f4910f3deed68e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release files / dbLinkPro-0.0.2-py3-none-any.whl

Download URL dbLinkPro-0.0.2-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c167661da6a392ed9085f566a5a96f7fdb89f80753d99f22997854d1471cba1
BLAKE2b-256 checksum
How to use checksums
049e9fb53ccbcd55d1430a7b3cef4dca7f1eba73885b7fd3b461b18713ec0e8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page