odmantic.index
Source code in odmantic/index.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
__init__(*fields, unique=False, name=None)
¶
Declare an ODM index in the Model.Config.indexes generator.
Example usage:
from odmantic import Model, Index
from odmantic.query import desc
class Player(Model):
name: str
score: int
model_config = {
"indexes": lambda: [Index(Player.name, desc(Player.score))],
}
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*fields |
Any | SortExpression | str
|
fields to build the index with |
()
|
unique |
bool
|
build a unique index |
False
|
name |
Optional[str]
|
specify an optional custom index name |
None
|
Source code in odmantic/index.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|