| 2 | | Special properties statements for Elixir entities |
| 3 | | |
| 4 | | ========== |
| 5 | | Properties |
| 6 | | ========== |
| 7 | | |
| 8 | | This module contains DSL statements which allow you to declare special |
| 9 | | properties your Elixir entities might have. For simple fields or |
| 10 | | relationships between your entities, please see the corresponding modules. |
| | 2 | This module provides support for defining properties on your entities. It both |
| | 3 | provides, the `Property` class which acts as a building block for common |
| | 4 | properties such as fields and relationships (for those, please consult the |
| | 5 | corresponding modules), but also provides some more specialized properties, |
| | 6 | such as `ColumnProperty`. It also provides the GenericProperty class which allows you to wrap any SQLAlchemy property, and its DSL-syntax equivalent: |
| | 7 | has_property_. |
| 14 | | The `has_property` statement allows you to define properties which rely on |
| 15 | | their entity's table and columns (an thus which need them to be defined before |
| 16 | | the property can be declared). |
| | 11 | The ``has_property`` statement allows you to define properties which rely on |
| | 12 | their entity's table (and columns) being defined before they can be declared |
| | 13 | themselves. The `has_property` statement takes two arguments: first the name of |
| | 14 | the property to be defined and second a function (often given as an anonymous |
| | 15 | lambda) taking one argument and returning the desired SQLAlchemy property. That |
| | 16 | function will be called whenever the entity table is completely defined, and |
| | 17 | will be given the .c attribute of the entity as argument (as a way to access |
| | 18 | the entity columns). |
| | 39 | ''' |
| | 40 | Abstract base class for all entity builders. An Entity builder is a class |
| | 41 | of objects which can be added to an Entity (usually by using special |
| | 42 | properties or statements) to "build" that entity. Building an entity, |
| | 43 | meaning to add columns to its "main" table, create other tables, add |
| | 44 | properties to its mapper, ... To do so an EntityBuilder must override the |
| | 45 | corresponding method(s). This is to ensure the different operations happen |
| | 46 | in the correct order (for example, that the table is fully created before |
| | 47 | the mapper that use it is defined). |
| | 48 | ''' |
| | 49 | |
| | 117 | ''' |
| | 118 | A specialized form of the GenericProperty to generate SQLAlchemy |
| | 119 | ``column_property``'s. |
| | 120 | |
| | 121 | It takes a single argument, which is a function (often |
| | 122 | given as an anonymous lambda) taking one argument and returning the |
| | 123 | desired (scalar-returning) SQLAlchemy ClauseElement. That function will be |
| | 124 | called whenever the entity table is completely defined, and will be given |
| | 125 | the .c attribute of the entity as argument (as a way to access the entity |
| | 126 | columns). The ColumnProperty will first wrap your ClauseElement in a label |
| | 127 | with the same name as the property, then wrap that in a column_property. |
| | 128 | |
| | 129 | .. sourcecode:: python |
| | 130 | |
| | 131 | class OrderLine(Entity): |
| | 132 | quantity = Field(Float) |
| | 133 | unit_price = Field(Numeric) |
| | 134 | price = ColumnProperty(lambda c: c.quantity * c.unit_price) |
| | 135 | |
| | 136 | Please look at the `corresponding SQLAlchemy |
| | 137 | documentation <http://www.sqlalchemy.org/docs/04/mappers.html |
| | 138 | #advdatamapping_mapper_expressions>`_ for details. |
| | 139 | ''' |
| | 140 | |