|
1 | | - |
| 1 | + |
2 | 2 |
|
3 | 3 | # Bolt |
4 | | -Bolt protocol library over TCP socket. Bolt protocol is created and in use for communication with [Neo4j](https://neo4j.com/) Graph database. The Bolt documentation is available at [https://7687.org/](https://7687.org/). This library is aimed to be low level and keep up with protocol messages architecture and specifications. |
| 4 | +PHP library for communication with [Neo4j](https://neo4j.com/) graph database over TCP socket with Bolt protocol specification. The Bolt documentation is available at [https://www.neo4j.com/](https://www.neo4j.com/docs/bolt/current/). This library is aimed to be low level, support all available versions and keep up with protocol messages architecture and specifications. |
5 | 5 |
|
6 | | - |
7 | | - |
8 | | - |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
9 | 10 |
|
10 | | - |
11 | | - |
12 | | - |
13 | | - |
| 11 | +[](https://github.com/neo4j-php/Bolt/stargazers) |
| 12 | +[](https://packagist.org/packages/stefanak-michal/bolt/stats) |
| 13 | +[](https://github.com/neo4j-php/Bolt/releases) |
| 14 | +[](https://github.com/neo4j-php/Bolt/releases/latest) |
14 | 15 |
|
15 | 16 | ## Version support |
16 | 17 |
|
17 | | -We are trying to keep up and this library supports **Neo4j <= 4.4**. |
| 18 | +We are trying to keep up and this library supports **Neo4j <= 4.4** with **Bolt <= 4.4**. |
18 | 19 |
|
19 | | -[More info](https://github.com/neo4j-php/Bolt/wiki/Version-support) |
| 20 | +https://www.neo4j.com/docs/bolt/current/bolt-compatibility/ |
20 | 21 |
|
21 | 22 | ## Requirements |
22 | 23 |
|
23 | | -It's hard to live without all new features which means we keep at **PHP >= 7.1**. |
| 24 | +Keep up with [PHP supported versions](https://www.php.net/supported-versions.php) means we are at **PHP >= 7.4**. |
24 | 25 |
|
25 | | -[More info](https://github.com/neo4j-php/Bolt/wiki/Requirements) |
| 26 | +_If you need support for PHP < 7.4 you can use latest v3.x release. Not all new features are implement backwards._ |
| 27 | + |
| 28 | +### Extensions |
| 29 | + |
| 30 | +- mbstring https://www.php.net/manual/en/book.mbstring.php |
| 31 | +- sockets https://www.php.net/manual/en/book.sockets.php (optional) - Required when you use Socket connection class |
| 32 | +- openssl https://www.php.net/manual/en/book.openssl.php (optional) - Required when you use StreamSocket connection class with enabled SSL |
| 33 | +- phpunit >= 9 https://phpunit.de/ (development) |
26 | 34 |
|
27 | 35 | ## Installation |
28 | 36 |
|
29 | | -You can use composer or download this repository. |
| 37 | +You can use composer or download this repository from github and manually implement it. |
| 38 | + |
| 39 | +### Composer |
| 40 | + |
| 41 | +Run the following command in your project to install the latest applicable version of the package: |
30 | 42 |
|
31 | 43 | `composer require stefanak-michal/bolt` |
32 | 44 |
|
33 | | -[More info](https://github.com/neo4j-php/Bolt/wiki/Installation) |
| 45 | +[Packagist](https://packagist.org/packages/stefanak-michal/bolt) |
| 46 | + |
| 47 | +### Manual |
| 48 | + |
| 49 | +1. Download [latest release](https://github.com/neo4j-php/Bolt/releases/latest) or [master](https://github.com/neo4j-php/Bolt) |
| 50 | +2. Unpack |
| 51 | +3. Copy content of `src` directory to your project |
34 | 52 |
|
35 | 53 | ## Usage |
36 | 54 |
|
37 | | -Concept of usage is based on Bolt messages and mostly you need just these. |
| 55 | +Concept of usage is based on Bolt messages. Available protocol methods depends on Bolt version. |
| 56 | + |
| 57 | +https://www.neo4j.com/docs/bolt/current/bolt/message/ |
38 | 58 |
|
39 | 59 | ```php |
40 | | -<?php |
41 | | -$bolt = new \Bolt\Bolt(new \Bolt\connection\Socket()); |
| 60 | +// Create connection class and specify target host and port |
| 61 | +$conn = new \Bolt\connection\Socket(); |
| 62 | +// Create new Bolt instance and provide connection object |
| 63 | +$bolt = new \Bolt\Bolt($conn); |
| 64 | +// Build and get protocol version instance which creates connection and executes handshake |
42 | 65 | $protocol = $bolt->build(); |
| 66 | +// Login to database with credentials |
43 | 67 | $protocol->hello(\Bolt\helpers\Auth::basic('neo4j', 'neo4j')); |
44 | | -$stats = $protocol->run('RETURN 1 AS num, 2 AS cnt'); |
| 68 | +// Execute query with parameters |
| 69 | +$stats = $protocol->run('RETURN $a AS num, $b AS str', ['a' => 123, 'b' => 'text']); |
| 70 | +// Pull records from last executed query |
45 | 71 | $rows = $protocol->pull(); |
46 | 72 | ``` |
47 | 73 |
|
| 74 | +Response from database (`$rows`) always contains n+1 rows because last entry are meta informations. |
| 75 | + |
48 | 76 | [More info](https://github.com/neo4j-php/Bolt/wiki/Usage) |
49 | 77 |
|
| 78 | +### Transactions |
| 79 | + |
| 80 | +Bolt from version 3 supports transactions and protocol contains these methods: |
| 81 | + |
| 82 | +- begin |
| 83 | +- commit |
| 84 | +- rollback |
| 85 | + |
| 86 | +_`run` executes query in auto-commit transaction if explicit transaction was not open._ |
| 87 | + |
| 88 | +### Cypher query parameters |
| 89 | + |
| 90 | +| Neo4j | PHP | |
| 91 | +| --- | --- | |
| 92 | +| Null | null | |
| 93 | +| Boolean | boolean | |
| 94 | +| Integer | integer | |
| 95 | +| Float | float | |
| 96 | +| Bytes | [Bytes class](https://github.com/neo4j-php/Bolt/blob/master/src/structures/Bytes.php) | |
| 97 | +| String | string | |
| 98 | +| List | array with consecutive numeric keys from 0 | |
| 99 | +| Dictionary | object or array which is not considered as list | |
| 100 | +| Structure | [directory with structures](https://github.com/neo4j-php/Bolt/tree/master/src/structures) | |
| 101 | + |
| 102 | +List or dictionary can be also provided as instance of class implementing `Bolt\PackStream\IPackListGenerator` or `Bolt\PackStream\IPackDictionaryGenerator`. This approach helps with memory management while working with big amount of data. To learn more you can check [performance test](https://github.com/neo4j-php/Bolt/blob/master/tests/PerformanceTest.php) or [packer test](https://github.com/neo4j-php/Bolt/blob/master/tests/PackStream/v1/PackerTest.php). |
| 103 | + |
| 104 | +### Neo4j Aura |
| 105 | + |
| 106 | +Connecting to Aura requires encryption which is provided with SSL. To connect to Aura you have to use StreamSocket connection class and enable SSL. |
| 107 | + |
| 108 | +```php |
| 109 | +// url without neo4j+s protocol |
| 110 | +$conn = new \Bolt\connection\StreamSocket('helloworld.databases.neo4j.io'); |
| 111 | +// enable SSL |
| 112 | +$conn->setSslContextOptions([ |
| 113 | + 'verify_peer' => true |
| 114 | +]); |
| 115 | +$bolt = new \Bolt\Bolt($conn); |
| 116 | +``` |
| 117 | + |
| 118 | +https://www.php.net/manual/en/context.ssl.php |
| 119 | + |
50 | 120 | ## Another solutions |
51 | 121 |
|
52 | 122 | https://neo4j.com/developer/php/ |
| 123 | + |
| 124 | + |
| 125 | +## Support the driver |
| 126 | + |
| 127 | +This project is made as opensource but every support in form of donations are highly appreciated. |
| 128 | + |
| 129 | +<a href='https://ko-fi.com/Z8Z5ABMLW' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://cdn.ko-fi.com/cdn/kofi1.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a> |
0 commit comments