初始化仓库及v1.0.0提交
This commit is contained in:
33
app/Models/Message.php
Normal file
33
app/Models/Message.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Config\Database;
|
||||
|
||||
class Message
|
||||
{
|
||||
public static function findBySessionId(int $sessionId): array
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$stmt = $db->prepare('SELECT * FROM messages WHERE session_id = :session_id ORDER BY created_at ASC');
|
||||
$stmt->execute(['session_id' => $sessionId]);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
public static function create(array $data): array
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$stmt = $db->prepare('INSERT INTO messages (session_id, role, content, file_info, thinking_content) VALUES (:session_id, :role, :content, :file_info, :thinking_content)');
|
||||
$stmt->execute([
|
||||
'session_id' => $data['session_id'],
|
||||
'role' => $data['role'],
|
||||
'content' => $data['content'],
|
||||
'file_info' => isset($data['file_info']) ? json_encode($data['file_info']) : null,
|
||||
'thinking_content' => $data['thinking_content'] ?? null,
|
||||
]);
|
||||
|
||||
$stmt = $db->prepare('SELECT * FROM messages WHERE id = :id');
|
||||
$stmt->execute(['id' => (int) $db->lastInsertId()]);
|
||||
return $stmt->fetch();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user