dgraph 入门

获得 dgraph/dgraph 镜像之后,三条命令,启动服务

docker run -it -p 16080:6080 -p 18080:8080 -p 19080:9080 -p 18000:8000 -v /home/admin/dgraph:/dgraph --name test-dgraph dgraph/dgraph dgraph zero (启动zero)
docker exec -it test-dgraph dgraph server --memory_mb 2048 --zero localhost:5080(启动 dgraph server)
docker exec -it test-dgraph dgraph-ratel(启动ratel(图形界面))

dgraph 8000端口,添加数据,查询数据的图形界面,8080 是http接口, 其他涉及端口 5080, 6080用途暂不明。

alter 接口,添加schema,修改schema(话说这里没有表的概念么 )?
添加数据的语句,定义schema

name: string @index(term) .
age: int @index(int) .
friend: uid @count .

mutate, 用来添加数据, friend指向另一个用户 <> 前面的部分为 node 的标示

{
  set {
    _:michael <name> "Michael" .
    _:michael <age> "39" .
    _:michael <friend> _:amit .
    _:michael <friend> _:sarah .
    _:michael <friend> _:sang .
    _:michael <friend> _:catalina .
    _:michael <friend> _:artyom .
    _:michael <owns_pet> _:rammy .

    _:amit <name> "अमित"@hi .
    _:amit <name> "অমিত"@bn .
    _:amit <name> "Amit"@en .
    _:amit <age> "35" .
    _:amit <friend> _:michael .
    _:amit <friend> _:sang .
    _:amit <friend> _:artyom .

    _:luke <name> "Luke"@en .
    _:luke <name> "Łukasz"@pl .
    _:luke <age> "77" .

    _:artyom <name> "Артём"@ru .
    _:artyom <name> "Artyom"@en .
    _:artyom <age> "35" .

    _:sarah <name> "Sarah" .
    _:sarah <age> "55" .

    _:sang <name> "상현"@ko .
    _:sang <name> "Sang Hyun"@en .
    _:sang <age> "24" .
    _:sang <friend> _:amit .
    _:sang <friend> _:catalina .
    _:sang <friend> _:hyung .
    _:sang <owns_pet> _:goldie .

    _:hyung <name> "형신"@ko .
    _:hyung <name> "Hyung Sin"@en .
    _:hyung <friend> _:sang .

    _:catalina <name> "Catalina" .
    _:catalina <age> "19" .
    _:catalina <friend> _:sang .
    _:catalina <owns_pet> _:perro .

    _:rammy <name> "Rammy the sheep" .

    _:goldie <name> "Goldie" .

    _:perro <name> "Perro" .
  }
}

查询语句,并且通过friend这条边 获取连线节点的信息,两重 expand意思是 以root节点为中心,向外获取两层,everyone 取什么都行,无所谓,anyofterms: Matches strings that have any of the specified terms in any order; case insensitive.
allofterms: Matches strings that have all specified terms in any order; case insensitive.

{
  everyone(func: anyofterms(name, "Michael Amit")) {
    name
    friend {
      name@en:ko:ru
      friend { expand(_all_) {expand(_all_)} }
    }
  }
}

Leave a comment

Your email address will not be published.

*