Skip to content
Permalink
Browse files

Improved SQLite plugin (Added PDO options).

  • Loading branch information
corpsee committed Dec 25, 2019
1 parent 4a5d7b5 commit 15efe73fbe59b965ed5ddd9c938b465a17cc2b3f
Showing with 19 additions and 2 deletions.
  1. +1 −0 docs/en/plugins/sqlite.md
  2. +18 −2 src/Plugin/Sqlite.php
@@ -11,6 +11,7 @@ Configuration
#### Build Settings options

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

#### Plugin options

@@ -25,6 +25,11 @@ class Sqlite extends Plugin
*/
protected $path = '';

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

/**
* @return string
*/
@@ -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'];
}
@@ -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);

0 comments on commit 15efe73

Please sign in to comment.
You can’t perform that action at this time.