kayak / pypika

PyPika is a python SQL query builder that exposes the full richness of the SQL language using a syntax that reflects the resulting query. PyPika excels at all sorts of SQL queries but is especially useful for data analysis.
http://pypika.readthedocs.io/en/latest/
Apache License 2.0
2.43k stars 293 forks source link

Add a `pipe` method #723

Closed wd60622 closed 5 months ago

wd60622 commented 1 year ago

Think that it could be pretty convenient to add a pipe method. Any thoughts? I can create a PR if it makes sense

from pypika import Query
from pypika.queries import QueryBuilder

def filter_to_desired_rows(query: QueryBuilder, values_to_select) -> QueryBuilder:
    ...

def aggregated_statistics(query: QueryBuilder, groups) -> QueryBuilder: 
    ...

initial_query = Query.from_("my_table")
query = (
    initial_query
    .pipe(filter_to_desired_rows, values_to_select=...)
    .pipe(aggregated_statistics, groups=...)
)