this is somewhat frequent question, lookup the group in the past if
anyone has something usable.
maybe something like
query(cls).filter(
or_(*[column == value for column in alternatives] ))
if many values, use column.in_(values) instead of ==
alternatives can come from yourtable.columns or
classmapper( yourclas).iterate_properties.
things to check:
- types, e.g. comparing strings and integers may fail or succeed
- primary_key = set( c.key for c in class_mapper( cls).primary_key )
- relations/references maybe also be checked via .has/.any
e.g. references = [ p for p in
classmapper(yourclass).iterate_properties
if (p not in primary_key
and (not isinstance( p, PropertyLoader) #not a relation
or p.use_list == False )) #or a singular reference
]
these above are just for example, do your own filtering
ciao
svil
On Tuesday 14 October 2008 20:26:16 Jorge Vargas wrote:
> Hi,
>
> I'm trying to implement a "simple search" field in my application
> and I was wondering which will be the best way to implement it on
> SQLAlchemy. I have googled around and found several partial
> solutions but none of them convince me of being the right way.
>
> My use case is the following. I got a textfield search box which
> will post a set of words, my webapp is to take those words and do a
> query in *any* field of the corresponding table, and it is to say
> within just one table. For example I got a User class that has
> first_name,last_name,address_fields. And I ran a query for "John
> Thompson", that will bring me back a list of user objects where any
> of the following is valid, "John" in first_name, "John" in
> last_name, "John" in address, "Thompson" in first_name, "Thompson"
> in last_name, "Thompson" in address_field.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---