summaryrefslogtreecommitdiff
path: root/storage
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2024-11-20 06:51:40 +0300
committerGrail Finder <wohilas@gmail.com>2024-11-20 06:51:40 +0300
commitaaf056663628f15bb6e4f23c899b6fd31bac5bf7 (patch)
treea0129fbb531e31d1a9d6465549a44b823906aaae /storage
parentf32375488f5127c910021f627d83e017c5c7a10f (diff)
Enha: db chat management
Diffstat (limited to 'storage')
-rw-r--r--storage/storage.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/storage/storage.go b/storage/storage.go
index 11cbb4a..43162c8 100644
--- a/storage/storage.go
+++ b/storage/storage.go
@@ -11,6 +11,7 @@ import (
type ChatHistory interface {
ListChats() ([]models.Chat, error)
GetChatByID(id uint32) (*models.Chat, error)
+ GetLastChat() (*models.Chat, error)
UpsertChat(chat *models.Chat) (*models.Chat, error)
RemoveChat(id uint32) error
}
@@ -31,6 +32,12 @@ func (p ProviderSQL) GetChatByID(id uint32) (*models.Chat, error) {
return &resp, err
}
+func (p ProviderSQL) GetLastChat() (*models.Chat, error) {
+ resp := models.Chat{}
+ err := p.db.Get(&resp, "SELECT * FROM chat ORDER BY updated_at DESC LIMIT 1")
+ return &resp, err
+}
+
func (p ProviderSQL) UpsertChat(chat *models.Chat) (*models.Chat, error) {
// Prepare the SQL statement
query := `