Save to database #13
@@ -121,7 +121,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||||||
* }
|
* }
|
||||||
* @psalm-type ServicesConfig = array{
|
* @psalm-type ServicesConfig = array{
|
||||||
* _defaults?: DefaultsType,
|
* _defaults?: DefaultsType,
|
||||||
* _instanceof?: InstanceofType,
|
* _instanceof?: array<class-string, InstanceofType>,
|
||||||
* ...<string, DefinitionType|AliasType|PrototypeType|StackType|ArgumentsType|null>
|
* ...<string, DefinitionType|AliasType|PrototypeType|StackType|ArgumentsType|null>
|
||||||
* }
|
* }
|
||||||
* @psalm-type ExtensionType = array<string, mixed>
|
* @psalm-type ExtensionType = array<string, mixed>
|
||||||
@@ -857,6 +857,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
|||||||
* http_errors?: bool|Param,
|
* http_errors?: bool|Param,
|
||||||
* expect?: mixed,
|
* expect?: mixed,
|
||||||
* ssl_key?: mixed,
|
* ssl_key?: mixed,
|
||||||
|
* force_ip_resolve?: mixed, // Default: null
|
||||||
* stream?: bool|Param,
|
* stream?: bool|Param,
|
||||||
* synchronous?: bool|Param,
|
* synchronous?: bool|Param,
|
||||||
* read_timeout?: scalar|Param|null,
|
* read_timeout?: scalar|Param|null,
|
||||||
|
|||||||
@@ -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