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/ganilson/tabernacleorm.git
cd tabernacleorm
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black src tests
isort src tests
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
AUTHOR: Ganilson Garcia - ANGOLA, HUILA, LUBANGO
Project details
Release history Release notifications | RSS feed
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.1.tar.gz
(17.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tabernacleorm-0.1.1.tar.gz.
File metadata
- Download URL: tabernacleorm-0.1.1.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cedf380437850b5cd2fdc139dc762bcc172936dfe271dcf7f9b8bf797b548183
|
|
| MD5 |
7d2a33f918310b3b9bde7c0887c7aef7
|
|
| BLAKE2b-256 |
1c3e3221f8c9c03f3c012ebf8b45b17f7b512cd0df1cf037fdc01e78c465ddaa
|
File details
Details for the file tabernacleorm-0.1.1-py3-none-any.whl.
File metadata
- Download URL: tabernacleorm-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d4874dc053d95dfe07ddb6edbe26b9f5883284a0d4eaf3806c9ad9cbbb64aa1
|
|
| MD5 |
9fabe1e3251a8072542adcdb0d6fbc42
|
|
| BLAKE2b-256 |
aea46b70fe7ea3cda5f7a4f7fb1c1940f2c50692f6b268a42584b3b62957eb72
|