一旦添加了数据之后,如何进行基本的 Query 呢?

基本和 SQL 很像,就是 select .... from ... where …,进阶的还可以指定 block 编号。

Select 的用法

1. Select All

select 基本上输入是 Array,如果我们要 select 所有 user:

{
  "select": ["*"],
  "from": "user"
}

API 是 fdb/<ledger 名称>/query

# linux
curl -H "Accept: application/json" -X POST -d '{ "select": ["*"], "from": "user"}' <http://13.114.145.25/fdb/seedao/testing/query>

# windows
curl -H "Accept: application/json" -X POST -d "{ \\"select\\": [\\"*\\"], \\"from\\": \\"user\\"}" <http://13.114.145.25/fdb/seedao/testing/query>

拿回来的资料就是 array,每一个 predicate 以及对应的值:

[
   {
      "_id":351843720888323,
      "user/wallet":"0x5e6CcE07A609D7550Ffd39beEa0d8B2eeF28FCd3",
      "user/email":"[email protected]"
   },
   {
      "_id":351843720888322,
      "user/wallet":"0x7EA1EaA27b313D04D359bF3e654FE927376e31Bc",
      "user/email":"[email protected]"
   },
   {
      "_id":351843720888321,
      "user/wallet":"0x5e6CcE07A609D7550Ffd39beEa0d8B2eeF28FCd2",
      "user/email":"[email protected]"
   },
   {
      "_id":351843720888320,
      "user/wallet":"0x7EA1EaA27b313D04D359bF3e654FE927376e31Bb",
      "user/email":"[email protected]"
   }
]

2. 不要显示 namespace

如果想要拿回来的数据不要是 user/wallet, user/email 而是直接是 wallet, email,就可以在 select * 前添加 predicates 即可

{
  "select": ["wallet", "email", "*"],
  "from": "user"
}

cURL:

# linux
curl -H "Accept: application/json" -X POST -d '{"select":["wallet","email","*"],"from":"user"}' <http://13.114.145.25/fdb/seedao/testing/query>

# windows
curl -H "Accept: application/json" -X POST -d "{\\"select\\":[\\"wallet\\",\\"email\\",\\"*\\"],\\"from\\":\\"user\\"}" <http://13.114.145.25/fdb/seedao/testing/query>