SQLite::isTable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace App\Ship\Utils\Database\Driver;
4
5
use Rudra\Container\Facades\Rudra;
6
7
class SQLite
8
{
9
    public function __construct(protected $table){}
10
11
    public function up(): void
12
    {
13
        Rudra::get("DSN")->prepare("
14
            CREATE TABLE {$this->table} (
15
                id INTEGER PRIMARY KEY,
16
                name TEXT NOT NULL,
17
                created_at TEXT DEFAULT CURRENT_TIMESTAMP,
18
                updated_at TEXT DEFAULT CURRENT_TIMESTAMP
19
            );
20
        ")->execute();
21
    }
22
23
    public function isTable()
24
    {
25
        $query = Rudra::get("DSN")->query("
26
            SELECT name FROM sqlite_master WHERE type='table' AND name='{$this->table}';
27
        ");
28
29
        return $query->fetchColumn();
30
    }
31
32
    public function writeLog(string $name): void
33
    {
34
        $query = Rudra::get("DSN")->prepare("
35
            INSERT INTO {$this->table} (name)
36
            VALUES (:name)"
37
        );
38
39
        $query->execute([':name' => $name]);
40
    }
41
}
42