Update crosstab to support more types of input #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I needed
crosstab
support for generating graphs in a SQL Alchemy ORM project, so I thought I'd share the code.Major changes:
crosstab
.Column
s in the Return Def. This allows me to use the same crosstab code multiple times in the sameSession
without having to generate a new table name. Generating a new table for each request could add up over the course of days or months in a web server (ie, memory leak). Depends on details.AS
clause. Generic selectables andQuery
objects don't have a name, and I couldn't find a SQLA way to generate a unique name, so I removed the return value name (in theAS
clause) from the compilation. Works on 9.6, and works in CI, so I'm not sure why the docs consistently include a name. Being able to get a compiled name from.alias
would be a great way to make this work, if I was smart enough to figure it out. I tried various manipulations ofAlias.name
, but there's some extra machinery going on there I don't understand.Query
objects instmt
andcategories
arguments. For ORM projects, that's a major source of cleaner code. Still not perfect, but I think the tests show a pretty good way to use the new code.Less major changes:
requirements.txt
for better dependency control. Just makes life easier.envfile.txt
in tests. Because Windows doesn't really handle environment variables well, and a file ignored by git is not the worst place to stick a DB Connection String.