sqloxide
sqloxide copied to clipboard
AST edit for container type
In example, as I understood, edits are applied only on textual/string data, can this be enhanced to other built-in types, such as lists? For example:
import sqloxide
query = """
with my_cte2 as (
select 1
),
my_cte1 as (
select 2
)
select *
from my_cte1
join my_cte2
"""
def mutator(node):
if "cte_tables" in node.keys():
node["cte_tables"] = list(sorted(node["cte_tables"], key=lambda x: x["alias"]["name"]))
return node
ast = sqloxide.parse_sql(query, dialect="postgres")
sqloxide.mutate_expressions(ast, mutator)