Hi all,

I'd like to have a generic function that executes a given SQL query
filtering it with conditions passed as keyword args, but I do not find
a clean way to refer to the primitive columns (on the underlying
table) instead of those already bound to the select.

Given a simple select::

  >>> query = sometable.select()

and a dictionary::

  >>> args = { 'somecolname': 'avalue', 'othercolname': 1 }

I tried to implement a simple function::

  >>> def apply_filters(query, args):
  ...     for colname in args:
  ...         query = query.where(XXX(colname) == args[colname])
  ...     return query

I first tried using "query.columns[colname]" in place of the "XXX()"
stub, but that does not do the job, because it brings in a subselect.

Of course it works when I refer to the table columns, but how can I
reach them having just the query on the table? I tried inspecting the
query, that carries a "_raw_columns", or "_froms", but it does not
seem a clean approach. What am I missing?

Thanks in advance for any hint,
ciao, lele.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to