sqloxide icon indicating copy to clipboard operation
sqloxide copied to clipboard

AST edit for container type

Open psukys opened this issue 4 months ago • 4 comments

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)

psukys avatar Oct 24 '24 06:10 psukys