使用多个条件从 tarantool 中选择 [英] Select from tarantool using multiple conditions
本文介绍了使用多个条件从 tarantool 中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何一次选择一个空间中的两个或多个字段的条件?我在文档中没有找到示例.
How do i make a select with conditions with two or more fields from one space at once? I didn't find an example in the documentation.
推荐答案
有两种方法可以做到这一点:使用 SQL 或使用较低级别的 lua API.
There are 2 ways to do this: using SQL or using a lower-level lua API.
第一个需要你设置空间格式(见此处).它看起来像这样:
The first one requires you to set space format (see here). It looks like this:
box.space.myusers:format({{name='id',type='number'},
{name='first_name',type='string'},
{name='last_name',type='string'}})
这是 SQL 找出列名所必需的.然后就可以查询如下:
This is required for SQL to figure out column names. Then you can query it as follows:
box.execute([[SELECT "id" FROM "myusers" WHERE "first_name"='John' AND "last_name"='Doe';]])
另一种选择相同空间的方法是:
Another way to select from the same space is:
user_ids = {}
for_,user in box.space.myusers.index.first_name:pairs("John") do
if user.last_name == "Doe" then
table.insert(user_ids, user.id)
end
end
查看此处了解有关低水平空间 API.
Look here for more details on the low-level space API.
这篇关于使用多个条件从 tarantool 中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文