-
-
Notifications
You must be signed in to change notification settings - Fork 185
Expand file tree
/
Copy pathSQLiteConfig.php
More file actions
71 lines (58 loc) · 2.08 KB
/
Copy pathSQLiteConfig.php
File metadata and controls
71 lines (58 loc) · 2.08 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
68
69
70
71
<?php
declare(strict_types=1);
namespace Tempest\Database\Config;
use PDO;
use SensitiveParameter;
use Tempest\Database\Migrations\DatePrefixStrategy;
use Tempest\Database\Migrations\MigrationNamingStrategy;
use Tempest\Database\Tables\NamingStrategy;
use Tempest\Database\Tables\PluralizedSnakeCaseStrategy;
use UnitEnum;
final class SQLiteConfig implements DatabaseConfig
{
public string $dsn {
get => sprintf(
'sqlite:%s',
$this->path,
);
}
public ?string $username {
get => null;
}
public ?string $password {
get => null;
}
public DatabaseDialect $dialect {
get => DatabaseDialect::SQLITE;
}
public bool $usePersistentConnection {
get => $this->persistent;
}
public MigrationNamingStrategy $migrationNamingStrategy {
get => $this->migrationNaming;
}
public array $options {
get {
$options = [];
if ($this->persistent) {
$options[PDO::ATTR_PERSISTENT] = true;
}
return $options;
}
}
/**
* @param string $path Path to the SQLite database file. Use ':memory:' for an in-memory database.
* @param bool $persistent Whether to use persistent connections. Persistent connections are not closed at the end of the script and are cached for reuse when another script requests a connection using the same credentials.
* @param NamingStrategy $namingStrategy The naming strategy for database tables and columns.
* @param MigrationNamingStrategy $migrationNaming The naming strategy for migration file prefixes.
* @param string|UnitEnum|null $tag An optional tag to identify this database configuration.
*/
public function __construct(
#[SensitiveParameter]
public string $path = 'localhost',
public bool $persistent = false,
public NamingStrategy $namingStrategy = new PluralizedSnakeCaseStrategy(),
public MigrationNamingStrategy $migrationNaming = new DatePrefixStrategy(),
public string|UnitEnum|null $tag = null,
) {}
}