zymawy/dgraph

dgraph 的流畅 API

1.0.1 2024-07-08 05:13 UTC

This package is auto-updated.

Last update: 2024-09-02 05:26:01 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

这里应该放置您的描述。请限制在一到两段之内。考虑添加一个小例子。

支持我们

我们投入了大量资源来创建一流的开放源代码包。您可以通过购买我们的付费产品之一来支持我们。

我们非常感谢您从家乡寄给我们明信片,并说明您正在使用我们的哪个包。您可以在我们的联系页面上找到我们的地址。我们在我们的虚拟明信片墙上发布所有收到的明信片。

安装

您可以通过 composer 安装此包

composer require zymawy/dgraph

您可以使用以下命令发布和运行迁移

php artisan vendor:publish --tag="dgraph-migrations"
php artisan migrate

您可以使用以下命令发布配置文件

php artisan vendor:publish --tag="dgraph-config"

这是发布配置文件的内容

return [
];

可选地,您可以使用以下命令发布视图

php artisan vendor:publish --tag="dgraph-views"

使用方法

创建客户端

use Zymawy\Dgraph\DgraphClient;

/** @var DgraphClient $client */
$client = new DgraphClient('https://:8080');

定义和修改模式

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://: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();
}

添加初始数据

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://:8080");

use Zymawy\Dgraph\Api\Mutation;
use Zymawy\Dgraph\Exceptions\DgraphException;

/** @var DgraphClient $client */
$client = new DgraphClient("https://: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();
}

运行基本查询

测试

composer test

变更日志

请参阅变更日志以获取有关最近更改的更多信息。

贡献

请参阅贡献指南以获取详细信息。

安全漏洞

请参阅我们的安全策略以了解如何报告安全漏洞。

致谢

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅许可证文件