I've run into a few cases where I need to abandon the ORM and run
`session.execute()`
Usually... I'm doing a bunch of nested queries and only pull out a `count`
or a few rows of 1-2 id columns. Writing in pure sql is faster (for me),
gives me more control, and avoids having to do a baked-query.
Here's where my concern comes in -- `execute` returns a ResultProxy, and
the first element is a RowProxy
so to get a count, I'm doing something like this:
result = dbSession.execute(foo)
result = list(result)[0][0]
This is... ugly. and then I have to handle the logic to ensure I got a
correct record back.
I'm wondering if anyone has figured a more elegant way to handle queries
like this.
The best i can think of is using an shared function:
result = extract_result_one(result)
result = extract_result_first(result)
result = extract_result_count(result)
and then just raise an appropriate error if there are too many (or no) rows.
anyone have a better idea?
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.