|
| 1 | +Neo4jQueryAPI client |
| 2 | + |
| 3 | +The Neo4j QueryAPI client is for developers and data engineers who want to interact programmatically with Neo4j databases — running queries, handling results, and managing database configurations. It offers: |
| 4 | + |
| 5 | +- Easy configuration to pick and choose drivers |
| 6 | +- An intuitive API for smooth query execution |
| 7 | +- Extensibility for custom use cases |
| 8 | +- Built and tested under close collaboration with the official Neo4j driver team |
| 9 | +- Easier to start with, just need a client to any neo4j instance |
| 10 | +- Fully typed with Psalm and CS fixed for code quality |
| 11 | +- It does not supports Bolt, Rather compatible with HTTP, and auto-routed drivers |
| 12 | + |
| 13 | + |
| 14 | + |
1 | 15 | # Query API
|
2 | 16 |
|
3 |
| -Usage example: |
| 17 | +A PHP client for Neo4j, a graph database. |
| 18 | + |
| 19 | +## Installation |
| 20 | + |
| 21 | +You can install the package via Composer: |
| 22 | + |
| 23 | +```sh |
| 24 | +composer require this-repo/neo4j-client |
| 25 | +``` |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +### Connecting to Neo4j |
4 | 30 |
|
5 | 31 | ```php
|
6 | 32 | use Neo4j\QueryAPI\Neo4jQueryAPI;
|
7 |
| -use Neo4j\QueryAPI\Objects\Authentication; |
| 33 | +use Neo4j\QueryAPI\Authentication\AuthenticateInterface; |
| 34 | + |
| 35 | +$client = Neo4jQueryAPI::login('http://localhost:7474', new AuthenticateInterface('username', 'password')); |
| 36 | +``` |
| 37 | + |
| 38 | +### Running a Query |
| 39 | + |
| 40 | +```php |
| 41 | +$query = 'MATCH (n) RETURN n'; |
| 42 | +$result = $client->run($query); |
| 43 | + |
| 44 | +foreach ($result as $record) { |
| 45 | + print_r($record); |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +### Transactions |
| 50 | + |
| 51 | +#### Begin a Transaction |
| 52 | + |
| 53 | +```php |
| 54 | +$transaction = $client->beginTransaction(); |
| 55 | +``` |
| 56 | + |
| 57 | +#### Run a Query in a Transaction |
| 58 | + |
| 59 | +```php |
| 60 | +$query = 'CREATE (n:Person {name: $name}) RETURN n'; |
| 61 | +$parameters = ['name' => 'John Doe']; |
| 62 | +$result = $transaction->run($query, $parameters); |
| 63 | +``` |
| 64 | + |
| 65 | +#### Commit a Transaction |
| 66 | + |
| 67 | +```php |
| 68 | +$transaction->commit(); |
| 69 | +``` |
| 70 | + |
| 71 | +#### Rollback a Transaction |
| 72 | + |
| 73 | +```php |
| 74 | +$transaction->rollback(); |
| 75 | +``` |
| 76 | + |
| 77 | +## Testing |
| 78 | + |
| 79 | +To run the tests, execute the following command: |
| 80 | + |
| 81 | +```sh |
| 82 | +vendor/bin/phpunit |
| 83 | +``` |
| 84 | + |
| 85 | +Cypher values and types map to these php types and classes: |
| 86 | + |
| 87 | +| Cypher | PHP | |
| 88 | +|--------------------|:-----------------:| |
| 89 | +| Single name | | |
| 90 | +| Integer | ``` * int ``` | |
| 91 | +| Float | ``` * float ``` | |
| 92 | +| Boolean | ``` * bool ``` | |
| 93 | +| Null | ``` * null ``` | |
| 94 | +| String | ``` * string ``` | |
| 95 | +| Array | | |
| 96 | +| Date | | |
| 97 | +| Duration | | |
| 98 | +| 2D Point | | |
| 99 | +| 3D Point | | |
| 100 | +| Cartesian 2D Point | | |
| 101 | +| Cartesian 3D Point | | |
| 102 | +| Node | | |
| 103 | +| Path | | |
| 104 | +| Map | | |
| 105 | +| Exact name | | |
| 106 | +| Bookmarks | Yes | |
| 107 | + |
| 108 | +## Diving deeper: |
| 109 | + |
| 110 | +| Feature | Supported? | |
| 111 | +|----------|:-------------:| |
| 112 | +| Authentication | Yes | |
| 113 | +| Transaction | Yes | |
| 114 | +| HTTP | Yes | |
| 115 | +| Cluster | Yes | |
| 116 | +| Aura | Partly (recent versions) | |
| 117 | +| Bookmarks | Yes | |
| 118 | + |
| 119 | +> **_NOTE:_** It supports neo4j databases versions > 5.25 (which has QueryAPI enabled.) |
| 120 | +
|
| 121 | + |
| 122 | + |
| 123 | +## Contributing |
| 124 | + |
| 125 | +Please see CONTRIBUTING for details. |
| 126 | + |
| 127 | +## Security |
| 128 | + |
| 129 | +If you discover any security-related issues, please email *[email protected]* instead of using the issue tracker. |
| 130 | + |
| 131 | +## Credits |
| 132 | + |
| 133 | +- [Your Name](https://github.com/your-github-username) |
| 134 | +- [All Contributors](https://github.com/your-repo/neo4j-client/graphs/contributors) |
| 135 | + |
| 136 | +## License |
8 | 137 |
|
9 |
| -$client = Neo4jQueryAPI::login('https://myaddress.com', Authentication::bearer('mytokken')) |
10 |
| -``` |
| 138 | +The MIT License (MIT). Please see License File for more information. |
0 commit comments