Thanks to visit codestin.com
Credit goes to github.com

Skip to content

adrienckr/cognidb

 
 

Repository files navigation

CogniDB

A utility that provides seamless database access to your agents with a single line of code.

📦 Installation

pip install cognidb

⚙️ Configuration

Using Environment Variables (.env)

# Database Settings
HOST=localhost
PORT=3306
DATABASE=your_database
USER=your_username
PASSWORD=your_password

# OpenAI API Key
OPENAI_API_KEY=your-openai-api-key

Using Python Code

from cognidb import CogniDB

db = CogniDB(
    db_type="mysql",  # or "postgresql"
    host="localhost",
    port=3306,
    dbname="your_database",
    user="your_username",
    password="your_password",
    api_key="your-openai-api-key"  # Optional if set in .env
)

🚀 Quick Start

from cognidb import CogniDB

# Initialize using environment variables
db = CogniDB(db_type="mysql")

# Simple query
result = db.query("Show me all customers")

# Query with potential clarification
result = db.query("Show transactions from last month")
  • 📊 MySQL and PostgreSQL support

🔍 Example Queries

# Basic queries
customers = db.query("List all premium customers")

# Aggregations
summary = db.query("Total sales by product category")

# Complex queries
analysis = db.query("Find customers who spent more than average")

⚠️ Error Handling

try:
    db = CogniDB(db_type="mysql")
    result = db.query("Show customer accounts")
except ValueError as e:
    print(f"Configuration error: {e}")
except Exception as e:
    print(f"Query error: {e}")

📦 Dependencies

  • openai
  • psycopg2
  • mysql-connector-python
  • sqlparse
  • psycopg2-binary

📝 License

MIT License © 2024

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%