@@ -7,7 +7,9 @@ built on top of [ReactPHP](https://reactphp.org/).
7
7
8
8
* [ Quickstart example] ( #quickstart-example )
9
9
* [ Usage] ( #usage )
10
- * [ Database] ( #database )
10
+ * [ Factory] ( #factory )
11
+ * [ open()] ( #open )
12
+ * [ DatabaseInterface] ( #databaseinterface )
11
13
* [ exec()] ( #exec )
12
14
* [ query()] ( #query )
13
15
* [ quit()] ( #quit )
@@ -27,10 +29,11 @@ existing SQLite database file (or automatically create it on first run) and then
27
29
28
30
``` php
29
31
$loop = React\EventLoop\Factory::create();
32
+ $factory = new Clue\React\SQLite\Factory($loop);
30
33
31
34
$name = 'Alice';
32
- Clue\React\SQLite\Database:: open($loop, 'users.db')->then(
33
- function (Clue\React\SQLite\Database $db) use ($name) {
35
+ $factory-> open('users.db')->then(
36
+ function (Clue\React\SQLite\DatabaseInterface $db) use ($name) {
34
37
$db->exec('CREATE TABLE IF NOT EXISTS foo (id INTEGER PRIMARY KEY AUTOINCREMENT, bar STRING)');
35
38
36
39
$db->query('INSERT INTO foo (bar) VALUES (?)', array($name))->then(
@@ -53,25 +56,29 @@ See also the [examples](examples).
53
56
54
57
## Usage
55
58
56
- ### Database
59
+ ### Factory
57
60
58
- The ` Database ` class represents a connection that is responsible for
59
- comunicating with your SQLite database wrapper, managing the connection state
60
- and sending your database queries.
61
+ The ` Factory ` is responsible for opening your [ ` DatabaseInterface ` ] ( #databaseinterface ) instance.
62
+ It also registers everything with the main [ ` EventLoop ` ] ( https://github.com/reactphp/event-loop#usage ) .
63
+
64
+ ``` php
65
+ $loop = React\EventLoop\Factory::create();
66
+ $factory = new Clue\React\SQLite\Factory($loop);
67
+ ```
61
68
62
69
#### open()
63
70
64
- The static ` open(LoopInterface $loop, string $filename, int $flags = null): PromiseInterface<Database > ` method can be used to
71
+ The ` open(string $filename, int $flags = null): PromiseInterface<DatabaseInterface > ` method can be used to
65
72
open a new database connection for the given SQLite database file.
66
73
67
- This method returns a promise that will resolve with a ` Database ` on
74
+ This method returns a promise that will resolve with a ` DatabaseInterface ` on
68
75
success or will reject with an ` Exception ` on error. The SQLite extension
69
76
is inherently blocking, so this method will spawn an SQLite worker process
70
77
to run all SQLite commands and queries in a separate process without
71
78
blocking the main process.
72
79
73
80
``` php
74
- Database:: open($loop, 'users.db')->then(function (Database $db) {
81
+ $factory-> open('users.db')->then(function (DatabaseInterface $db) {
75
82
// database ready
76
83
// $db->query('INSERT INTO users (name) VALUES ("test")');
77
84
// $db->quit();
@@ -84,14 +91,20 @@ The optional `$flags` parameter is used to determine how to open the
84
91
SQLite database. By default, open uses ` SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE ` .
85
92
86
93
``` php
87
- Database:: open($loop, 'users.db', SQLITE3_OPEN_READONLY)->then(function (Database $db) {
94
+ $factory-> open('users.db', SQLITE3_OPEN_READONLY)->then(function (DatabaseInterface $db) {
88
95
// database ready (read-only)
89
96
// $db->quit();
90
97
}, function (Exception $e) {
91
98
echo 'Error: ' . $e->getMessage() . PHP_EOL;
92
99
});
93
100
```
94
101
102
+ ### DatabaseInterface
103
+
104
+ The ` DatabaseInterface ` represents a connection that is responsible for
105
+ comunicating with your SQLite database wrapper, managing the connection state
106
+ and sending your database queries.
107
+
95
108
#### exec()
96
109
97
110
The ` exec(string $query): PromiseInterface<Result> ` method can be used to
0 commit comments