Skip to content

Commit

Permalink
Improved SQLite plugin (Added PDO options).
Browse files Browse the repository at this point in the history
  • Loading branch information
corpsee committed Dec 25, 2019
1 parent 4a5d7b5 commit 15efe73
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/en/plugins/sqlite.md
Expand Up @@ -11,6 +11,7 @@ Configuration
#### Build Settings options

* **path** [string] - SQLite database path.
* **options** [array, optional] - Additional PDO connection options ('PDO::ATTR_*').

#### Plugin options

Expand Down
20 changes: 18 additions & 2 deletions src/Plugin/Sqlite.php
Expand Up @@ -25,6 +25,11 @@ class Sqlite extends Plugin
*/
protected $path = '';

/**
* @var array
*/
protected $pdoOptions = [];

/**
* @return string
*/
Expand All @@ -47,6 +52,14 @@ public function __construct(Builder $builder, Build $build, array $options = [])
$this->path = $sql['path'];
}

if (!empty($buildSettings['sqlite']['path'])) {
$this->path = $buildSettings['sqlite']['path'];
}

if (!empty($buildSettings['sqlite']['options']) && \is_array($buildSettings['sqlite']['options'])) {
$this->pdoOptions = $buildSettings['sqlite']['options'];
}

if (!empty($this->options['queries']) && \is_array($this->options['queries'])) {
$this->queries = $this->options['queries'];
}
Expand All @@ -72,8 +85,11 @@ public function __construct(Builder $builder, Build $build, array $options = [])
public function execute()
{
try {
$opts = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];
$pdo = new PDO('sqlite:' . $this->path, $opts);
$pdoOptions = array_merge([
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
], $this->pdoOptions);

$pdo = new PDO('sqlite:' . $this->path, $pdoOptions);

foreach ($this->queries as $query) {
$pdo->query($query);
Expand Down

0 comments on commit 15efe73

Please sign in to comment.