-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Create index usage documentation
- Loading branch information
Showing
5 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# ... Continuation of the previous snippet ... | ||
|
||
from odmantic import AIOEngine | ||
|
||
engine = AIOEngine() | ||
await engine.configure_database([Product]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from odmantic import Field, Index, Model | ||
|
||
|
||
class Product(Model): | ||
name: str | ||
stock: int | ||
category: str | ||
sku: str = Field(unique=True) | ||
|
||
class Config: | ||
@staticmethod | ||
def indexes(): | ||
yield Index(Product.name, Product.stock, name="name_stock_index") | ||
yield Index(Product.name, Product.category, unique=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import pymongo | ||
|
||
from odmantic import Model | ||
|
||
|
||
class Post(Model): | ||
title: str | ||
content: str | ||
|
||
class Config: | ||
@staticmethod | ||
def indexes(): | ||
yield pymongo.IndexModel( | ||
[(+Post.title, pymongo.TEXT), (+Post.content, pymongo.TEXT)] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# ... Continuation of the previous snippet ... | ||
|
||
from odmantic import SyncEngine | ||
|
||
engine = SyncEngine() | ||
engine.configure_database([Product]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters