Giter Site home page Giter Site logo

base-de-donnee's Introduction

DataBaseV2 - Python Database Utility

Overview

The DataBaseV2 class is a Python utility for interacting with relational databases using SQLAlchemy. This utility is designed to simplify common database operations such as table creation, data retrieval, insertion, deletion, and updates. It currently supports SQLite, MySQL, and PostgreSQL database types.

Dependencies

  • Python 3.11.3
  • SQLAlchemy 2.0.21
  • pandas 2.2.0

Installation

Ensure that the required dependencies are installed. You can install them using the following command:

pip install sqlalchemy==2.0.21 pandas==2.2.0

Usage

Initializing the Database Connection

from DataBaseV2 import DataBaseV2

# Example for SQLite
db_instance = DataBaseV2(db_name='example_db', db_type='sqlite')

# Example for MySQL
db_instance = DataBaseV2(
    db_name='example_db',
    db_type='mysql',
    db_user='your_username',
    db_password='your_password',
    db_host='localhost',
    db_port=3306
)

# Example for PostgreSQL
db_instance = DataBaseV2(
    db_name='example_db',
    db_type='postgresql',
    db_user='your_username',
    db_password='your_password',
    db_host='localhost'
)

Creating a Table

db_instance.create_table('example_table', id=db.Integer, name=db.String(255), age=db.Integer)

Adding a Row

db_instance.add_row('example_table', name='John Doe', age=25)

Retrieving Data as DataFrame

data = db_instance.dataframe('example_table')
print(data)

Deleting a Row by ID

db_instance.delete_row_by_id('example_table', 1)

Updating a Row by ID

db_instance.update_row_by_id('example_table', 1, name='Updated Name', age=30)

Querying Database and Getting Result as DataFrame

query = "SELECT * FROM example_table WHERE age > 25"
result = db_instance.query_to_dataframe(query)
print(result)

Deleting a Table

db_instance.delete_table('example_table')

Note

  • Ensure that you have the necessary privileges to perform operations on the specified database.
  • Error handling has been implemented for common scenarios, but it's advisable to further enhance it based on specific use cases.

Contributing

Feel free to contribute to the improvement and expansion of this utility. Fork the repository, make your changes, and submit a pull request.

License

This project is licensed under the MIT License.

base-de-donnee's People

Contributors

quera-fr avatar mickevin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.