def create_function_query(session, model, functions):
 processed = []
 for function in functions:
  if ('name' not in function):
   raise KeyError('Missing `name` key in function object')
  if ('field' not in function):
   raise KeyError('Missing `field` key in function object')
  (funcname, fieldname) = (function['name'], function['field'])
  funcobj = getattr(func, funcname)
  try:
   field = getattr(model, fieldname)
  except AttributeError as exception:
   exception.field = fieldname
   raise exception
  processed.append(funcobj(field))
 return session.query(*processed)

def create_function_query ( session , model , functions ) : processed = [ ] for function in functions : if ( 'name' not in function ) : raise KeyError ( 'Missing `name` key in function object' ) if ( 'field' not in function ) : raise KeyError ( 'Missing `field` key in function object' ) ( funcname , fieldname ) = ( function [ 'name' ] , function [ 'field' ] ) funcobj = getattr ( func , funcname ) try : field = getattr ( model , fieldname ) except AttributeError as exception : exception . field = fieldname raise exception processed . append ( funcobj ( field ) ) return session . query ( * processed )
creates a sqlalchemy query representing the given sqlalchemy functions .