-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from josnin/featureLoadSave
save chat message using tortoise ORM
- Loading branch information
Showing
12 changed files
with
169 additions
and
9 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
from tortoise import Tortoise, run_async | ||
from django.conf import settings | ||
from .tortoise_models import ChatMessage | ||
|
||
async def chat_save_message(username, room_id, message, message_type, image_caption): | ||
|
||
""" function to store chat message in sqlite """ | ||
|
||
await Tortoise.init(**settings.TORTOISE_INIT) | ||
await Tortoise.generate_schemas() | ||
|
||
await ChatMessage.create(room_id=room_id, | ||
username=username, | ||
message=message, | ||
message_type=message_type, | ||
image_caption=image_caption | ||
) | ||
|
||
await Tortoise.close_connections() |
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
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,21 @@ | ||
|
||
from tortoise import fields | ||
from tortoise.models import Model | ||
|
||
class ChatMessage(Model): | ||
""" use to store chat history message | ||
make used of tortoise ORM since its support asyncio ORM | ||
""" | ||
id = fields.IntField(pk=True) | ||
room_id = fields.IntField(null=True) | ||
username = fields.CharField(max_length=50, null=True) | ||
message = fields.TextField() | ||
message_type = fields.CharField(max_length=50, null=True) | ||
image_caption = fields.CharField(max_length=50, null=True) | ||
date_created = fields.DatetimeField(null=True, auto_now_add=True) | ||
|
||
class Meta: | ||
table = 'chat_chatmessage' | ||
|
||
def __str__(self): | ||
return self.message |
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
Binary file not shown.
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