Skip to main content

Package for using multi DBs for Infinity team

Project description

infi-multiDB

Description of your library goes here.

Installation

pip install infi_multi_db

Usage

Here is a simple example of usage

from infi_multi_db import MultiDB

# Replace these values with your actual PostgreSQL connection parameters
connection_params = {
    "dbname": "test",
    "user": "postgres",
    "password": "1234",
    "host": "localhost",
    "port": 5432,
}

# Instantiate the InfiMultyDB with PostgreSQL as the database type
multi_db = MultiDB(db_type="postgresql", connection_params=connection_params)

# Start the connection
multi_db.start_connection()

# Example: Create a table
table_name = "example_table"
columns = [("id", "SERIAL"), ("name", "VARCHAR(255)"), ("age", "INTEGER")]
multi_db.create_table(table_name, columns)

# Example: Insert a record into the table
record_data = {"name": "John Doe", "age": 30}
multi_db.create_record(table_name, record_data)

# Example: Read records from the table
query = "age > 25"
records = multi_db.read_records(table_name, query)
print("Records:", records)
records = multi_db.read_records(table_name, query, ["age"])
print("Records:", records)


# Example: Update a record in the table
record_id_to_update = 1  # Replace with the actual record ID
new_data = {"age": 31}
multi_db.update_record(table_name, record_id_to_update, new_data)

# Example: Read records after update
records_after_update = multi_db.read_records(table_name, query)
print("Records after update:", records_after_update)

# Example: Delete the table
multi_db.delete_table(table_name)

# Stop the connection
multi_db.stop_connection()

Alternatively, you can import DB classes directly and use them. For example:

from infi_multi_db import PostgreSQL

# Replace these values with your actual PostgreSQL connection parameters
connection_params = {
    "dbname": "test",
    "user": "postgres",
    "password": "1234",
    "host": "localhost",
    "port": 5432,
}

# Instantiate the InfiMultyDB with PostgreSQL as the database type
post_db = PostgreSQL(connection_params=connection_params)

# Start the connection
post_db.start_connection()

# Example: Create a table
table_name = "example_table"
columns = [("id", "SERIAL"), ("name", "VARCHAR(255)"), ("age", "INTEGER")]
post_db.create_table(table_name, columns)

# Example: Insert a record into the table
record_data = {"name": "John Doe", "age": 30}
post_db.create_record(table_name, record_data)

# Example: Read records from the table
query = "age > 25"
records = post_db.read_records(table_name, query)
print("Records:", records)
records = post_db.read_records(table_name, query, ["age"])
print("Records:", records)


# Example: Update a record in the table
record_id_to_update = 1  # Replace with the actual record ID
new_data = {"age": 31}
post_db.update_record(table_name, record_id_to_update, new_data)

# Example: Read records after update
records_after_update = post_db.read_records(table_name, query)
print("Records after update:", records_after_update)

# Example: Delete the table
post_db.delete_table(table_name)

# Stop the connection
post_db.stop_connection()

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

infi_multi_db-0.0.3.tar.gz (5.5 kB view hashes)

Uploaded Source

Built Distribution

infi_multi_db-0.0.3-py3-none-any.whl (5.9 kB view hashes)

Uploaded Python 3

Supported by

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