A simple OracleDB handler for executing queries with pandas.
Project description
OracleDBHandler Library
Overview
OracleDBHandler
is a Python class designed to simplify interactions with an Oracle database. It provides functionality to connect to the database, insert and update data from a pandas
DataFrame, execute arbitrary queries, delete data, check for duplicate records, and more. (Link: https://pypi.org/project/OracleDBHandler/)
Features
- Connect to an Oracle database.
- Insert data from a
pandas
DataFrame. - Update data in an Oracle table.
- Execute arbitrary queries with or without parameters and return the results.
- Delete data from tables with or without conditions.
- Check for duplicates in a table based on specified columns.
- Close the connection to the Oracle database.
Requirements
Make sure you have the necessary libraries installed:
- Python 3.x
oracledb
andpandas
libraries:pip install oracledb pandas
Installation
Install via pip:
pip install OracleDBHandler
Usage
1. Initialize and Connect to Oracle Database
Instantiate the OracleDBHandler
class with your Oracle database credentials and call the connect
method.
from OracleDBHandler import OracleDBHandler
db_handler = OracleDBHandler(
user='your_user',
password='your_password',
host='your_host',
port='your_port',
serviceName='your_service'
)
db_handler.connect()
2. Insert Data into Oracle Table
import pandas as pd
data = {'ID': [1, 2], 'Name': ['John', 'Alice'], 'Age': [25, 30]}
df = pd.DataFrame(data)
db_handler.insert_data(df, 'your_table')
3. Update Data in Oracle Table
updated_data = {'ID': [1], 'Name': ['John Updated'], 'Age': [26]}
df_update = pd.DataFrame(updated_data)
db_handler.update_data(df_update, 'your_table', 'ID')
4. Execute Arbitrary Queries
query = "SELECT * FROM your_table WHERE Age > :age"
params = {'age': 25}
result = db_handler.execute_query(query, params)
print(result)
5. Delete Data from a Table
# Delete data with condition
db_handler.delete_data('your_table', 'Age > 30')
# Delete all data
db_handler.delete_data('your_table')
6. Check for Duplicate Records
# Check for duplicates based on specific columns
duplicates = db_handler.check_duplicates('your_table', ['Name', 'Age'])
print(duplicates)
# Check for duplicates across all columns
duplicates_all = db_handler.check_duplicates('your_table')
print(duplicates_all)
7. Close the Database Connection
db_handler.close()
Error Handling
The library provides basic error handling for database-related issues. If a connection or query fails, the exception message is printed, and the transaction is rolled back if necessary.
License
This project is licensed under the MIT License.
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
Built Distribution
File details
Details for the file oracledbhandler-0.1.0.tar.gz
.
File metadata
- Download URL: oracledbhandler-0.1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cb1e99a92641f1b98cb43a32a89f3e73d20de3b33d14213a1c7ed8c65c9478c |
|
MD5 | ba83b990ba30ab5bb45387a5d0f761fd |
|
BLAKE2b-256 | 67426004055e5e3264ffbf6b5f59e1723e81a8665bb5c5a3c2f29eae32c03d36 |
File details
Details for the file OracleDBHandler-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: OracleDBHandler-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24710b95bfa65a34b1658141c4bd64051f5c7af85ba65765467a9d3b3015a0fd |
|
MD5 | aa0b20d63e0ee561d4f6b49077b57fc1 |
|
BLAKE2b-256 | 1244febbc470f51cc9db8026f3647c9d526062015290217f5e2bd8f7e3bb6442 |