database changes

This commit is contained in:
2026-02-12 15:09:06 +03:00
parent c5448b14f6
commit 022cf4ba06
18 changed files with 202 additions and 223 deletions

View File

@@ -9,7 +9,7 @@ import (
"go.mongodb.org/mongo-driver/v2/bson"
)
func GetGptChatHistory(db *laniakea.DatabaseContext, chatId string) ([]*AiChatMessage, error) {
func GetGptChatHistory(db *laniakea.DatabaseContext, chatId string) ([]AiChatMessage, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := database.GetMongoCollection(db, "gpt_chat_messages")
@@ -17,7 +17,7 @@ func GetGptChatHistory(db *laniakea.DatabaseContext, chatId string) ([]*AiChatMe
if err != nil {
return nil, err
}
result := make([]*AiChatMessage, 0)
result := make([]AiChatMessage, 0)
err = cursor.All(ctx, &result)
return result, err
}

View File

@@ -22,12 +22,12 @@ type CodeEntry struct {
TotalUsages uint `bson:"totalUsages"`
}
func FindCode(db *laniakea.DatabaseContext, code string) (*CodeEntry, error) {
func FindCode(db *laniakea.DatabaseContext, code string) (CodeEntry, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
collection := database.GetMongoCollection(db, "codes")
res := collection.FindOne(ctx, bson.M{"code": code})
entry := new(CodeEntry)
entry := CodeEntry{}
err := res.Decode(entry)
return entry, err
}

View File

@@ -20,14 +20,14 @@ type ConsoleLogEntry struct {
TimeStamp int64 `bson:"timeStamp" json:"time_stamp"`
}
func WriteConsoleLog(db *laniakea.DatabaseContext, e *ConsoleLogEntry) error {
func WriteConsoleLog(db *laniakea.DatabaseContext, e ConsoleLogEntry) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := database.GetMongoCollection(db, "logs")
_, err := col.InsertOne(ctx, e)
return err
}
func GetConsoleLogs(db *laniakea.DatabaseContext) (extypes.Slice[*ConsoleLogEntry], error) {
func GetConsoleLogs(db *laniakea.DatabaseContext) ([]ConsoleLogEntry, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := database.GetMongoCollection(db, "logs")
@@ -39,7 +39,7 @@ func GetConsoleLogs(db *laniakea.DatabaseContext) (extypes.Slice[*ConsoleLogEntr
return nil, err
}
defer cursor.Close(ctx)
result := make(extypes.Slice[*ConsoleLogEntry], 0)
result := make([]ConsoleLogEntry, 0)
err = cursor.All(ctx, &result)
return result, nil
}

View File

@@ -17,7 +17,7 @@ type AiChatMessage struct {
Index int `bson:"index"`
}
func GetRPChatHistory(db *laniakea.DatabaseContext, chatId string) ([]*AiChatMessage, error) {
func GetRPChatHistory(db *laniakea.DatabaseContext, chatId string) ([]AiChatMessage, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := database.GetMongoCollection(db, "rp_chat_messages")
@@ -25,7 +25,7 @@ func GetRPChatHistory(db *laniakea.DatabaseContext, chatId string) ([]*AiChatMes
if err != nil {
return nil, err
}
result := make([]*AiChatMessage, 0)
result := make([]AiChatMessage, 0)
err = cursor.All(ctx, &result)
return result, err
}
@@ -47,7 +47,7 @@ func GetRPChatHistorySize(db *laniakea.DatabaseContext, chatId string) (int64, e
col := database.GetMongoCollection(db, "rp_chat_messages")
return col.CountDocuments(ctx, bson.M{"chatId": chatId})
}
func DeleteRPChatEntry(db *laniakea.DatabaseContext, entry *AiChatMessage) error {
func DeleteRPChatEntry(db *laniakea.DatabaseContext, entry AiChatMessage) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := database.GetMongoCollection(db, "rp_chat_messages")