ormDB + SQLAlchemy
What This Adapter Does
ormDB is a relational database engine written in Rust that replaces PostgreSQL, MySQL, and SQLite as the actual database underneath your application. The ormdb[sqlalchemy] package connects SQLAlchemy’s ORM layer to ormDB, so your mapped classes, relationships, and session-based workflows continue to work while the database resolves object graphs natively.
SQLAlchemy’s relationship() declarations describe how your Python objects relate to each other. With a SQL database, loading related objects triggers additional queries or complex JOINs depending on your loading strategy. ormDB receives the relationship graph as a native graph-fetch request and returns the complete object tree in a single round-trip, regardless of depth, eliminating N+1 queries.
Quick Setup
Install the adapter:
pip install ormdb[sqlalchemy]
Configure the engine:
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
engine = create_engine("ormdb://localhost:5555/mydb")
Your existing mapped classes and queries work unchanged:
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
class Base(DeclarativeBase):
pass
class User(Base):
__tablename__ = "users"
id: Mapped[str] = mapped_column(primary_key=True)
name: Mapped[str]
posts: Mapped[list["Post"]] = relationship(back_populates="author")
class Post(Base):
__tablename__ = "posts"
id: Mapped[str] = mapped_column(primary_key=True)
title: Mapped[str]
author_id: Mapped[str] = mapped_column(ForeignKey("users.id"))
author: Mapped["User"] = relationship(back_populates="posts")
comments: Mapped[list["Comment"]] = relationship()
# Single round-trip graph fetch
with Session(engine) as session:
users = session.query(User).options(
joinedload(User.posts).joinedload(Post.comments)
).all()
What Changes, What Stays the Same
Stays the same: Mapped classes, relationship() declarations, Session operations, query() and select() patterns, loading strategies (joinedload, subqueryload, selectinload), and transaction management.
Changes: The database engine. All loading strategies become single-round-trip graph fetches. Migrations gain A-D safety grading via Alembic integration. Vector search, geo search, full-text search, and change streams are available natively. SQLAlchemy with ormDB is ideal for Python/Django projects.
Removed: Raw SQL via text(), session.execute("SELECT ..."), and SQLAlchemy Core table expressions. All queries must use the ORM layer. See how ormDB compares to PostgreSQL, the database SQLAlchemy most commonly connects to.
Frequently Asked Questions
Do SQLAlchemy's relationship() declarations work with ormDB?
Yes. Your existing relationship() declarations map directly to ormDB's native relations. When you access related objects or use joinedload/subqueryload, ormDB resolves the entire object graph in a single round-trip.
Does the SQLAlchemy Core (non-ORM) layer work?
The adapter supports SQLAlchemy ORM operations through the Session and mapped classes. SQLAlchemy Core's raw SQL text() expressions and direct table operations are not supported because ormDB does not use SQL.
Can I use Alembic migrations with ormDB?
The adapter integrates with Alembic. Migration operations are routed through ormDB's engine, which grades each migration from A (safe) to D (destructive) before applying it.
What about SQLAlchemy's async support?
The adapter supports both synchronous and asynchronous sessions. AsyncSession works with ormDB's native async protocol for non-blocking database operations.
Is the adapter production-ready?
The adapter is in beta. ormDB itself is in Alpha v0.1.0. It is suitable for development and testing today, with production readiness expected as ormDB reaches stable releases.