Skip to content

Commit 7688294

Browse files
authored
Merge pull request #43 from SimonFrings/docs
Improve documentation and examples
2 parents c788322 + ae22bfb commit 7688294

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ so you can query your data without blocking your main application.
2525
and does not get in your way.
2626
Future or custom commands and events require no changes to be supported.
2727
* **Good test coverage** -
28-
Comes with an automated tests suite and is regularly tested against actual SQLite databases in the wild.
28+
Comes with an automated test suite and is regularly tested against actual SQLite databases in the wild.
2929

3030
**Table of contents**
3131

@@ -64,6 +64,10 @@ existing SQLite database file (or automatically create it on first run) and then
6464
`INSERT` a new record to the database:
6565

6666
```php
67+
<?php
68+
69+
require __DIR__ . '/vendor/autoload.php';
70+
6771
$factory = new Clue\React\SQLite\Factory();
6872

6973
$db = $factory->openLazy('users.db');
@@ -164,11 +168,11 @@ the underlying database is ready. Additionally, it will only keep this
164168
underlying database in an "idle" state for 60s by default and will
165169
automatically end the underlying database when it is no longer needed.
166170

167-
From a consumer side this means that you can start sending queries to the
171+
From a consumer side, this means that you can start sending queries to the
168172
database right away while the underlying database process may still be
169173
outstanding. Because creating this underlying process may take some
170-
time, it will enqueue all oustanding commands and will ensure that all
171-
commands will be executed in correct order once the database is ready.
174+
time, it will enqueue all outstanding commands and will ensure that all
175+
commands will be executed in the correct order once the database is ready.
172176
In other words, this "virtual" database behaves just like a "real"
173177
database as described in the `DatabaseInterface` and frees you from
174178
having to deal with its async resolution.
@@ -213,7 +217,7 @@ $db = $factory->openLazy('users.db', SQLITE3_OPEN_READONLY);
213217
By default, this method will keep "idle" connection open for 60s and will
214218
then end the underlying connection. The next request after an "idle"
215219
connection ended will automatically create a new underlying connection.
216-
This ensure you always get a "fresh" connection and as such should not be
220+
This ensures you always get a "fresh" connection and as such should not be
217221
confused with a "keepalive" or "heartbeat" mechanism, as this will not
218222
actively try to probe the connection. You can explicitly pass a custom
219223
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
355359
force-close the connection.
356360

357361
Unlike the `quit()` method, this method will immediately force-close the
358-
connection and reject all oustanding commands.
362+
connection and reject all outstanding commands.
359363

360364
```php
361365
$db->close();
@@ -400,7 +404,7 @@ See also the [`close()`](#close) method.
400404

401405
## Install
402406

403-
The recommended way to install this library is [through Composer](https://getcomposer.org).
407+
The recommended way to install this library is [through Composer](https://getcomposer.org/).
404408
[New to Composer?](https://getcomposer.org/doc/00-intro.md)
405409

406410
This project follows [SemVer](https://semver.org/).
@@ -427,7 +431,7 @@ $ sudo apt install php-sqlite3
427431
## Tests
428432

429433
To run the test suite, you first need to clone this repo and then install all
430-
dependencies [through Composer](https://getcomposer.org):
434+
dependencies [through Composer](https://getcomposer.org/):
431435

432436
```bash
433437
$ composer install
@@ -436,7 +440,7 @@ $ composer install
436440
To run the test suite, go to the project root and run:
437441

438442
```bash
439-
$ php vendor/bin/phpunit
443+
$ vendor/bin/phpunit
440444
```
441445

442446
## License

examples/insert.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
<?php
22

3-
use Clue\React\SQLite\Factory;
4-
use Clue\React\SQLite\Result;
5-
63
require __DIR__ . '/../vendor/autoload.php';
74

8-
$factory = new Factory();
5+
$factory = new Clue\React\SQLite\Factory();
96

107
$n = isset($argv[1]) ? $argv[1] : 1;
118
$db = $factory->openLazy('test.db');
@@ -14,8 +11,10 @@
1411
$promise->then(null, 'printf');
1512

1613
for ($i = 0; $i < $n; ++$i) {
17-
$db->exec("INSERT INTO foo (bar) VALUES ('This is a test')")->then(function (Result $result) {
14+
$db->exec("INSERT INTO foo (bar) VALUES ('This is a test')")->then(function (Clue\React\SQLite\Result $result) {
1815
echo 'New row ' . $result->insertId . PHP_EOL;
16+
}, function (Exception $e) {
17+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
1918
});
2019
}
2120

examples/search.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
<?php
22

3-
use Clue\React\SQLite\DatabaseInterface;
4-
use Clue\React\SQLite\Factory;
5-
use Clue\React\SQLite\Result;
6-
73
require __DIR__ . '/../vendor/autoload.php';
84

9-
$factory = new Factory();
5+
$factory = new Clue\React\SQLite\Factory();
106

117
$search = isset($argv[1]) ? $argv[1] : 'foo';
128
$db = $factory->openLazy('test.db');
139

14-
$db->query('SELECT * FROM foo WHERE bar LIKE ?', ['%' . $search . '%'])->then(function (Result $result) {
10+
$db->query('SELECT * FROM foo WHERE bar LIKE ?', ['%' . $search . '%'])->then(function (Clue\React\SQLite\Result $result) {
1511
echo 'Found ' . count($result->rows) . ' rows: ' . PHP_EOL;
1612
echo implode("\t", $result->columns) . PHP_EOL;
1713
foreach ($result->rows as $row) {
1814
echo implode("\t", $row) . PHP_EOL;
1915
}
20-
}, 'printf');
16+
}, function (Exception $e) {
17+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
18+
});
19+
2120
$db->quit();

0 commit comments

Comments
 (0)