Enha: db chat management
This commit is contained in:
@@ -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 := `
|
||||
|
||||
Reference in New Issue
Block a user