This module complements the sqlalchemy orm module, it contains the global Session factory to create session objects. Whenever a session is needed it can be constructed with a call of Session
session = Session
when using Elixir, Elixir needs to be told to use this session factory
elixir.session = Session
when using Declarative, this module contains an Entity class that can be used as a declarative_base and has some classes that mimic Elixir behavior
A declarative base class that adds some methods that used to be available in Elixir
Update a mapped class with data from a JSON-style nested dict/list structure.
Return the instance of this class based on the given identifier, or None if not found. This is equivalent to: session.query(MyClass).get(...)
Returns the first instance of this class matching the given criteria. This is equivalent to: session.query(MyClass).filter_by(...).first()
Generate a JSON-style nested dict/list structure from an object.
Subclass of sqlalchmey.ext.declarative.DeclarativeMeta. This metaclass processes the Property and ClassMutator objects.
Represents the definition of a ‘field’ on an entity.
This class represents a column on the table where the entity is stored.
Generic catch-all class to wrap an SQLAlchemy property.
class OrderLine(Entity):
quantity = Field(Float)
unit_price = Field(Numeric)
price = GenericProperty(lambda c: column_property(
(c.quantity * c.unit_price).label('price')))
A specialized form of the GenericProperty to generate SQLAlchemy column_property‘s.
It takes a function (often given as an anonymous lambda) as its first argument. Other arguments and keyword arguments are forwarded to the column_property construct. That first-argument function must accept exactly one argument and must return the desired (scalar-returning) SQLAlchemy ClauseElement.
The function will be called whenever the entity table is completely defined, and will be given the .c attribute of the table of the entity as argument (as a way to access the entity columns). The ColumnProperty will first wrap your ClauseElement in an “empty” label (ie it will be labelled automatically during queries), then wrap that in a column_property.
class OrderLine(Entity):
quantity = Field(Float)
unit_price = Field(Numeric)
price = ColumnProperty(lambda c: c.quantity * c.unit_price,
deferred=True)
Please look at the corresponding SQLAlchemy documentation for details.
Generates a many to one relationship.
Find all primary keys on the target and create foreign keys on the source accordingly.
Generates a one to many relationship.
This statement its sole reason of existence is to keep existing Elixir model definitions working. Do not use it when writing new code, instead use Declarative directly.