pretty-print sql
The idea is that: * each SQL important operator/keyword start on newline * nesting is made visible by identation (like in python)
some details: * compound ops - union/except/etc - are treated with somewhat medium indent - not inside but not outside either * SELECT has no newline prepended * don't know if INSERT/UPDATE/DELETE would need identation except in their WHERE clause
Comments (8)
-
repo owner -
Account Deleted - attached prettysql.2.diff
(original author: sdobrev) hmmm - keeping track of recursion level in the visitor.. How about moving it into some .enter/leave() methods of visitor? and either havbing them empty in the root Visitor, or their usage again put in try: except ?
-
Account Deleted - attached select_nice_echo.diff
Here a patch for 0.4.beta1. Much simpler, uses the depth of self.stack as indentlevel.
-
Account Deleted - attached select.echo.py
Here how overall code looks like, and how the resulting multilevel echo looks like
-
repo owner the tabbing looks a little deep to me. also if/when we integrate this, we have to go through and ensure that all the tests which test for specific SQL are normalizing whitespace. for the main unit tests this is probably already the case but theres also two doctests in doc/build.
-
Account Deleted too deep: you mean 4 spaces too much? may put that 4 as class or module variable; then people can set it to their preferred tab-width, or 0 to get all flush-to-left-aligned. or maybe ask the group how much they like the result? -- svil
-
repo owner - changed status to wontfix
sorry, I think logging filters (user-defined) are a better approach here....closing for now
-
repo owner - removed milestone
Removing milestone: 0.4.xx (automated comment)
- Log in to comment
the "indentlevel" setting in the accept_visitor breaks encapsulation. the object being visited should make no assumptions about its visitor, all indent counting should be in the compiler itself.