Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 10 days 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 (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2012-03-26T17:21:11.000Z (almost 13 years ago)
- Last Synced: 2024-10-28T13:27:14.452Z (about 2 months ago)
- Language: Python
- Homepage: http://pypi.python.org/pypi/kemi
- Size: 86.9 KB
- Stars: 4
- Watchers: 3
- 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 setTo 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 DeclarativeMetaBase = declarative_base(metaclass=DeclarativeMeta)
class Customer(Base):
name = Column(String)
billing_address = relationship("Address")
shipping_address = relationship("Address").. _SQLAlchemy: http://www.sqlalchemy.org/