【问题标题】:How i can perform request to tarantool like in mysql?我如何像在 mysql 中一样执行对 tarantool 的请求?
【发布时间】:2016-07-10 17:33:24
【问题描述】:

我需要从 tarantool 所有数据中选择一个空格中的两个值。 我如何像在 mysql 中一样执行对 tarantool 的请求?

select from aaa where a=1a22cadbdb or a=7f626e0123

现在我可以提出两个请求:

box.space.logs:select({'1a22cadbdb'})
box.space.logs:select({'7f626e0123'})

但我不知道如何将结果合并为一个;(

【问题讨论】:

    标签: tarantool


    【解决方案1】:

    以下代码将字段[0]合并到lua表

    a = box.space.logs:select({'1a22cadbdb'})
    b = box.space.logs:select({'7f626e0123'})
    c = { field_1 = a[0], field_2 = b[0] }
    

    select 返回一个或多个元组,以便您可以通过 [] 提取值。

    有关选择的更多详细信息:http://tarantool.org/doc/book/box/box_index.html?highlight=select#lua-function.index_object.select

    关于元组的更多细节:http://tarantool.org/doc/book/box/box_tuple.html?highlight=tuple#lua-module.box.tuple

    【讨论】:

      【解决方案2】:

      现在 Tarantool 允许您通过 SQL 进行检索,例如 box.execute([[select from "aaa" where "a"='1a22cadbdb' or "a"='7f626e0123';]])。在执行此操作之前,您必须使用 format() 函数添加 aaa 的字段名称和类型。

      【讨论】:

        【解决方案3】:

        对我来说这项工作很好,但需要从第一次选择中检查返回:

        local res = {}
        for k, v in pairs (box.space.email:select({email})[1]) do
            if type(v) == 'string' then
                table.insert(res, box.space.logs:select({v})[1])
            end
        end
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-10-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-06-30
          • 1970-01-01
          • 2021-12-25
          • 1970-01-01
          相关资源
          最近更新 更多