Switching from NetBean to Medoo

This commit is contained in:
julien
2026-03-09 00:33:30 +01:00
parent 8d7aba5447
commit 001dc204af
10 changed files with 146 additions and 359 deletions

View File

@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace App\Repositories;
use Medoo\Medoo;
/**
* Repository pour "post" basé sur Medoo.
* Retourne et consomme des tableaux associatifs.
*/
class PostRepositoryMedoo
{
private Medoo $db;
public function __construct(Medoo $db)
{
$this->db = $db;
}
public function allDesc(): array
{
return $this->db->select('post', ['id', 'title', 'content'], ['ORDER' => ['id' => 'DESC']]);
}
public function find(int $id): ?array
{
$row = $this->db->get('post', ['id', 'title', 'content'], ['id' => $id]);
return $row === null ? null : $row;
}
public function create(array $data): int
{
$this->db->insert('post', [
'title' => $data['title'] ?? '',
'content' => $data['content'] ?? '',
]);
return (int)$this->db->id();
}
public function update(int $id, array $data): void
{
$this->db->update('post', [
'title' => $data['title'] ?? '',
'content' => $data['content'] ?? '',
], ['id' => $id]);
}
public function delete(int $id): void
{
$this->db->delete('post', ['id' => $id]);
}
}