Chapter 10. Data Storage and Querying: Storing and Fetching Relevant Messages
In this chapter you will learn more about data storage and retrieval (i.e., querying in Opa). We will start with some general concepts and then illustrate them by applying them to our Birdy app.
Collections in Opa: Lists, Sets, and Maps
Collections are used to represent multiple instances of the same type of data. In Opa, there are three primary types of collections:
- Lists
- Sets
- Maps
Lists represent a sequence of items. The order of items is the order of insertion. There may be multiple occurrences of the same value in a list. We talked about lists in Recursive Types.
Sets represent a group of items, ordered by an
order
, typically an alphanumerical sort. Sets cannot contain duplicates.
They correspond to the mathematical notion of a set.
Maps are mappings from keys to values. They are often known by alternative names, such as associative array or dictionary. All the keys in a map are distinct.
Figure 10-1 depicts these different types of collections.
Figure 10-1. Illustration of different types of collections available in Opa
In the following sections we will discuss how to:
- Declare data for storage
- Write new or update previously stored data
- Query and retrieve data from storage
In each section we will also discuss features specific to records, lists, sets, and maps.
Declaring Data
We briefly talked about using ...
Get Opa: Up and Running now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.