feat(store): fist stepts for implement ContributionStore for managing contributions in SQLite
This commit is contained in:
@@ -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
|
||||
');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user