Skip to main content

Fast, simple, reliable — Database management made easy

Project description

EaseDB 🚀

Fast, Simple, Reliable — Database Management Made Easy

EaseDB is a powerful, lightweight database management library designed to simplify database interactions in Python. It provides a clean, intuitive API that supports both synchronous and asynchronous operations across multiple database backends.

🌟 Key Features

  • 🔄 Full Sync and Async Support
  • 🗃️ Multi-Database Backend Compatibility
    • MySQL/MariaDB
    • SQLite
    • PostgreSQL (Coming Soon)
  • 🚀 Simple, Pythonic API
  • 🔒 Safe Connection Management
  • 📦 Lightweight and Efficient

🚀 Quick Installation

pip install easedb

💡 Usage Examples

Synchronous Database Operations (SQLite)

Basic Operation

from easedb import Database

# Create a database connection
db = Database('sqlite:///example.db')

# Insert a record
db.set('users', {
    'name': 'John Doe',
    'age': 30,
    'email': 'john@example.com'
})

# Retrieve a record
user = db.get('users', {'name': 'John Doe'})
print(user)

Synchronous MySQL Database Operations

Table Creation and Basic CRUD Operations

from easedb import Database
import datetime
import decimal

# Create MySQL database connection
db = Database('mysql://user:password@localhost/database')

# Create a table
db.create_table('employees', {
    'id': 'INT AUTO_INCREMENT PRIMARY KEY',
    'name': 'VARCHAR(100) NOT NULL',
    'age': 'INT',
    'salary': 'DECIMAL(10,2)',
    'hire_date': 'DATETIME',
    'is_active': 'BOOLEAN DEFAULT TRUE'
})

# Insert a record
db.set('employees', {
    'name': 'Peter Smith',
    'age': 35,
    'salary': decimal.Decimal('75000.50'),
    'hire_date': datetime.datetime.now(),
    'is_active': True
})

# Retrieve a record
employee = db.get('employees', {'name': 'Peter Smith'})
print("Employee details:", employee)

# Retrieve multiple records
all_employees = db.get_all('employees')
print("All employees:", all_employees)

# Update a record
db.update('employees', 
    {'name': 'Peter Smith'}, 
    {'salary': decimal.Decimal('80000.75')}
)

# Delete a record
db.delete('employees', {'name': 'Peter Smith'})

Complex Queries

# Query with complex conditions
active_senior_employees = db.get_all('employees', {
    'is_active': True, 
    'age': {'>=': 30}
})

# Sorting and limiting results
top_5_salaries = db.get_all('employees', 
    order_by='salary DESC', 
    limit=5
)

Direct SQL Execution

Raw SQL Commands and Advanced Operations

from easedb import Database
import datetime

# Create a database connection
db = Database('mysql://user:password@localhost/database')

# Create a complex table with a single execute command
db.execute('''
    CREATE TABLE IF NOT EXISTS advanced_users (
        id INT AUTO_INCREMENT PRIMARY KEY,
        username VARCHAR(50) UNIQUE NOT NULL,
        email VARCHAR(100) UNIQUE NOT NULL,
        registration_date DATETIME,
        last_login DATETIME,
        login_count INT DEFAULT 0,
        account_status ENUM('active', 'inactive', 'suspended') DEFAULT 'active',
        total_purchases DECIMAL(10,2) DEFAULT 0.00
    )
''')

# Insert multiple records using execute
db.execute('''
    INSERT INTO advanced_users 
    (username, email, registration_date, last_login, login_count, account_status, total_purchases)
    VALUES 
    ('john_doe', 'john@example.com', %s, %s, 5, 'active', 1250.75),
    ('jane_smith', 'jane@example.com', %s, %s, 12, 'active', 3500.25)
''', (
    datetime.datetime.now(), 
    datetime.datetime.now(),
    datetime.datetime.now(), 
    datetime.datetime.now()
))

# Complex query with joins and aggregations
result = db.execute('''
    SELECT 
        u.username, 
        u.email, 
        COUNT(p.id) as purchase_count, 
        SUM(p.amount) as total_spent
    FROM 
        advanced_users u
    LEFT JOIN 
        purchases p ON u.id = p.user_id
    GROUP BY 
        u.id, u.username, u.email
    HAVING 
        total_spent > 1000
    ORDER BY 
        total_spent DESC
    LIMIT 10
''')

# Iterate through results
for row in result:
    print(f"Username: {row['username']}, Total Spent: {row['total_spent']}")

# Transaction example
try:
    db.execute('START TRANSACTION')
    
    # Multiple related operations
    db.execute('UPDATE accounts SET balance = balance - 500 WHERE id = 1')
    db.execute('UPDATE accounts SET balance = balance + 500 WHERE id = 2')
    
    db.execute('COMMIT')
except Exception as e:
    db.execute('ROLLBACK')
    print(f"Transaction failed: {e}")

Batch Operations and Prepared Statements

# Batch insert with prepared statement
users_data = [
    ('alice', 'alice@example.com'),
    ('bob', 'bob@example.com'),
    ('charlie', 'charlie@example.com')
]

db.execute(
    'INSERT INTO users (username, email) VALUES (%s, %s)', 
    users_data
)

Asynchronous Database Operations (MySQL)

from easedb import AsyncDatabase
import asyncio
import datetime
import decimal

async def main():
    # Create an async database connection
    db = AsyncDatabase('mysql://user:password@localhost/database')
    
    # Create a table
    await db.create_table('products', {
        'id': 'INT AUTO_INCREMENT PRIMARY KEY',
        'name': 'VARCHAR(100) NOT NULL',
        'price': 'DECIMAL(10,2)',
        'created_at': 'DATETIME',
        'is_active': 'BOOLEAN DEFAULT TRUE'
    })
    
    # Insert a record
    await db.set('products', {
        'name': 'Laptop',
        'price': decimal.Decimal('1250.00'),
        'created_at': datetime.datetime.now(),
        'is_active': True
    })
    
    # Retrieve a record
    product = await db.get('products', {'name': 'Laptop'})
    print("Product details:", product)

asyncio.run(main())

🛠️ Advanced Features

  • CRUD Operations
  • Async and Sync Support
  • Multiple Database Type Support
  • Automatic Connection Management
  • Error Handling and Retry Mechanisms
  • Query Builder (Planned)
  • Connection Pooling (Planned)

🧪 Testing

We use pytest for comprehensive testing.

Running Tests

# Install test dependencies
pip install -r requirements.txt

# Run all tests
pytest

# Generate coverage report
pytest --cov=src/easedb

🤝 Contributing

Contributions are welcome! Please check our issues page or submit a pull request.

📄 License

MIT

🌐 Links

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

easedb-0.1.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

easedb-0.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file easedb-0.1.0.tar.gz.

File metadata

  • Download URL: easedb-0.1.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.7

File hashes

Hashes for easedb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c63371804f1066374ff2900b488ffea765929ffe2318effc0f722188d5882868
MD5 3da330761cfaac595165b3d1842a65c8
BLAKE2b-256 4162aee29238af65728f566322d6d62c3349a7ff0e330e739d4410f78a310dd4

See more details on using hashes here.

File details

Details for the file easedb-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: easedb-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.7

File hashes

Hashes for easedb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c30ae35827d6d59ee01c2fa238dee5ca0fc291b2ad75d5d45d9a5adcd88bdbee
MD5 a0fc40fb7f60473962509a0f7e7ba754
BLAKE2b-256 33032874702e7ab5ef7db419bfae11550315429888a16f08908fb65fa602f586

See more details on using hashes here.

Supported by

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