-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathSQLiteDriver.php
More file actions
67 lines (58 loc) · 1.88 KB
/
SQLiteDriver.php
File metadata and controls
67 lines (58 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* This file is part of Cycle ORM package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Cycle\Database\Driver\SQLite;
use Cycle\Database\Config\DriverConfig;
use Cycle\Database\Config\SQLiteDriverConfig;
use Cycle\Database\Driver\Driver;
use Cycle\Database\Driver\SQLite\Query\SQLiteDeleteQuery;
use Cycle\Database\Driver\SQLite\Query\SQLiteSelectQuery;
use Cycle\Database\Driver\SQLite\Query\SQLiteUpdateQuery;
use Cycle\Database\Exception\StatementException;
use Cycle\Database\Query\InsertQuery;
use Cycle\Database\Query\QueryBuilder;
/**
* @property SQLiteDriverConfig $config
*/
class SQLiteDriver extends Driver
{
/**
* @param SQLiteDriverConfig $config
*/
public static function create(DriverConfig $config): static
{
return new static(
$config,
new SQLiteHandler(),
new SQLiteCompiler('""'),
new QueryBuilder(
new SQLiteSelectQuery(),
new InsertQuery(),
new SQLiteUpdateQuery(),
new SQLiteDeleteQuery(),
),
);
}
public function getType(): string
{
return 'SQLite';
}
protected function mapException(\Throwable $exception, string $query): StatementException
{
if ((int) $exception->getCode() === 23000) {
return new StatementException\ConstrainException($exception, $query);
}
return (new StatementException($exception, $query))->setMessage(
message: $this->config->connection->formatExceptionMessage($exception->getMessage()),
);
}
protected function setIsolationLevel(string $level): void
{
$this->logger?->alert("Transaction isolation level is not fully supported by SQLite ({$level})");
}
}