Key Selector
This module provides the KeySelector class, which inherits from Select and provides methods for filtering keys based on certain criteria.
The KeySelector class has methods to filter keys by event ID, key, and language. Each method returns a new instance of KeySelector with the applied filters.
The KeySelector class is initialized with a class object and a boolean indicating if it is being used with SQLite. The class object must be a subclass of BaseKey.
- Classes:
KeySelector: A class used to select keys meeting certain criteria.
Example
key_selector = KeySelector(MyKeyClass) filtered_by_event = key_selector.by_event(1) filtered_by_key = key_selector.by_key(‘mykey’) filtered_by_language = key_selector.by_language(‘English’)
This allows for flexible and powerful querying of keys in a codebase.
- class loglan_core.addons.key_selector.KeySelector(model=<class 'loglan_core.key.BaseKey'>, is_sqlite=False, case_sensitive=False, disable_model_check=False)[source]
Bases:
BaseSelectorA class used to select keys meeting certain criteria.
- is_sqlite
If SQLite is being used. Defaults to False.
- Type:
bool
- case_sensitive
If the queries should be case-sensitive.
- Type:
bool
- disable_model_check
If the model check is disabled during initialization.
- Type:
bool
- __init__(model=<class 'loglan_core.key.BaseKey'>, is_sqlite=False, case_sensitive=False, disable_model_check=False)[source]
Initializes the KeySelector object with the provided parameters.
- Parameters:
model (Type[BaseKey]) – The class to be used as the base key. Must be a subclass of BaseKey.
is_sqlite (bool) – If SQLite is being used. Defaults to False.
case_sensitive (bool) – If the queries should be case-sensitive.
disable_model_check (bool) – If the model check is disabled during initialization.
- Raises:
ValueError – If the provided model is not a subclass of BaseKey.
- by_event(event_id=None)[source]
Filters the keys by the given event ID.
- Parameters:
event_id (int | None) – The identifier of the event to filter by. If None, no event filtering is applied.
- Returns:
The filtered KeySelector instance.
- Return type:
- by_key(key)[source]
Filters the keys by the given key.
- Parameters:
key (str) – The key to filter by.
- Returns:
The filtered KeySelector instance.
- Return type:
- by_language(language=None)[source]
Filters the keys by the given language.
- Parameters:
language (str | None) – The language to filter by. If None, no language filtering is applied.
- Returns:
The filtered KeySelector instance.
- Return type:
- by_word_id(word_id, distinct=False)[source]
Filters the keys by the given word ID.
- Parameters:
word_id (int) – The identifier of the word to filter by.
distinct (bool) – If the query should be distinct. Defaults to False.
- Returns:
The filtered KeySelector instance.
- Return type:
Keep in mind that duplicated keys from related definitions will be counted with
`.count()`but excluded from`.all()`request