0

我有两个表:useruser_matching。我想在 1 个查询中从两个表中获取项目。例如,类似 SQL 的查询:

select * from user where user.id = (select id from user_matching where id = user_matching_id)

通常我应该在 NoSQL DB 中使用 2 个查询。现在我这样做:

  1. user_matching获取user_id
  2. 用 user_id 从用户处获取

我可以使用 Tarantool 仅用 1 个查询替换它吗?怎么做?

4

1 回答 1

3

您需要创建存储过程,在其中组合两个选择的结果,例如:

function select_user_by_matching_id(matching_id)
    local id = box.space.user_matching:get{matching_id} # or :select
    local user_data = box.space.user:get{id} # or :select
    # work with user_data
    return user_data
end

创建此过程后,您可以通过 Tarantool 驱动程序调用此过程并获取组合结果。

更多细节在这里:http ://tarantool.org/doc/book/app/c-lua_tutorial.html?highlight=call

于 2016-04-05T07:34:22.213 回答