-
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tsung-Ju Lii
committed
Aug 24, 2023
1 parent
d7c3207
commit 5da8c72
Showing
4 changed files
with
42 additions
and
28 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...ate/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_beanie/dao/__init__.py
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 @@ | ||
"""DAO classes.""" |
39 changes: 39 additions & 0 deletions
39
...te/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_beanie/dao/dummy_dao.py
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,39 @@ | ||
from typing import List, Optional | ||
|
||
from {{cookiecutter.project_name}}.db.models.dummy_model import DummyModel | ||
|
||
|
||
class DummyDAO: | ||
"""Class for accessing dummy table.""" | ||
|
||
async def create_dummy_model(self, name: str) -> None: | ||
""" | ||
Add single dummy to session. | ||
:param name: name of a dummy. | ||
""" | ||
await DummyModel.insert_one(DummyModel(name=name)) | ||
|
||
async def get_all_dummies(self, limit: int, offset: int) -> List[DummyModel]: | ||
""" | ||
Get all dummy models with limit/offset pagination. | ||
:param limit: limit of dummies. | ||
:param offset: offset of dummies. | ||
:return: stream of dummies. | ||
""" | ||
return await DummyModel.find_all(skip=offset, limit=limit).to_list() | ||
|
||
async def filter( | ||
self, | ||
name: Optional[str] = None | ||
) -> List[DummyModel]: | ||
""" | ||
Get specific dummy model. | ||
:param name: name of dummy instance. | ||
:return: dummy models. | ||
""" | ||
if name is None: | ||
return [] | ||
return await DummyModel.find(DummyModel.name == name).to_list() |
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
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