【问题标题】:Tarantool Querying QuestionsTarantool 查询问题
【发布时间】:2020-02-21 01:03:53
【问题描述】:

我的数据结构格式如下:

unix/:/var/run/tarantool/tarantool.sock> s:format()
---
- [{'name': 'id', 'type': 'unsigned'}, {'name': 'version', 'type': 'array'}, {'name': 'data',
    'type': 'array'}]
...

我里面已经有以下数据:

unix/:/var/run/tarantool/tarantool.sock> s:select{}
---
- - [0, [[21, 'action123'], [12, 'actionXYZ'], [11, 'actionABC']], [['actionXYZ',
        'SOME_JAVASCRIPT_CONTENT']]]
  - [1, [[33, 'action123'], [12, 'baseXYZ'], [11, 'baseABC']], [['bas123', 'SOME_CSS_CONTENT']]]
...

我已通读参考资料和文档,但在完成以下内容时有点迷失:

  1. 什么是“WHERE”等价物? IE。选择以查找具有version12 的条目

    没有看到适用的例子 https://www.tarantool.io/en/doc/2.2/reference/reference_lua/box_space/#lua-function.space_object.select

  2. 列出带有字段名称的项目(这样我就知道我正在查看哪个块)。在某种程度上,有点像在 SQL 的结果中包含“列标题”。

    我的format() 中有命名 元组 - 在查询数据时如何查看这些名称?

    {'name': 'id', 'type': 'unsigned'}, {'name': 'version', 'type': 'array'}, {'name': 'data', '类型': '数组'}]

  3. 印刷精美! (最好是yaml)

    我尝试使用https://www.tarantool.io/en/doc/2.2/reference/reference_lua/yaml/ 环绕我的选择语句,但没有任何效果。

【问题讨论】:

    标签: tarantool


    【解决方案1】:
    1. 您需要使用索引进行命令式有效查询,请看这里:

    https://www.tarantool.io/en/doc/2.2/reference/reference_lua/box_space/#lua-function.space_object.create_index

    https://www.tarantool.io/en/doc/2.2/reference/reference_lua/box_index/

    1. 使用元组:tomap():

    https://www.tarantool.io/en/doc/2.2/reference/reference_lua/box_tuple/#lua-function.tuple_object.tomap

    1. 这取决于你想要它漂亮在哪里。您可能需要调整 yaml 设置,或者只是链接 tomap 调用:
    tarantool> box.space.TEST:pairs():map(function(x) return x:tomap({names_only=true}) end):totable()
    ---
    - - COLUMN1: 1
        COLUMN2: a
      - COLUMN1: 13
        COLUMN2: a
      - COLUMN1: 1000
        COLUMN2: a
    

    【讨论】:

      猜你喜欢
      • 2016-06-29
      • 1970-01-01
      • 2019-04-19
      • 2019-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多