Core statements¶
-
class
metapensiero.sqlalchemy.proxy.core.
ProxiedQuery
(query, metadata=None)¶ Specialize
base.ProxiedBase
to deal with SQLAlchemy core statements.An instance of this class wraps a standard SQLAlchemy query, either a selectable or an updateable. When called it applies the arguments filtering or changing the original query, calling it and returning the results set.
-
__init__
(query, metadata=None)¶ Initialize the proxy.
Parameters: - query – the SA statement (currently only
SELECT
s) - metadata – 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.
- query – the SA statement (currently only
-
filterQueryWithArgs
(session, conditions, args)¶ Apply filter conditions to the query.
conditions, if specified, is a list of SQLAlchemy expressions to be applied as filters to the query, using the
AND
operator.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 selected columns.
-
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.
Beware, this implements a rather simplicistic heuristic such that it identifies only the primary key of the first table involved in the query: in other words, it assumes that the primary key fields come as early as possible in the list of columns.
-
getResult
(session, query, asdict)¶ Execute the query in the given session, returning the result.
If asdict is
True
return a list of dictionaries, one for each row, otherwise return the SQLAlchemy resultset (as returned by.fetchall()
).
-