The Whys and Hows of Data Stores

I’ve been working with Data Stores a lot this week and have had a few questions about my work, so I thought it would be helpful to have a thread about how we are using them.

Here is my experience

Why Use Data Stores

I am using them for two reasons:

  1. To create a local database that mirrors part of my actual database.
    The reason for this is to minimise database hits when people are searching for items. So for example a user of my system may have 1000 contact records, each of which has 20 fields. If you use the “normal” method of doing search by name for example, Wappler will hit the database literally each time you type another letter in the search box and bring back loads of data. When my app has 1000s of users this will be very expensive (£,$,€) in terms of database usage. If I read the basic details of all the contacts into a data store, all the searching can go on locally on the user’s machine and then I can just go to the database once for the one record they want to edit.

Of course, in doing this you need to consider the maximum you can store locally… and data security… I’d be interested to hear people’s knowledge and experience about this!

  1. Booking Form Implementation
    I will create a large booking form, and I will use data stores to record a user’s responses, then when they press [Book Now] I will hit the database once with all their final responses.

How I am Using Them

I’m creating a different data store for each database table I want to mirror, so one for contacts, one for events, etc.

Each data store just has simple variables in it to store the associated column values, so one for first_name, last_name etc.

I have extra variables in the data store for local actions taken within the app. So for example if someone searches all contacts with a gender of male then I have a flow which sets an is_searched variable to true for all males, and a repeat which lists all contacts where is_searched==1. I also have an is_selected variable to select a working list of contacts to apply a single action to like sending an email.

In the process, I have learned that you have to be a bit careful with data types… in particular:

Also, be careful with the use of session storage. Remember that if you don’t tick the use session storage box then the data will remain on the computer after the user closes the tab of the browser running your app.

Oh, and once you have named a data store, it is best not to re-name it right now.

In order to fill data stores from the database, I am using flows… there is an article below about how I do that.

I’m really loving working with Data Stores.

Be great to hear your experiences too!

Best wishes,
Antony.

Community Page
Last updated: