Module: properties

This module provides support for defining properties on your entities. It both provides, the Property class which acts as a building block for common properties such as fields and relationships (for those, please consult the corresponding modules), but also provides some more specialized properties, such as ColumnProperty and Synonym. It also provides the GenericProperty class which allows you to wrap any SQLAlchemy property, and its DSL-syntax equivalent: has_property.

has_property

The has_property statement allows you to define properties which rely on their entity's table (and columns) being defined before they can be declared themselves. The has_property statement takes two arguments: first the name of the property to be defined and second a function (often given as an anonymous lambda) taking one argument and returning the desired SQLAlchemy property. That function will be called whenever the entity table is completely defined, and will be given the .c attribute of the entity as argument (as a way to access the entity columns).

Here is a quick example of how to use has_property.

class OrderLine(Entity):
    has_field('quantity', Float)
    has_field('unit_price', Float)
    has_property('price',
                 lambda c: column_property(
                     (c.quantity * c.unit_price).label('price')))

Classes

ColumnProperty

A specialized form of the GenericProperty to generate SQLAlchemy column_property's.

EntityBuilder

Abstract base class for all entity builders. An Entity builder is a class of objects which can be added to an Entity (usually by using special properties or statements) to "build" that entity. Building an entity, meaning to add columns to its "main" table, create other tables, add properties to its mapper, ... To do so an EntityBuilder must override the corresponding method(s). This is to ensure the different operations happen in the correct order (for example, that the table is fully created before the mapper that use it is defined).

GenericProperty

Generic catch-all class to wrap an SQLAlchemy property.

Property

Abstract base class for all properties of an Entity.