Use this file to discover all available pages before exploring further.
Data source class for populating select 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.
The column name that indicates which options are selected by default. Should contain 1 for default options and 0 otherwise. If None, no options are selected by default.If more than one option has a value of 1 in this column, then the first option with a value of 1 will be selected.
Dictionary mapping custom field names to column names. Unlike the custom_fields argument in SelectParameterOption, the dictionary value is the column name storing the custom field values instead of the custom field values themselves.
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 SelectDataSource 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 SingleSelectParameter or MultiSelectParameter.
from squirrels import parameters as p, data_sources as ds@p.SingleSelectParameter.create_from_source( name="product_category", label="Product Category", description="Select a product category")def product_category_source(): return ds.SelectDataSource( table_or_query=""" SELECT category_id AS id, category_name AS name, sort_order FROM product_categories """, id_col="id", options_col="name", order_by_col="sort_order" )
In addition, the following are some additional examples for creating a SelectDataSource object.
This example marks certain options as selected by default using a column that contains 1 or 0.
ds.SelectDataSource( table_or_query=""" SELECT region_id, region_name, (CASE WHEN is_top_choice = 'y' THEN 1 ELSE 0 END) AS is_default FROM regions """, id_col="region_id", options_col="region_name", is_default_col="is_default")
Enabling cascading effects with a parent parameter
In this example, the available product options are filtered based on the selected value of another parameter called “product_category”.
@p.SingleSelectParameter.create_from_source( name="product", label="Product", description="Select a product from the chosen category", parent_name="product_category")def product_source(): return ds.SelectDataSource( table_or_query=""" SELECT product_id, product_name, category_id, price FROM products ORDER BY product_name """, id_col="product_id", options_col="product_name", parent_id_col="category_id" # Cascades based on category selection )