Skip to content

Commit

Permalink
Flesh out get_query doc string
Browse files Browse the repository at this point in the history
  • Loading branch information
bendnorman committed Nov 13, 2024
1 parent ac0c270 commit 37457fd
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/dbcp/data_mart/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,25 @@ def _estimate_proposed_power_co2e(


def get_query(filename: str) -> str:
"""Get the query from a file."""
"""
Get the query from a file.
To avoid having to write long queries in Python, we store them in separate files
in the src/dbcp/sql_queries directory. To use them, call this function with the
filename of the query you want to use.
Args:
filename: name of the file in the sql_queries directory with the .sql extension
Returns:
the query as a string
Example:
>>> import pandas as pd
>>> from dbcp.data_mart.helpers import get_query
>>> from dbcp.helpers import get_sql_engine
>>> engine = get_sql_engine()
>>> query = get_query("get_proposed_infra_projects.sql")
>>> df = pd.read_sql(query, engine)
"""
sql_query_dir = Path(__file__).parent / "sql_queries"
full_path = sql_query_dir / filename
return full_path.read_text()

0 comments on commit 37457fd

Please sign in to comment.