Skip to main content

A lightweight and intuitive Python ORM for database operations

Project description

TabernacleORM 🏛️

A lightweight, intuitive, and Pythonic ORM for database operations.

✨ Features

  • Simple Model Definition - Define models using Python classes with typed fields
  • Intuitive Query API - Chain methods like filter(), order_by(), limit()
  • Auto Migrations - Built-in migration system for schema versioning
  • SQLite Support - Works out of the box with SQLite (more databases coming soon)
  • Type Hints - Full type annotation support for better IDE experience

📦 Installation

pip install tabernacleorm

Or install from source:

pip install -e .

🚀 Quick Start

1. Define Your Models

from tabernacleorm import Model, Database, StringField, IntegerField, DateTimeField

# Initialize database
db = Database("my_app.db", echo=True)

# Define your model
class User(Model):
    name = StringField(max_length=100, nullable=False)
    email = StringField(max_length=255, unique=True)
    age = IntegerField(nullable=True)
    created_at = DateTimeField(auto_now_add=True)

# Connect model to database
User.set_database(db)

# Create the table
db.create_table(User)

2. Create Records

# Method 1: Create and save
user = User(name="John Doe", email="john@example.com", age=30)
user.save()

# Method 2: Create directly
user = User.create(name="Jane Doe", email="jane@example.com", age=25)

3. Query Records

# Get all users
users = User.all()

# Filter users
young_users = User.filter(age__lt=30)
john = User.get(name="John Doe")

# Chain queries
users = User.filter(age__gte=18).order_by("-created_at").limit(10)

# Advanced filtering
admins = User.filter(email__contains="@admin.com")
recent = User.filter(created_at__gte=yesterday)

4. Update Records

user = User.get(id=1)
user.name = "John Smith"
user.save()

# Or bulk update
User.filter(age__lt=18).update(status="minor")

5. Delete Records

user = User.get(id=1)
user.delete()

# Or bulk delete
User.filter(active=False).delete()

📋 Field Types

Field Type SQL Type Python Type
IntegerField INTEGER int
StringField VARCHAR str
TextField TEXT str
FloatField REAL float
BooleanField BOOLEAN bool
DateTimeField DATETIME datetime
DateField DATE date
ForeignKey INTEGER int

🔍 Query Operators

Operator Description Example
__gt Greater than age__gt=18
__gte Greater or equal age__gte=18
__lt Less than age__lt=65
__lte Less or equal age__lte=65
__ne Not equal status__ne="inactive"
__in In list id__in=[1, 2, 3]
__contains Contains substring name__contains="John"
__startswith Starts with email__startswith="admin"
__endswith Ends with email__endswith=".com"
__isnull Is null check deleted_at__isnull=True

🔄 Migrations

from tabernacleorm import Database
from tabernacleorm.migrations import Migration, MigrationManager, Schema

db = Database("my_app.db")
manager = MigrationManager(db)

class AddStatusColumn(Migration):
    version = "001"
    description = "Add status column to users table"
    
    def up(self, db):
        db.execute(Schema.add_column("users", "status", "VARCHAR(50) DEFAULT 'active'"))
    
    def down(self, db):
        # SQLite doesn't support DROP COLUMN easily
        pass

manager.register(AddStatusColumn())
manager.migrate()

🛠️ Development

# Clone the repository
git clone https://github.com/yourusername/tabernacleorm.git
cd tabernacleorm

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black src tests
isort src tests

📄 License

MIT License - see LICENSE for details.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

tabernacleorm-0.1.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

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

tabernacleorm-0.1.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tabernacleorm-0.1.0.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for tabernacleorm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2756db6f8adf6d41b48a30c8eec34fbdcdc7fd0fa5811dfa655f4be7eab304c4
MD5 e015a6fa6944215f99ea8a407d915bb4
BLAKE2b-256 6e4ef7da6e43b9cdd3d956b4eb017328201b7a1d7cd6d1a9b1cf02b8b9688b50

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tabernacleorm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for tabernacleorm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e72ab56f35ec6ef397ab09b60cddfdd8a6d28b3ff7c791c87a78c92e60856f81
MD5 a4fef203e586c9412c6b27decbabd7da
BLAKE2b-256 334f1899204fe2d2b77b7dd63900265b6d14fe9592323c08690c16cf8415b9cb

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