ORM queries

class metapensiero.sqlalchemy.proxy.orm.ProxiedEntity(entity, fields=None, metadata=None)

Specialize base.ProxiedBase to deal with SQLAlchemy ORM queries.

An instance of this class wraps an entity, that is a SQLAlchemy mapped class. When called it builds a query, eventually applying filters specified by the arguments and returning the results set.

__init__(entity, fields=None, metadata=None)

Initialize the proxy.

Parameters:
  • entity – a SQLAlchemy mapped class, or an ORM query
  • fields – a list of field names
  • metadata – a dictionary

When fields is not specified, it is automatically computed from the list of columns of the mapped table, extended with the properties defined on the entity itself. Otherwise, it is the sequence of attributes that will be extracted from each instance to build the list of dictionaries of the result.

metadata is a dictionary, containing extra information about fields: when possibile, these info are collected from the SA definition (each field has a info dictionary); for computed fields when the returned value does not correspond to a physical field, or simply to override/expand such information on a per query basis, you may pass an additional dictionary of values, keyed on the field name.

filterQueryWithArgs(session, conditions, args)

Construct a filtered query on the wrapped entity.

Parameters:
  • session – an SQLAlchemy Session
  • conditions – a list of SQLAlchemy expressions
  • args – a dictionary
Return type:

an ORM query

The query gets then massaged by filters.apply_filters(), further filtered and modified as specified by the args dictionary.

Return the altered query.

getColumns(query)

Return the columns specified by self.fields.

getCount(session, query)

Execute a query to get the actual count of matching records.

getMetadata(query, countslot, resultslot, successslot)

Augment superclass implementation with primary key name.

getResult(session, query, asdict)

Execute the query in the given session, returning the result.