如何使用 ID 数组从 Ballerina 表中选择记录?

问题描述 投票:0回答:1

我正在开发一个 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
http-post ballerina x-www-form-urlencoded ballerina-http ballerina-swan-lake
1个回答
0
投票

最简单的方法是使用

array:indexOf
函数进行文件管理。

Foo[] selection = from Foo foo in fooTable
        where ids.indexOf(foo.id) !is ()
        select foo;
© www.soinside.com 2019 - 2024. All rights reserved.