Index
Bases: Record
, Generic[R]
An Index is a data structure that allows for fast lookup of records by their properties. It is used internally by the Record class and once created, is automatically updated when records are created or updated.
It is not recommended using the Index class directly, but rather through the where_eq
method of the Record
class.
Example
MyRecord.where_eq(foo='bar')
MyRecord
has an index on the property foo
, this will return all records of type MyRecord
where foo
is
equal to 'bar'
.
Creates a new index given a record_type and a single or multiple properties to index on.
Example
Index(MyRecord, 'foo')
This will create an index named 'MyRecord.foo'
, which is stored in the MyRecord
class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record_type |
Type[R]
|
The record_type to index. |
required |
on |
Union[str, List[str], Tuple[str]]
|
The properties to index on. Can be a single property or a list/tuple of properties. |
required |
Source code in aars/core.py
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
|
add_record(obj: R)
Adds a record to the index.
Source code in aars/core.py
558 559 560 561 562 563 564 565 566 567 568 569 |
|
lookup(query: IndexQuery) -> AsyncIterator[R]
Fetches records with given values for the indexed properties.
Example
index = Index(MyRecord, 'foo')
index_query = IndexQuery(MyRecord, **{'foo': 'bar'})
index.lookup(index_query)
MyRecord
where foo
is equal to 'bar'
.
This is an anti-pattern, as the IndexQuery
should be created by calling MyRecord.where_eq(foo='bar')
instead.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query |
IndexQuery
|
The query to execute. |
required |
Returns:
Type | Description |
---|---|
AsyncIterator[R]
|
An async iterator over the records. |
Source code in aars/core.py
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
|
regenerate(items: List[R])
Regenerates the index with given items.
Source code in aars/core.py
580 581 582 583 584 |
|
remove_record(obj: R)
Removes a record from the index, i.e. when it is forgotten.
Source code in aars/core.py
571 572 573 574 575 576 577 578 |
|