Reading Assignment: Multi-Index Database API

Now that you know the basics about tables. Let’s get nitty gritty. Read through this blog post. Then answer the following questions.

[Some of the questions below have been updated since the start of this thread]

  1. Why do we need to have persistant storage?
  2. What are the functions to manage a database?
  3. What are the benefits of having iterators instead of a traditional key-value storage option?

Post your answers in this forum thread.

  1. So we can view saved data later
  2. It must be of type unsigned 64-bit integer
  3. You can create multiple views on a table
1 Like

1. Why do we need to have persistant storage?
Actions must exist in an action context, this context must exist in a memory space (ram), so it can have a valid point of start (set of instructions), since the only way to pass the state of a data on EOSIO is by having a persisted database to be compared within the new data that will be inserted. (blockchain persistant storage that allow to do not have duplicate objects?)

2. What limitations are set on the primary key?
the primary key of the object in the eosio::multi_index container must be a unique unsigned 64-bit integer. Its by rule stablished, the unsigned 64-bit integer will work has the unique ID on the index table.

3. What are the benefits of having iterators instead of a traditional key-value storage option?
Enables rich retrieval capabilities. Up to 16 secondary indices can be defined, each having its own way of ordering and retrieving table contents. This allow to retrieve multiple views on the same table, different value types if need it and other data.

2 Likes
  1. Why do we need to have persistent storage?
    This storage contains the EOS blockchain state and therefore must be available at all times. This includes the tables that hold order books, account balances, contract statuses and voting data.

  2. What limitations are set on the primary key?
    The primary key must be unique and an unsigned 64 bit integer type.

  3. What are the benefits of having iterators instead of a traditional key-value storage option?
    The main benefit is that they allow the code be less type dependant. The iterator will still work even if you change the underlying container type that is being iterated. Iterators are class objects which encapsulate safe node pointers that are only exposed via the iterator’s methods. Iterators can be used to provide differing table views where the table has multiple secondary indices.

2 Likes
  1. So that we can check if the data is valid on the EOS blockchain

  2. The primary key must be unique and have an unsigned 64 bit integer type.

  3. We can retrieve multiple views of the same table

1 Like

Hi @filip.
It seems like all the links to the reading assignments and EOS developer documentation are broken links. :worried:

I get “404 NOT FOUND” on all the links I’ve tried. Can you please update the links?

Ivo

Will do ASAP! Thanks for letting me know :slight_smile:

@filip (or whoever is now maintaining this course) a friendly reminder the assignment article link is still broken.

Should I wait for this course to be fully updated before continuing? Or is it supposed to be updated and I should continue and let you know if anything still needs fixing?

I was able to find some of the answers here (permalink):

1. Why do we need to have persistent storage?
  • Without some form of permanent storage everything that gets done is thrown away because there’s no place to store it. Persistent storage is required to save information for longer periods than the current session- i.e between user visits.
  • It also allows you to keep more data than can be stored in memory as persistent storage like databases often have orders of magnitude more available space.
2. What limitations are set on the primary key?
  • It must be unique
  • There needs to be a primary_key() method that returns the value of the primary key
3. What are the benefits of having iterators instead of a traditional key-value storage option?

A generic answer since the article I found didn’t really address this question:

  • Iterators are an abstraction which provides a generic API to traverse a collection of data without needing to know how that data is structured
  • Since iterators operate on collections it means it can return more than one item
1 Like

Hello sir, we are really close to update the EOS Programming 101, you could wait between 1 to 2 week until the new one is released if you want to, but most of the programming syntax is going to be the same, so you can continue the course and let us know if there is any issue so we can fix it ASAP.

If you have any doubt, please let us know so we can help you! :slight_smile:

Carlos Z.

great definition of iterators !!

1 Why do we need to have persistant storage ?
Like “traditional” computers programs are stored in “persistant storage” areas ( hard drive ) and executed in RAM.
Similarly on EOS Virtual Machine SmartContract ( ie programs ) are stored on the EOS blockchain and actions executed in RAM.

2 What limitations are set on the primary key?
it’s an unsigned 64 bits integer and must be unique.

3-What are the benefits of having iterators instead of a traditional key-value storage option?
The purpose is to have multiple views|scope like in SQL database table.
eosio::multi_index containers provides “iterators” to achieve similar funtionalities".

1 Like
  1. Why do we need to have persistant storage?

So that We can retrieve/share the historical dataset according to the business logic.

  1. What limitations are set on the primary key?

unsigned 64-bit integer.

  1. What are the benefits of having iterators instead of a traditional key-value storage option?

We can retrieve multiple views of the same table.

1 Like

@filip @Phillip_Hamnett @thecil

1 Like

Hello sir, yeah i think they update the hole manual and that link is not working anymore.
Here is another with documentation for: EOSIO cdt.

If you have any doubt, please let us know so we can help you! :slight_smile:

Carlos Z.

  1. Why do we need to have persistant storage?
    To store data that is going to be needed in future actions performed by the contract.

  2. What limitations are set on the primary key?
    Primary index type must be uint64_t and must be unique.

  3. What are the benefits of having iterators instead of a traditional key-value storage option?
    The allow us to keep a collection of objects sorted by a variety of different key types, which could be derived from the data within the object

1 Like

1 Like

@chadrickm
Hello sir(s), yes that web site has been deprecated, we will try to change the link from the course ASAP.

Thank you for notice it.

Here it is the updated documentary about Data persistence and Secondary Indices.

Hope you find this useful. :slight_smile:

If you have any doubt, please let us know so we can help you!

Carlos Z.

1 Like

image

2 Likes

@marsrvr I like your visual approach to the readings and assignments. Also being a rocket scientist is quite a laudable achievement. I hope and wish I will be able to learn more from your nodal thought process and potentially maybe we can embark on certain project together in the near future. I am looking indepth unto financial market and creating an automated process to reward traders in the financial market field,agriculture and mineral resources in the nearest future. Let me know if you have interesting project to pursue.

2 Likes
  1. Why do we need to have persistant storage?
    In order to permanently store data even when our smart contract is not in execution.

  2. What are the functions to manage a database?

  • Querying an entry with .find
  • Creating new entries with .emplace
  • Modifying existing entries with .modify
  1. What are the benefits of having iterators instead of a traditional key-value storage option?
    Iterators simplify the way to go through the elements of lists or the records of a table.
1 Like