I use SQL Alchemy ORM and I find when I return a single column, I get the following results:
[(result,), (result_2,)] # etc...
With this set, I believe that I should do this often:
results = [r[0] for r in results]
This is not that bad, because my result sets are usually small, but if it weren’t, it could add significant overhead. Most importantly, I feel this clutters the source, and skipping this step is a fairly common mistake that I encounter.
Is there any way to avoid this extra step?
Relatively aside: this behavior of the form seems inconvenient in this case, but in another case, when my result set was, [(id, value)], it ends as follows:
[(result_1_id, result_1_val), (result_2_id, result_2_val)]
Then I can just do:
results = dict(results)
This has the advantage of making sense a useful step after returning the results.
Is this really a problem or am I just nitpick, and post-processing after getting a result set makes sense for both cases? I am sure that we can think of some other common post-processing operations to make the result set more useful in the application code. Is there high performance and convenient solutions in all directions or unsatisfactory post-processing and is simply required for different applications?
When my application can really use the objects returned by SQL Alchemy ORM, it seems very useful, but in cases where I can not or cannot, not so much. Is this just a common ORM problem in general? Am I better off not using the ORM layer in such cases?
I suppose I should show an example of the real orm queries I'm talking about:
session.query(OrmObj.column_name).all()
or
session.query(OrmObj.id_column_name, OrmObj.value_column_name).all()
Of course, in a real query there are usually some filters, etc.