https://github.com/dnouri/kemi
kemi is an add-on for SQLAlchemy that aims to make defining relations with declarative easier for the most common cases.
https://github.com/dnouri/kemi
Last synced: 12 months ago
JSON representation
kemi is an add-on for SQLAlchemy that aims to make defining relations with declarative easier for the most common cases.
- Host: GitHub
- URL: https://github.com/dnouri/kemi
- Owner: dnouri
- Created: 2012-03-26T17:09:45.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2012-03-26T17:21:11.000Z (about 14 years ago)
- Last Synced: 2025-04-03T00:42:41.432Z (about 1 year ago)
- Language: Python
- Homepage: http://pypi.python.org/pypi/kemi
- Size: 86.9 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
kemi
====
kemi is an add-on for SQLAlchemy_ that aims to make defining relations
with declarative easier for the most common cases.
Consider this example from the SQLAlchemy docs::
class Customer(Base):
__tablename__ = 'customer'
id = Column(Integer, primary_key=True)
name = Column(String)
billing_address_id = Column(Integer, ForeignKey("address.id"))
shipping_address_id = Column(Integer, ForeignKey("address.id"))
billing_address = relationship("Address",
primaryjoin="Address.id==Customer.billing_address_id")
shipping_address = relationship("Address",
primaryjoin="Address.id==Customer.shipping_address_id")
Using kemi, this can be written as::
class Customer(Base):
name = Column(String)
billing_address = relationship("Address")
shipping_address = relationship("Address")
Things that kemi currently does:
* adds a ``__tablename__`` if none is explicitely set on the class
* adds an ``id`` column if no primary key column is present
* adds foreign key columns for relationships if no foreign key columns
are present
* adds ``primaryjoins`` to relationships if they're not set
To use kemi, you need to use its DeclarativeMeta class when you make a
call to ``declarative_base``::
from sqlalchemy.ext.declarative import declarative_base
from kemi import DeclarativeMeta
Base = declarative_base(metaclass=DeclarativeMeta)
class Customer(Base):
name = Column(String)
billing_address = relationship("Address")
shipping_address = relationship("Address")
.. _SQLAlchemy: http://www.sqlalchemy.org/