我正在开发一个 Ballerina 项目,我有一个名为 fooTable 的记录表,其定义如下:
type Foo record {|
readonly int id;
string name;
|};
table<Foo> key(id) fooTable = table [
{ id: 1, name: "f1" },
{ id: 2, name: "f2" },
{ id: 3, name: "f3" },
{ id: 4, name: "f4" }
];
现在,我需要根据 id 值数组从 fooTable 中选择一组 Foo 记录。
int[] ids = [1, 2, 3];
Foo[] selection; // filtering query expression
最简单的方法是使用
array:indexOf
函数进行文件管理。
Foo[] selection = from Foo foo in fooTable
where ids.indexOf(foo.id) !is ()
select foo;