Dgraph安装和使用(一)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hotqin888/article/details/81156959

Dgraph使用笔记

1 在win上用docker安装

docker pull dgraph/dgraph

2 运行dgraph

网络上一些旧的安装方法已经过时,要按照官网的办法:

拉取后要安装官网的步骤,先制作一个docker-compose.yml(将代码拷贝到一个文本文件内,然后修改名称,放到docker当前目录中),内容就不贴了。

然后执行命令docker-compose up –d

如下图

用浏览器打开

浏览器输入192.168.99.100:8000

里面的update URL填入192.168.99.100:8080

 

3 运行

官网中说把符号‘   ’之间的代码拷贝到命令行,然后点击run。注意切换命令行下部的mutate---alter---query

1) 添加数据

{
  set {
   _:luke <name> "Luke Skywalker" .
   _:leia <name> "Princess Leia" .
   _:han <name> "Han Solo" .
   _:lucas <name> "George Lucas" .
   _:irvin <name> "Irvin Kernshner" .
   _:richard <name> "Richard Marquand" .

   _:sw1 <name> "Star Wars: Episode IV - A New Hope" .
   _:sw1 <release_date> "1977-05-25" .
   _:sw1 <revenue> "775000000" .
   _:sw1 <running_time> "121" .
   _:sw1 <starring> _:luke .
   _:sw1 <starring> _:leia .
   _:sw1 <starring> _:han .
   _:sw1 <director> _:lucas .

   _:sw2 <name> "Star Wars: Episode V - The Empire Strikes Back" .
   _:sw2 <release_date> "1980-05-21" .
   _:sw2 <revenue> "534000000" .
   _:sw2 <running_time> "124" .
   _:sw2 <starring> _:luke .
   _:sw2 <starring> _:leia .
   _:sw2 <starring> _:han .
   _:sw2 <director> _:irvin .

   _:sw3 <name> "Star Wars: Episode VI - Return of the Jedi" .
   _:sw3 <release_date> "1983-05-25" .
   _:sw3 <revenue> "572000000" .
   _:sw3 <running_time> "131" .
   _:sw3 <starring> _:luke .
   _:sw3 <starring> _:leia .
   _:sw3 <starring> _:han .
   _:sw3 <director> _:richard .

   _:st1 <name> "Star Trek: The Motion Picture" .
   _:st1 <release_date> "1979-12-07" .
   _:st1 <revenue> "139000000" .
   _:st1 <running_time> "132" .
  }
}

拷贝到命令行,切换到mutate,然后run

2) 添加索引

name: string @index(term) .
  release_date: datetime @index(year) .
  revenue: float .
  running_time: int .

拷贝到命令行,切换到alter,然后run

3) 查询

{
  me(func:allofterms(name, "Star Wars")) @filter(ge(release_date, "1980")) {
    name
    release_date
    revenue
    running_time
    director {
     name
    }
    starring {
     name
    }
  }
}

拷贝到命令行,切换到query,然后run

4 问题

第二次运行docker-compose up –d出错,只好docker-compose up用这个命令,勉强运行起来了。

关机后下次运行是不是用下面这个命令呢?

start & stop

docker-compose start命令启动运行某个服务的所有容器; 
docker-compose stop命令停止运行一个服务的所有容器;

 

阅读更多

没有更多推荐了,返回首页