Metadata-Version: 2.4
Name: zhibet_starter_pack
Version: 0.2.0
Summary: A database utility package using psycopg2
Author-email: Amadou Bah <Amadou.Bah@its.ny.gov>
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: psycopg2-binary>=2.9.0
Requires-Dist: python-dotenv>=1.0.0
Dynamic: license-file

# zhibet

`zhibet` is a lightweight Python utility package designed to simplify PostgreSQL database connections and safe query execution using `psycopg2` and `python-dotenv`.

## Features

- **Easy Connection Management**: Automatically loads database credentials from environment variables.
- **SQL Injection Prevention**: Built-in support for safe, dynamic SQL query construction using `psycopg2.sql`.
- **Input Validation**: Helper utilities utilizing regular expressions to validate database inputs (like table names or email formats) before execution.

## Class Method Table's

these methods can be initiated by the following command : **db.Method()**
> Postgres Methods

| Method | Description | 
|--------|-----|
| connect_db | Establishes a secure connection to the Postgress database |
| create_table | Creates a new table in the postgres database based on a specified schema definition | 
| insert_data| Inserts one new records (row) into a designated table |
| drop_table| Permanently deletes a specified table and all of its contained data from the Postgres database|
| modify_table| Alters the structure or schema of an existing table (e.g., adding, modifying, or dropping columns) inside the postgres database |


> MSSQL Methods

| Method | Description | 
|--------|-----|
|get_mssql_engine| Establishes a secure connection to the mssql database|


> Helper Functions

| Method | Description | 
|--------|-----|
|pdf_reader| extra table data from a pdf and dump it into a spreadsheet
| migrate| migrate data from one source to another, using a chunk size as a params |


## Usage

The following section illustrate how to effectively use the tool

>Tool Initiation

```bash
from zhibet.zhibet import Zhibet

db = Zhibet()

try:
    # Database connection initition
    db.connect_db(user_str,password_str,database_str,port,host_str)

except  Exception as e:
    print(f"Table creation failed {e}")
```

>Table Creation Walkthrough :

```bash
table_name = "practice_creaction_table_1"

# variable = dict[str, list[str]]
Table_Creation_Schema = {
    # Replace "AUTOINCREMENT" with "GENERATED BY DEFAULT AS IDENTITY" for Postgres
    "id": ["INTEGER", "PRIMARY KEY", "GENERATED BY DEFAULT AS IDENTITY"],
    "username": ["TEXT", "NOT NULL", "UNIQUE"],
    "email": ["TEXT", "NOT NULL"],
    "age": ["INTEGER"],
    "<>": ["TEXT"],
    # Note: TIMESTAMP is preferred over TEXT for date/time fields in Postgres
    "created_at": ["TIMESTAMP", "DEFAULT CURRENT_TIMESTAMP"]
}

try:
    # Create New Table
    db.create_table(table_name,new_table_schema,workspace_schema)

except Exception as e:

    print(f"Table creation failed {e}")

```

>Data Insertion Walkthrough :

``` bash
# follow the following format : variable = dict[str, list[str]]

# Data schema example
sample_data = {
    "username": "Snow White",
    "email": "john.doe@example.com",
    "age": 45
    "<>":"<>"
}

# Sample Table Title
created_table_name = "practice_creaction_table_1"

# Table location / container
workspace_str = "<home>"

try:
    # Insert Data
    db.insert_data(created_table_name,sample_data,workspace_str)

except Exception as e:

    print(f"Table creation failed {e}")
```

>Table Deletion Walkthrough :

``` Bash
# Sample Table Title
created_table_name = "practice_creaction_table_1"

try:
    # Drop Table
    db.drop_table(created_table_name,"workspace")

except Exception as e:

    print(f"Table creation failed {e}")
```

>Table Modification Walkthrough :

``` Bash
created_table_name = "practice_creaction_table_1"

try:
    # Motify Table
    db.modify_table(created_table_name,"drop")

except Exception as e:

    print(f"Table creation failed {e}")
```
