QueryableList¶
A list of Queryable objects
This class is a subclass of the built-in list class that allows for querying the list of objects.
-
Plankapy v1
- Board Interfaces
- Card Interfaces Card
-
Models
QueryableList - Planka
- Project Interfaces Project
- QueryableList
- User Interfaces User
| METHOD | DESCRIPTION |
|---|---|
filter_where |
Filter the list of objects by keyword arguments |
order_by |
Order the list by a key |
pop_where |
Get the first object that matches the filter |
select_where |
Select objects from the list that match a function |
take |
Take the first n objects from the list |
filter_where
¶
filter_where(**kwargs) -> QueryableList[M] | None
Filter the list of objects by keyword arguments
| PARAMETER | DESCRIPTION |
|---|---|
|
See Model for the available attributes
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
QueryableList[M] | None
|
QueryableList[M]: The objects that match the filter or None if no objects match |
Example:
>>> users = QueryableList(project.users)
>>> users
[User(id=1, name='Bob'), User(id=2, name='Alice'), User(id=3, name='Bob')]
>>> users.filter_where(name='Bob')
[User(id=1, name='Bob'), User(id=3, name='Bob')]
Source code in src/plankapy/v1/models.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | |
order_by
¶
order_by(key: str, desc: bool = False) -> QueryableList[M]
Order the list by a key
| PARAMETER | DESCRIPTION |
|---|---|
|
The key to order by
TYPE:
|
|
True to order in descending order, False otherwise
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QueryableList[M]
|
QueryableList[M]: The list of objects ordered by the key |
Example:
>>> users = QueryableList(project.users)
>>> users
[User(name='Bob'), User(name='Alice')]
>>> users = users.order_by('name')
>>> users
[User(name='Alice'), User(name='Bob')]
>>> users = users.order_by('name', desc=True)
>>> users
[User(name='Bob'), User(name='Alice')]
Source code in src/plankapy/v1/models.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
pop_where
¶
pop_where(**kwargs) -> M | None
Get the first object that matches the filter
| PARAMETER | DESCRIPTION |
|---|---|
|
Keyword arguments to filter the list by
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
M
|
The first object that matches the filter
TYPE:
|
Example:
>>> users = QueryableList(project.users)
>>> users
[User(id=1, name='Bob'), User(id=2, name='Alice'), User(id=3, name='Bob')]
>>> users.pop_where(name='Bob')
User(id=1, name='Bob')
>>> user = users.pop_where(name='Frank')
>>> user
None
Source code in src/plankapy/v1/models.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
select_where
¶
select_where(predicate: Callable[[M], bool]) -> QueryableList[M]
Select objects from the list that match a function
| PARAMETER | DESCRIPTION |
|---|---|
|
A function that takes an object and returns a boolean |
| RETURNS | DESCRIPTION |
|---|---|
QueryableList[M]
|
QueryableList[M]: The objects that match the function |
Example:
>>> users = QueryableList(project.users)
>>> users
[User(id=1, name='Bob'), User(id=2, name='Alice'), User(id=3, name='Frank')]
>>> users = users.select_where(lambda x: x.name in ('Bob', 'Alice'))
>>> users
[User(id=1, name='Bob'), User(id=2, name='Alice')]
Source code in src/plankapy/v1/models.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | |
take
¶
take(n: int) -> QueryableList[M]
Take the first n objects from the list
| PARAMETER | DESCRIPTION |
|---|---|
|
The number of objects to take
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QueryableList[M]
|
QueryableList[M]: The first n objects in the list, if n is greater than the length of the list, the list is padded with |
Example:
>>> users = QueryableList(project.users)
>>> users.take(2)
[User(name='Alice'), User(name='Bob')]
>>> users.take(3)
[User(name='Alice'), User(name='Bob'), None]
Source code in src/plankapy/v1/models.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | |