From 6be9d5576ad0ae8c6335187b896681002c98878d Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Mon, 4 Oct 2021 10:37:11 +0200 Subject: [PATCH 1/2] Improve documentation --- README.md | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b71a95b..995ce88 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ so you can query your data without blocking your main application. and does not get in your way. Future or custom commands and events require no changes to be supported. * **Good test coverage** - - Comes with an automated tests suite and is regularly tested against actual SQLite databases in the wild. + Comes with an automated test suite and is regularly tested against actual SQLite databases in the wild. **Table of contents** @@ -64,6 +64,10 @@ existing SQLite database file (or automatically create it on first run) and then `INSERT` a new record to the database: ```php +openLazy('users.db'); @@ -164,11 +168,11 @@ the underlying database is ready. Additionally, it will only keep this underlying database in an "idle" state for 60s by default and will automatically end the underlying database when it is no longer needed. -From a consumer side this means that you can start sending queries to the +From a consumer side, this means that you can start sending queries to the database right away while the underlying database process may still be outstanding. Because creating this underlying process may take some -time, it will enqueue all oustanding commands and will ensure that all -commands will be executed in correct order once the database is ready. +time, it will enqueue all outstanding commands and will ensure that all +commands will be executed in the correct order once the database is ready. In other words, this "virtual" database behaves just like a "real" database as described in the `DatabaseInterface` and frees you from having to deal with its async resolution. @@ -213,7 +217,7 @@ $db = $factory->openLazy('users.db', SQLITE3_OPEN_READONLY); By default, this method will keep "idle" connection open for 60s and will then end the underlying connection. The next request after an "idle" connection ended will automatically create a new underlying connection. -This ensure you always get a "fresh" connection and as such should not be +This ensures you always get a "fresh" connection and as such should not be confused with a "keepalive" or "heartbeat" mechanism, as this will not actively try to probe the connection. You can explicitly pass a custom idle timeout value in seconds (or use a negative number to not apply a @@ -355,7 +359,7 @@ The `close(): void` method can be used to force-close the connection. Unlike the `quit()` method, this method will immediately force-close the -connection and reject all oustanding commands. +connection and reject all outstanding commands. ```php $db->close(); @@ -400,7 +404,7 @@ See also the [`close()`](#close) method. ## Install -The recommended way to install this library is [through Composer](https://getcomposer.org). +The recommended way to install this library is [through Composer](https://getcomposer.org/). [New to Composer?](https://getcomposer.org/doc/00-intro.md) This project follows [SemVer](https://semver.org/). @@ -427,7 +431,7 @@ $ sudo apt install php-sqlite3 ## Tests To run the test suite, you first need to clone this repo and then install all -dependencies [through Composer](https://getcomposer.org): +dependencies [through Composer](https://getcomposer.org/): ```bash $ composer install @@ -436,7 +440,7 @@ $ composer install To run the test suite, go to the project root and run: ```bash -$ php vendor/bin/phpunit +$ vendor/bin/phpunit ``` ## License From ae22bfbf1310a3442088a00b7d944a83b1c84282 Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Mon, 4 Oct 2021 10:43:16 +0200 Subject: [PATCH 2/2] Improve examples and use full namespaces --- examples/insert.php | 9 ++++----- examples/search.php | 13 ++++++------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/examples/insert.php b/examples/insert.php index e1f5fee..7c2b262 100644 --- a/examples/insert.php +++ b/examples/insert.php @@ -1,11 +1,8 @@ openLazy('test.db'); @@ -14,8 +11,10 @@ $promise->then(null, 'printf'); for ($i = 0; $i < $n; ++$i) { - $db->exec("INSERT INTO foo (bar) VALUES ('This is a test')")->then(function (Result $result) { + $db->exec("INSERT INTO foo (bar) VALUES ('This is a test')")->then(function (Clue\React\SQLite\Result $result) { echo 'New row ' . $result->insertId . PHP_EOL; + }, function (Exception $e) { + echo 'Error: ' . $e->getMessage() . PHP_EOL; }); } diff --git a/examples/search.php b/examples/search.php index f60f8aa..f03f547 100644 --- a/examples/search.php +++ b/examples/search.php @@ -1,21 +1,20 @@ openLazy('test.db'); -$db->query('SELECT * FROM foo WHERE bar LIKE ?', ['%' . $search . '%'])->then(function (Result $result) { +$db->query('SELECT * FROM foo WHERE bar LIKE ?', ['%' . $search . '%'])->then(function (Clue\React\SQLite\Result $result) { echo 'Found ' . count($result->rows) . ' rows: ' . PHP_EOL; echo implode("\t", $result->columns) . PHP_EOL; foreach ($result->rows as $row) { echo implode("\t", $row) . PHP_EOL; } -}, 'printf'); +}, function (Exception $e) { + echo 'Error: ' . $e->getMessage() . PHP_EOL; +}); + $db->quit();