This module provides support for defining several options on your entities.
The ‘using_options’ DSL statement allows you to set up some additional behaviors on your model objects, including table names, ordering, and more. To specify an option, simply supply the option as a keyword argument onto the statement, as follows:
class Person(Entity):
using_options(tablename='person', order_by='name')
name = Field(Unicode(64))
The list of supported arguments are as follows:
Option Name | Description |
---|---|
metadata | Specify a custom MetaData for this entity. By default, entities uses the global camelot.core.orm.metadata. This option can also be set for all entities of a module by setting the __metadata__ attribute of that module. |
tablename | Specify a custom tablename. You can either provide a plain string or a callable. The callable will be given the entity (ie class) as argument and must return a string representing the name of the table for that entity. By default, the tablename is automatically generated: it is a concatenation of the full module-path to the entity and the entity (class) name itself. The result is lower-cased and separated by underscores (“_”), eg.: for an entity named “MyEntity” in the module “project1.model”, the generated table name will be “project1_model_myentity”. |
order_by | How to order select results. Either a string or a list of strings, composed of the field name, optionally lead by a minus (for descending order). |
session | Specify a custom contextual session for this entity. By default, entities uses the global camelot.core.orm.Session. This option takes a ScopedSession object or None. In the later case your entity will be mapped using a non-contextual mapper which requires manual session management, as seen in pure SQLAlchemy. |
For examples, please refer to the examples and unit tests.