0

I have two tables: user, user_matching. And I wanna get items from both tables in 1 query. For example, SQL-like query:

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

Usually I should use 2 query in NoSQL DB. Now I do it like this:

  1. Get from user_matching user_id
  2. With user_id Get from user

Can I replace it with only 1 query using Tarantool. And How To?

1 Answers1

3

You need to create stored procedure where you combine result of two selection, e.g.:

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

After you create this procedure you can call this procedure via Tarantool driver with fetching combined result.

More detail here: http://tarantool.org/doc/book/app/c-lua_tutorial.html?highlight=call

Oleg V. Volkov
  • 21,719
  • 4
  • 44
  • 68