定制 bingher/tugraph 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bingher/tugraph

最新稳定版本:v0.0.9

Composer 安装命令:

composer require bingher/tugraph

包简介

TuGraph PHP Driver with Restfull API

README 文档

README

Install

composer require bingher/tugraph

Use

  • use origin cypher query
use bingher\tugraph\TuGraph;

$config = [
    'uri' => '<API Base Uri>',
    'user' => '<User>',
    'password' => '<Password>',
    'graph' => '<Graph name,default:empty>',
];

$tu = new TuGraph($config);

$sql = 'Match p = (n)-[]-(m) Return p';
$result = $tu->graph('<GraphName>')->call($sql);
  • use php-cypher-dsl query
use bingher\tugraph\TuGraph;
use function WikibaseSolutions\CypherDSL\node;
use function WikibaseSolutions\CypherDSL\query;

$config = [
    'uri' => '<API Base Uri>',
    'user' => '<User>',
    'password' => '<Password>',
    'graph' => '<Graph name,default:empty>',
];

$tu = new TuGraph($config);

$tom = node("Person")->withProperties(["name" => "Tom Hanks"]);
$coActors = node();

$statement = query()
    ->match($tom->relationshipTo(node(), "ACTED_IN")->relationshipFrom($coActors, "ACTED_IN"))
    ->returning($coActors->property("name"))
    ->build();

$result = $tu->graph('<GraphName>')->call($statement);
  • example
use bingher\tugraph\TuGraph;

$config = [
    'uri' => '<API Base Uri>',
    'user' => '<User>',
    'password' => '<Password>',
    'graph' => '<Graph name,default:empty>',
];

$tu = new TuGraph($config);

$zg = TuGraph::node('主公');
$r  = TuGraph::link(['隶属']);
$wj = TuGraph::node();

$res = $tu->graph('三国')
    ->match($zg->relationship($r, $wj))
    ->where([$zg->property('name')->equals('曹操'), $wj->property('name')->startsWith('夏侯')])
    ->returning([$zg, $r, $wj])
    ->call();

$sql = $tu->sql();
var_dump($sql);
$this->assertStringMatchesFormat("MATCH (%s:主公)-[%s:隶属]-(%s) WHERE ((%s.name = '曹操') AND (%s.name STARTS WITH '夏侯')) RETURN %s, %s, %s", $sql);
var_dump($res);

query result

array(4) {
  ["elapsed"]=>float(0.0040798187255859375)
  ["header"]=>
  array(3) {
    [0]=>
    array(2) {
      ["name"]=>string(35) "varc9815f2faa847fca20a93a8d940604e5"
      ["type"]=>int(1)
    }
    [1]=>
    array(2) {
      ["name"]=>string(35) "var741b1da0dd39e501fc9adf7febe0706a"
      ["type"]=>int(2)
    }
    [2]=>
    array(2) {
      ["name"]=>string(35) "vard064169534b1fb4d74dbec62d435ef5a"
      ["type"]=>int(1)
    }
  }
  ["result"]=>
  array(3) {
    [0]=>
    array(3) {
      [0]=>string(170) "{"identity":91,"label":"主公","properties":{"camp":"魏","family":"谯县曹氏","father_position":"太尉","hometown":"豫州","name":"曹操","position":"魏武帝"}}"
      [1]=>string(94) "{"dst":91,"forward":false,"identity":0,"label":"隶属","label_id":2,"src":28,"temporal_id":0}"
      [2]=>string(126) "{"identity":28,"label":"武将","properties":{"camp":"魏","family":"谯县夏侯氏","hometown":"豫州","name":"夏侯惇"}}"
    }
    [1]=>
    array(3) {
      [0]=>string(170) "{"identity":91,"label":"主公","properties":{"camp":"魏","family":"谯县曹氏","father_position":"太尉","hometown":"豫州","name":"曹操","position":"魏武帝"}}"
      [1]=>string(94) "{"dst":91,"forward":false,"identity":0,"label":"隶属","label_id":2,"src":34,"temporal_id":0}"
      [2]=>string(126) "{"identity":34,"label":"武将","properties":{"camp":"魏","family":"谯县夏侯氏","hometown":"豫州","name":"夏侯尚"}}"
    }
    [2]=>
    array(3) {
      [0]=>string(170) "{"identity":91,"label":"主公","properties":{"camp":"魏","family":"谯县曹氏","father_position":"太尉","hometown":"豫州","name":"曹操","position":"魏武帝"}}"
      [1]=>string(94) "{"dst":91,"forward":false,"identity":0,"label":"隶属","label_id":2,"src":35,"temporal_id":0}"
      [2]=>string(126) "{"identity":35,"label":"武将","properties":{"camp":"魏","family":"谯县夏侯氏","hometown":"豫州","name":"夏侯渊"}}"
    }
  }
  ["size"]=>int(3)
}
  • use result function
$sql = '<cypher query>';
$callResult = $tu->call($sql);
$result = $tu->result($callResult);
var_dump($result);

result

array (
    'nodes' => array(...node array),
    'edges' => array(...edge array),
    'table' => array(...array),
)

Ref

TuGraph Restfull API TuGraph Cypher API php-cypher-dsl wiki

统计信息

  • 总下载量: 33
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-13