Query the database and return a list of model instances. This method builds and executes a SQL query based on the provided parameters and class configuration, then converts the query results into model instances. Args: fields: Optional list of fields to select.
(
cls: Type[TClickhouseModel],
*,
fields: Optional[SelectFields] = None,
filters: Optional[FilterFields] = None,
search: Optional[str] = None,
order_by: Optional[str] = None,
offset: Optional[int] = None,
limit: Optional[int] = None,
)
| 306 | |
| 307 | @classmethod |
| 308 | async def select( |
| 309 | cls: Type[TClickhouseModel], |
| 310 | *, |
| 311 | fields: Optional[SelectFields] = None, |
| 312 | filters: Optional[FilterFields] = None, |
| 313 | search: Optional[str] = None, |
| 314 | order_by: Optional[str] = None, |
| 315 | offset: Optional[int] = None, |
| 316 | limit: Optional[int] = None, |
| 317 | ) -> list[TClickhouseModel]: |
| 318 | """Query the database and return a list of model instances. |
| 319 | |
| 320 | This method builds and executes a SQL query based on the provided parameters and |
| 321 | class configuration, then converts the query results into model instances. |
| 322 | |
| 323 | Args: |
| 324 | fields: Optional list of fields to select. Defaults to cls.selectable_fields. |
| 325 | Example: ["id", "name", "email"] |
| 326 | filters: Optional dictionary of filters to apply. Keys must be defined in |
| 327 | cls.filterable_fields to be effective. |
| 328 | Example: {"project_id": "123", "start_time": "2023-01-01"} |
| 329 | search: Optional search string to apply to all searchable fields configured in |
| 330 | cls.searchable_fields. For LIKE/ILIKE searches, wildcards (%) |
| 331 | are automatically added if not present. |
| 332 | Example: "authentication" will search all configured fields for "authentication" |
| 333 | order_by: Optional ORDER BY clause (without the "ORDER BY" prefix). |
| 334 | Example: "created_at DESC" |
| 335 | offset: Optional OFFSET value for pagination. |
| 336 | limit: Optional LIMIT value to restrict the number of results. |
| 337 | |
| 338 | Returns: |
| 339 | List[TClickhouseModel]: A list of model instances of the exact calling class type, |
| 340 | with each instance created from a row in the query results. The return type is |
| 341 | properly typed using generics to preserve the concrete subclass type. |
| 342 | |
| 343 | Example: |
| 344 | ```python |
| 345 | # Get last 10 traces for a specific project |
| 346 | traces = await TraceModel.select( |
| 347 | filters={"project_id": "abc123"}, |
| 348 | order_by="timestamp DESC", |
| 349 | limit=10 |
| 350 | ) |
| 351 | |
| 352 | # Search for traces with spans containing "authentication" |
| 353 | traces = await TraceModel.select( |
| 354 | filters={"project_id": "abc123"}, |
| 355 | search="authentication", |
| 356 | limit=10 |
| 357 | ) |
| 358 | |
| 359 | # Access model properties on the results |
| 360 | for trace in traces: |
| 361 | print(f"Trace {trace.trace_id}: {trace.total_tokens} tokens") |
| 362 | ``` |
| 363 | """ |
| 364 | query, params = cls._get_select_query( |
| 365 | fields=fields, |
no test coverage detected