zymawy / dgraph
Fluent API for dgraph
Fund package maintenance!
zymawy
Requires
- google/protobuf: ^3.3
- grpc/grpc: ^1.3
- illuminate/contracts: ^10.0||^11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- spatie/laravel-ray: ^1.35
This package is auto-updated.
Last update: 2024-11-02 05:48:45 UTC
README
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
You can install the package via composer:
composer require zymawy/dgraph
You can publish and run the migrations with:
php artisan vendor:publish --tag="dgraph-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="dgraph-config"
This is the contents of the published config file:
return [
];
Optionally, you can publish the views using
php artisan vendor:publish --tag="dgraph-views"
Usage
Create a Client
use Zymawy\Dgraph\DgraphClient; /** @var DgraphClient $client */ $client = new DgraphClient('https://localhost:8080');
Define and Alter Schema
use Zymawy\Dgraph\Api\Operation; use Zymawy\Dgraph\Exceptions\DgraphException; use Zymawy\Dgraph\Types\StringType; use Zymawy\Dgraph\Types\IntType; use Zymawy\Dgraph\DgraphClient; /** @var DgraphClient $client */ $client = new DgraphClient('https://localhost:8080'); // Define the schema using the Operation class $operation = new Operation(); $operation ->addField("name", new StringType(["index(term)"])) ->addField("age", new IntType(["index(int)"])) ->addType("person", ["name", "age"]); try { $response = $client->alter($operation); if ($response->hasErrors()) { throw new DgraphException("Schema alteration error: " . json_encode($response->getErrors())); } else { echo "Schema successfully altered."; } } catch (DgraphException $e) { echo "Error: " . $e->getMessage(); }
Add Initial Data
use Zymawy\Dgraph\DgraphClient; use Zymawy\Dgraph\Txn; use Zymawy\Dgraph\Responses\DgraphResponse; use Zymawy\Dgraph\Exceptions\DgraphException; use Zymawy\Dgraph\Types\StringType; use Zymawy\Dgraph\Types\IntType; /** @var DgraphClient $client */ $client = new DgraphClient("https://localhost:8080"); use Zymawy\Dgraph\Api\Mutation; use Zymawy\Dgraph\Exceptions\DgraphException; /** @var DgraphClient $client */ $client = new DgraphClient("https://localhost:8080"); $mutation = new Mutation(); $mutation->set([ [ "uid" => "_:account1", "name" => "Hamza", "balance" => 1000.0 ], [ "uid" => "_:account2", "name" => "Zymawy", "balance" => 500.0 ] ]); try { $response = $client->mutate($mutation, true); // commitNow set to true if ($response->hasErrors()) { throw new DgraphException( "Mutation error: " . json_encode($response->getErrors()) ); } else { print_r($response->getData()); } } catch (DgraphException $e) { echo "Error: " . $e->getMessage(); }
Run a Basic Query
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.