Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use LazyTbl without an engine? #424

Open
randy3k opened this issue May 5, 2022 · 2 comments
Open

Use LazyTbl without an engine? #424

randy3k opened this issue May 5, 2022 · 2 comments

Comments

@randy3k
Copy link

randy3k commented May 5, 2022

Could we use LazyTbl without specifying an engine? I just want to use siuba to generate SQL query, similar to what pypika does.

@machow
Copy link
Owner

machow commented May 5, 2022

Hey--does this approach (using a mock engine) work?

from siuba.sql.utils import mock_sqlalchemy_engine
from siuba.sql import LazyTbl as _LazyTbl
cars_sql = _LazyTbl(
        mock_sqlalchemy_engine("postgresql"),
        "cars",
        ["cyl", "mpg", "hp"]
        )

# example showing the query
from siuba import _, mutate, show_query

q = cars_sql >> mutate(avg = _.hp - _.hp.mean()) >> show_query()

outputs:

SELECT cars.cyl, cars.mpg, cars.hp, cars.hp - avg(cars.hp) OVER () AS avg
FROM cars

Currently, show_query just prints the SQL and returns a LazyTbl, but I can add the equivalent of dbplyr's db_sql_render (or add an argument to show_query to return the generated string)

@susannvorberg
Copy link

I would also be interested in getting the SQL query and vote for an argument to show_query() to return the generated string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants