import ballerina/io;
type Employee record {
readonly string firstName;
readonly string lastName;
int salary;
};
public function main() {
// `t` has a key sequence with `firstName` and `lastName` fields.
table<Employee> key(firstName, lastName) t = table [
{firstName: "John", lastName: "Smith", salary: 100},
{firstName: "Fred", lastName: "Bloggs", salary: 200}
];
// The key sequence provides keyed access to members of the `table`.
Employee? e = t["Fred", "Bloggs"];
io:println(e);
}
Multiple key fieldsA |
import ballerina/io;
type Employee record {
readonly string firstName;
readonly string lastName;
int salary;
};
public function main() {
table<Employee> key(firstName, lastName) t = table [
{firstName: "John", lastName: "Smith", salary: 100},
{firstName: "Fred", lastName: "Bloggs", salary: 200}
];
t
has a key sequence with firstName
and lastName
fields.
Employee? e = t["Fred", "Bloggs"];
The key sequence provides keyed access to members of the table
.
io:println(e);
}
bal run multiple_key_fields.bal
{"firstName":"Fred","lastName":"Bloggs","salary":200}