Windows下dgraph的安装与使用
Windows下dgraph的安装与使用
安装
docker安装
-
使用docker下载dgraph
1
docker pull dgraph/dgraph:latest
-
配置
docker-compose.ym
l用于启动服务1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43version: "3.2"
services:
zero:
image: dgraph/dgraph:latest
volumes:
- type: volume
source: dgraph
target: /dgraph
volume:
nocopy: true
ports:
- 5080:5080
- 6080:6080
restart: on-failure
command: dgraph zero --my=zero:5080
alpha:
image: dgraph/dgraph:latest
volumes:
- type: volume
source: dgraph
target: /dgraph
volume:
nocopy: true
ports:
- 7080:7080
- 8080:8080
- 9080:9080
restart: on-failure
command: dgraph alpha --my=alpha:7080 --lru_mb=2048 --zero=zero:5080
ratel:
image: dgraph/dgraph:latest
volumes:
- type: volume
source: dgraph
target: /dgraph
volume:
nocopy: true
ports:
- 8000:8000
command: dgraph-ratel
volumes:
dgraph: -
启动服务,在yml文件下目录下启动
1
docker-compose up -d
Windows下可以直接安装
-
在dgraph官网下载dgraph安装包
-
解压,并配置环境变量
-
使用三个命令行,分别启动如下命令
1
2
3dgraph alpha --lru_mb 1024
dgraph zero
dgraph-ratel
dgraph数据类型
数据类型 | 可用索引 | 可用分词器 |
---|---|---|
default | list,count,index,upsert | default |
float | list,count,index,upsert | float |
bool | list,count,index,upsert | bool |
geo | list,count,index,upsert | geo |
datetime | list,count,index,upsert | year,month,day,hour |
string | list,count,index,upsert | exect,hash,term,fulltext,trigram |
password | - | - |
uid | list,count,reverse | - |
- 选取list后才能选择count
- 选用index后才能选择upsert
- string类型的分词器只能选一个
ratel的使用
ratel是dgraph的UI接口,可以在上面进行数据的CURD或者修改schema,浏览器进入localhost:8000
,本地开发可以选择Local Bundle
。
-
可以在
mutate
中对数据进行增删改-
新增数据
1
2
3
4
5{
set{
_:任意标识符 <谓词> "值" .
}
}- 如果没有提前建立好schema的话,需要插入数据后在schema里设置schema,创建索引等
-
修改数据
1
2
3
4
5{
set{
<uid> <谓词> "新值" .
}
} -
删除数据
1
2
3
4
5
6
7{
delete {
_:任意标识符 <谓词> "值" .
_:任意标识符 <谓词> * .
_:任意标识符 * * .
}
}
-
-
可以在
query
中查询1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20# 查询语句
{
自定义方法名(func:方法){
结果中需要展示的谓词
}
}
# 根据uid查询
{
方法名(func: uid(<要查询的uid>)) {
结果中需要展示的谓词
}
}
# 根据属性属性查询
{
方法名(func: eq(谓词,值)) {
结果中需要展示的谓词
}
}-
可以嵌套查询
1
2
3
4
5
6
7
8
9{
expand(func: allofterms(谓词, 值)) {
expand(_all_) {
expand(_all_) {
expand(_all_)
}
}
}
}
-
Comment