作者:淘宝店名维衣潮都_233 | 来源:互联网 | 2023-06-23 11:15
本文由编程笔记#小编为大家整理,主要介绍了dgraph基本查询语法一相关的知识,希望对你有一定的参考价值。dgraph的查询语法是在graphql上的扩展,添加了新的支
本文由编程笔记#小编为大家整理,主要介绍了dgraph 基本查询语法 一相关的知识,希望对你有一定的参考价值。
dgraph 的查询语法是在graphql 上的扩展,添加了新的支持,同时官方提供了一个
学习的网站 https://tour.dgraph.io/
基本环境(cluster 模式的)
参考 github 项目 https://github.com/rongfengliang/dgraph-docker-compose-deploy
git clone https://github.com/rongfengliang/dgraph-docker-compose-deploy
cd dgraph-docker-compose-deploy/one-zero
docker-compose up -d
基本使用
name: string @index(term) @lang .
age: int @index(int) .
friend: uid @count .
{
set {
_:michael "Michael" .
_:michael "39" .
_:michael _:amit .
_:michael _:sarah .
_:michael _:sang .
_:michael _:catalina .
_:michael _:artyom .
_:michael _:rammy .
_:amit "????"@hi .
_:amit "????"@bn .
_:amit "Amit"@en .
_:amit "35" .
_:amit _:michael .
_:amit _:sang .
_:amit _:artyom .
_:luke "Luke"@en .
_:luke "?ukasz"@pl .
_:luke "77" .
_:artyom "Артём"@ru .
_:artyom "Artyom"@en .
_:artyom "35" .
_:sarah "Sarah" .
_:sarah "55" .
_:sang "??"@ko .
_:sang "Sang Hyun"@en .
_:sang "24" .
_:sang _:amit .
_:sang _:catalina .
_:sang _:hyung .
_:sang _:goldie .
_:hyung "??"@ko .
_:hyung "Hyung Sin"@en .
_:hyung _:sang .
_:catalina "Catalina" .
_:catalina "19" .
_:catalina _:sang .
_:catalina _:perro .
_:rammy "Rammy the sheep" .
_:goldie "Goldie" .
_:perro "Perro" .
}
}
{
everyone(func: anyofterms(name, "Michael Amit")) {
name
friend {
[email protected]:ko:en
friend { expand(_all_) { expand(_all_) } }
}
}
}
schema(pred: [name, age, friend, owns_pet]) {
type
index
}
@
参考:
{
language_support(func: allofterms([email protected], "????")) {
[email protected]:hi:en
age
friend {
[email protected]:ru
age
}
}
}
内容查询
- allOfTerms(edge_name, "term1 ... termN")
- anyOfTerms(edge_name, "term1 ... termN")
比较查询
- eq(edge_name, value):
- ge(edge_name, value):
- le(edge_name, value):
- gt(edge_name, value):
- lt(edge_name, value):
参考:
{
michael_friends_and(func: allofterms(name, "Michael")) {
name
age
friend @filter(ge(age, 27) AND le(age, 48)) {
[email protected]
age
}
}
}
orderasc or orderdesc
{
michael_friends_sorted(func: allofterms(name, "Michael")) {
name
age
friend (orderasc: age) {
[email protected]
age
}
}
}
first: N
offset: N
after: uid
参考:
{
michael_friends_first(func: allofterms(name, "Michael")) {
name
age
friend (orderasc: [email protected], offset: 1, first: 2) {
[email protected]
}
}
}
{
michael_number_friends(func: allofterms(name, "Michael")) {
name
age
count(friend)
}
}
{
have_friends(func: has(friend)) {
[email protected]
age
number_of_friends : count(friend)
}
}
{
michael_number_friends(func: allofterms(name, "Michael")) {
persons_name : name
age
number_of_friends : count(friend)
}
}
参考资料
https://tour.dgraph.io/