Simple use of dictionary and TinyDB

Have you ever use tinyDB or other databases to store value? When there are so many data you have to store, you don’t wanna store it with so many call tinyDB store block. Therefore, the dictionary component is here to help.

What is a dictionary?

Dictionary is a built-in component.
Generally speaking, a dictionary uses a key to call and get the value.
For example,
It will return the string "whatever".
blocks (2)

How to use it?

As mentioned,

a dictionary uses a key to call and get the value.

What you’ll need:

image
image

The same logic as TinyDB, but we use the dictionary this time

The dictionary now acts like tinyDB, which can be used to store almost every type of value.

How to get the value?

Using the example above,


if the key doesn’t exist, return “not found”.

How to store/ add new value?

Storing new value:

It isn’t hard to achieve. If you want to replace with a new value, do this


Remember to store the dictionary with tinyDB as well.

Adding new value:

Similar to storing a new value, but it will create a new pair of key and value.

It is really useful when you have to store many data. There are also many features in the dictionary such as return the list of key and value.

If you find a helpful and you have time, leave a like :slight_smile:
Ask anything if you have any question, I will try to answer as much as I can.

40 Likes

Nice guide @WatermelonIce :+1:

5 Likes

Simple and understandable explained guide, @WatermelonIce! That gives you
:+1: :+1: :+1:
You made a Tutorial of blocks which are very very useful and must be understood correctly. Thank you very much!
:partying_face: :sunglasses:

3 Likes

Useful Tutorial. Keep it up…

2 Likes

I changed your title a bit since it is a combination of a Dictionary and a TinyDB. Hope you don’t mind.

5 Likes

Can I Store Html Text as pair?

1 Like

I think you can. What about just trying it out? :sweat_smile:

1 Like

As Yoshi said, what are you trying?
You want the key to be html or the value?
As mentioned,

Text can always be stored.

1 Like

Good guide @WatermelonIce :golfing_man:

2 Likes

Nice guide. Easy to understand. Great work

1 Like

very , very helpful! thank you very much for the tutorial! 10 thumbs up!!!

1 Like

Hello do we have to make the dictionnary each time the app is launched or is it persistant like TinyDB ?

In therm of performance what is the quicker way to get a value between dictionnay, TinyDB or Ressource Utilities (using GetString from blcok) ?

Thanks for the reply :wink:

Dictionary won’t save anything in the storage. You need tinyDB for that.

For resource utilities, that’s for json file, most probably the json file you put in assets

Ok so need to remake the dictionnary at each launch.

I have a JSON file for all my value and need to acces them :

  • make a dictionnary with all the values from the json
  • put all values from json in TinyDB
  • load the json in a resource utilities

And what is the most efficient during the app use between these 3 methods ?

Great Guide !! :+1:

1 Like

What wrong with my blocks, when run app, screen turn to “white screen”, there is nothing …blocks(3)

Is “http://azparts.epizy.com/blix/index.html” in your dictionary as a key?

i’ve tried http://azparts.epizy.com/blix/index.html is a key, and http://azparts.epizy.com/blix/index.html is a value, but it still dont work.

In this case you should put http://azparts.epizy.com/blix/index.html in key, and the url you want to go in value.

However, would you be redirected to other website when the page is loaded?

This all my blocks, 4 links in key i want it direct to 4 value.
when i open app, screen turn to “white screen” and nothings happen.blocks(3)