feat(store): fist stepts for implement ContributionStore for managing contributions in SQLite

This commit is contained in:
2026-07-08 06:50:56 +02:00
parent cb89a1c6b9
commit 3d2c0487b7
2 changed files with 37 additions and 1 deletions
+35
View File
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace App\Service;
use PDO;
class ContributionStore {
private PDO $pdo;
public function __construct(
private readonly string $dbPath = "%kernel.project_dir%/var/data/contributions.db",
private readonly ?int $retentionDays = null,
){
if(!is_dir(\dirname($this->dbPath))){
mkdir(\dirname($this->dbPath), 0755, recursive: true);
}
$this->pdo = new PDO('sqlite:' . $this->dbPath);
$this->pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$this->prepareSchema();
}
private function prepareSchema():void{
$this->pdo->exec('
CREATE TABLE IF NOT EXISTS contributions (
provider TEXT NOT NULL,
date TEXT NOT NULL,
count INTEGER NOT NULL CHECK (count >= 0),
PRIMARY KEY (provider, date)
) WITHOUT ROWID, STRICT
');
}
}