Use this file to discover all available pages before exploring further.
Data source class for populating date range parameter options from a database table or query.This class can be imported from the squirrels.data_sources or the squirrels module.
Either the name of the table to use, or a SQL query to run. If using a SQL query, it must start with “SELECT” (ignoring case and leading whitespaces) followed by a whitespace.The available tables are based on the source argument. If the source is SourceEnum.CONNECTION, then the SQL syntax is based on the underlying database from the connection argument. Otherwise, the SQL syntax is DuckDB SQL.
Name of the connection to use. Only used if the source is SourceEnum.CONNECTION. Connection must be defined in squirrels.yml or the connections.py file.If None, uses the default connection (specified by SQRL_CONNECTIONS__DEFAULT_NAME_USED environment variable or ‘default’).
A DateRangeDataSource object is created in the pyconfigs/parameters.py file. It must be created in a function decorated with the create_from_source factory method from DateRangeParameter.
from squirrels import parameters as p, data_sources as ds@p.DateRangeParameter.create_from_source( name="reporting_period", label="Reporting Period", description="Date range for the report")def reporting_period_source(): return ds.DateRangeDataSource( table_or_query=""" SELECT CURRENT_DATE - INTERVAL '30 days' AS default_start, CURRENT_DATE AS default_end, CURRENT_DATE - INTERVAL '1 year' AS min_date, CURRENT_DATE AS max_date """, default_start_date_col="default_start", default_end_date_col="default_end", min_date_col="min_date", max_date_col="max_date" )
In addition, the following are some additional examples for creating a DateRangeDataSource object.
Enabling cascading effects with a parent parameter
In this example, the date range is determined by the selected value of another parameter called “quarter”.
@p.DateRangeParameter.create_from_source( name="analysis_period", label="Analysis Period", description="The date range for the selected quarter", parent_name="quarter")def analysis_period_source(): return ds.DateRangeDataSource( table_or_query="quarterly_periods", default_start_date_col="quarter_start_date", default_end_date_col="quarter_end_date", min_date_col="year_start_date", max_date_col="year_end_date", parent_id_col="quarter_id" # Cascades based on quarter selection )