| | 1 | ''' |
| | 2 | ====== |
| | 3 | Fields |
| | 4 | ====== |
| | 5 | |
| | 6 | This module contains DSL statements which allow you to declare which |
| | 7 | fields (columns) your Elixir entities have. There are currently two |
| | 8 | different statements that you can use to declare fields: |
| | 9 | |
| | 10 | |
| | 11 | `has_field` |
| | 12 | ----------- |
| | 13 | The `has_field` statement allows you to define fields one at a time. |
| | 14 | |
| | 15 | The first argument is the name of the field, the second is its type, and |
| | 16 | following this any number of keyword arguments can be specified for |
| | 17 | additional behavior. The keyword arguments are passed on to the SQLAlchemy |
| | 18 | ``Column`` object. Please refer to the SQLAlchemy ``Column`` object's |
| | 19 | documentation for further detail about which keyword arguments are |
| | 20 | supported. |
| | 21 | |
| | 22 | Here is a quick example of how to use ``has_field``. |
| | 23 | |
| | 24 | :: |
| | 25 | |
| | 26 | class Person(Entity): |
| | 27 | has_field('id', Integer, primary_key=True) |
| | 28 | has_field('name', String(50)) |
| | 29 | |
| | 30 | |
| | 31 | `with_fields` |
| | 32 | ------------- |
| | 33 | The `with_fields` statement allows you to define fields all at once. |
| | 34 | |
| | 35 | Each keyword argument to this statement represents one field, which should |
| | 36 | be a `Field` object. The first argument to a Field object is its type, and |
| | 37 | following this any number of keyword arguments can be specified for |
| | 38 | additional behavior. The keyword arguments are passed on to the SQLAlchemy |
| | 39 | ``Column`` object. Please refer to the SQLAlchemy ``Column`` object's |
| | 40 | documentation for further detail about which keyword arguments are |
| | 41 | supported. |
| | 42 | |
| | 43 | Here is a quick example of how to use ``with_fields``. |
| | 44 | |
| | 45 | :: |
| | 46 | |
| | 47 | class Person(Entity): |
| | 48 | with_fields( |
| | 49 | id = Field(Integer, primary_key=True), |
| | 50 | name = Field(String(50)) |
| | 51 | ) |
| | 52 | ''' |
| | 53 | |
| 41 | | ''' |
| 42 | | Statement object for specifying a single field on an entity. |
| 43 | | |
| 44 | | The first argument is the name of the field, the second is its type, and |
| 45 | | following this any number of keyword arguments can be specified for |
| 46 | | additional behavior. The keyword arguments are passed on to the SQLAlchemy |
| 47 | | ``Column`` object. Please refer to the SQLAlchemy ``Column`` object's |
| 48 | | documentation for further detail about which keyword arguments are |
| 49 | | supported. |
| 50 | | |
| 51 | | Here is a quick example of how to use ``has_field``. |
| 52 | | |
| 53 | | :: |
| 54 | | |
| 55 | | class Person(Entity): |
| 56 | | has_field('id', Integer, primary_key=True) |
| 57 | | has_field('name', String(50)) |
| 58 | | ''' |
| 59 | | |
| 67 | | ''' |
| 68 | | Statement object for specifying all fields on an entity at once. |
| 69 | | |
| 70 | | Each keyword argument to this statement represents one field, which should |
| 71 | | be a Field object. The first argument to a Field object is its type, and |
| 72 | | following this any number of keyword arguments can be specified for |
| 73 | | additional behavior. The keyword arguments are passed on to the SQLAlchemy |
| 74 | | ``Column`` object. Please refer to the SQLAlchemy ``Column`` object's |
| 75 | | documentation for further detail about which keyword arguments are |
| 76 | | supported. |
| 77 | | |
| 78 | | Here is a quick example of how to use ``with_fields``. |
| 79 | | |
| 80 | | :: |
| 81 | | |
| 82 | | class Person(Entity): |
| 83 | | with_fields( |
| 84 | | id = Field(Integer, primary_key=True), |
| 85 | | name = Field(String(50)) |
| 86 | | ) |
| 87 | | ''' |
| 88 | | |