kaisawind's blog
  • 关于
  • 所有帖子

dgraph增删改查 - Sat, Aug 8, 2020

dgraph增删改查

1. 添加一条

{
  "set": [{
    "uid": "_:id",
    "name": "Alice",
    "age": 13,
    "dgraph.type": "User",
  }]
}

2. 添加多条

{
  "set": [
    {
      "uid": "_:id",
      "name": "Alice",
      "age": 13,
      "dgraph.type": "User",
    },
    {
      "uid": "_:id",
      "name": "Bob",
      "age": 13,
      "dgraph.type": "User",
    },
  ]
}

3. 查询

{
  users(func: type(User)) @filter(eq(username, "alice")) {
    uid
    expand(_all_)
  }
}

4. 删除

{
    "delete": [
        "uid": "0x1345"
    ]
}

5. 分页

{
    ids as users(func: type(User), first:10, offset:0) {
      uid
      expand(_all_)
    }
    
    metrics(func:uid(ids)) {
      count: count(uid)
    }
  }


辽ICP备2021007608号 | © 2025 | kaisawind

Facebook Twitter GitHub