Introduction

Please note that TurboEntity is now deprecated, please switch to it's official successor Elixir. Thank you!

What is TurboEntity?

In short, TurboEntity is a high-level declarative layer on top of SQLAlchemy, inspired by - but somewhat "thicker" than - Jonathan LaCour's ActiveMapper extension.

Features currently include:

There are limitations, though:

You can mix TurboEntity with plain SQLAlchemy as well as with ActiveMapper, it should all work fine together. As soon as you have defined your models and TurboEntity has created and initialized the necessary tables and mappers, you can continue to use SQLAlchemy exactly as you would usually.

The prefix "Turbo" doesn't mean that TurboEntity is strictly tied to TurboGears, or that it'd be a part of it or anything alike. As the provided examples show, it just depends on SQLAlchemy, nothing else. I just needed an easy to use mapper for some TurboGears-based projects, and the name reflects that: setup your models fast.

top

But there's already ActiveMapper?

Yes, and TurboEntity is not meant to fully replace it. If you need total control over your tables and columns you better stay with ActiveMapper or maybe plain SQLAlchemy. I just wanted something that does all that database-specific stuff automatically, like creating foreign-keys, secondary tables and the like, so I can concentrate on my models. I wanted to be able to create relationships the easiest imaginable way and have all the grind work done automatically.

As the name alludes, TurboEntity integrates fine with TurboGears. For an identity-example visit the examples-page

top

So what does it look like?

Less talk, more action - here's a short example:

from turboentity import *

class Movie (Entity):
    title = Column(Unicode(50))
    year = Column(Integer)
    actors = ManyToMany("Actor", order_by="name")
    genre = ManyToOne("Genre")

class Actor (Entity):
    name = Column(Unicode(60))
    movies = ManyToMany("Movie")

class Genre (Entity):
    title = Column(Unicode(30))
    movies = OneToMany("Movie", order_by="-year")

Now that's basically all. TurboEntity sets up three primary keys (as there are no userdefined primary keys here) - named "id" per default - and four database tables:

TurboEntity automatically figures out the relationships that resemble each other's inverses. Unlike ActiveMapper you can and should define relationships on both sides. If you leave out one side, you should specify the name of the inverse through the backref="{colname}"-parameter.

You can also specify both sides of the relationship and the backrefs. This way you enable TurboEntity to find the matching sides if you have multiple relationships between two entities.

This is just a small example to show you how it basically works, for more code look at the examples-page.

top

Where's the download?

TurboEntity is easily installed via setuptools. Just type

easy_install TurboEntity

into a terminal and you're done. It will also fetch and install all necessary dependencies for you, including SQLAlchemy if you don't have it yet.

You can also download the egg or the source here:

top