Published in


Ballerina Collections: Tables

Photo by Scott Graham on Unsplash

In my previous article we discussed about preliminary collections supported in Ballerina Language. In this article we will talk about Tables, another structured data type in Ballerina.

Tables are a built-in data-structure which contains an array of records. Each row in the table consists of a record and each row is uniquely identified by a key. The key is stored in the record as an immutable field. This is similar to the table concept which we find in SQL-based databases.

We can access elements in a table either by iterating over all the elements as an array or by pointing to the item using the associated key.

We can derive a key using multiple-fields.

Since the type of the key is not restricted to string, we could use a structured key as well.

Combining Tables with Language Integrated Queries

Ballerina has a feature called Language Integrated Queries, which will enable users to query and manipulate data in arrays with SQL-like syntax. This is based on the concept of Mathematical Set Builder Notation. We can use this feature in combination with Ballerina Tables.

Apart from using ‘key’ to access a row in a table we could use queries.

Usually when querying a table the result will be in an array format. But, we could also create a table using queries.

Query expressions also support let clause to define intermediate variables as well.

Ballerina queries can also use the join clause with table keys.

Ballerina tables combined with ‘Language Integrated Queries’, simplifies the data manipulation logic of any application.

In this article we discussed about the advanced collection support provided with Ballerina tables.

Key Points on Ballerina Tables:

  • Contains the ability of both arrays and maps
  • key is a part of the value itself
  • key should be unique
  • Type of the key is not restricted to string
  • Table preserves the order of the members




The Ballerina Tech Blog

Recommended from Medium

Filter your way through git log

Modular components and agile iterations

Static Libraries in the C language

Dynamo DB Cross Region Migration

A quick dive into Python’s “__slots__”

Multi-Versioning in Oracle explained using recursive INSERT

Trading Partners: Maximizing the value of integrations

Let’s learn, build and sell an API

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ayesh Almeida

Ayesh Almeida

A Tech Enthusiast who wants to build simple solutions for complex problems.

More from Medium

Evolution of Our Invalidation System

Paging by Scroll — ElasticSearch

Notes on Kafka Efficiency

TypeORM Query Builder Wrapper