How to retrieve data from local DB to show cached (stored) data

Hi Thunkers,

I’m working on a problem where I’m trying to reload data into my data viewer list from data stored in my local DB.
So for context, I’m using a temp local DB to populate my data viewer list, the use can navigate to different page, but on returning to the initial page I’m trying to reload/repopulate the data viewer list fields with the data stored in the local DB.
Effectively I’m trying to cache the initial results.
Due to using a local DB (assuming it would be faster and easier) than pulling from FireBase I can’t think of a way to retrieve each or all rows as the Get Row Object requires a “row id” and as I’m simply retrieving data rather than creating an entry, or using a single list viewer selection there isn’t a row id I can use to reference the desired rows…

I’m all ears if anyone can suggest a solution or alternative that will repopulate/retrieve/reshow the initial data?

Thanks Thunkers!

1 Like

If all what you want is to list the entries retrieved from Firebase then it would be much easier to save these entries in a list as app variable and display the list in the List Viewer.

If you want the data to persist between sessions then use stored variable as the list.

in local DB, the row IDs are just numbers from 1… however many rows.

Clarification (thanks @muneer) - you can call the rows with integer row numbers, but if you retrieve the row number, you get an alphanumeric string.

1 Like

Thank you both!
So here is my thought process and where I am so far.
I’m test building an app that initially pulls a number of items from a web api, I format this information, store it in a local DB and display the result in a custom list viewer. (I’m storing the data in a local DB as it seems the easiest way of populating a custom list viewer). In addition I am also syncing the data to FB so that future uses of the data can be retrieved from FB rather than the API.

The problem is when the user navigates away from the initial screen and then returns, I’m having to either call the data again from either the API or FB and rebuild the view, instead of just retaining what was already there or using what I have stored in the local DB from the first visit.

As the the data also includes images, there is a significant load time on each rebuild/visit to the same page. This is manageable on an initial visit to the page, but subsequent visits results in a poor experience if the load time is the same with each visit.

The fact that I have the data already in memory in the local DB, it seems puzzling I’d have to make a call to FB from the same user session or convert it a list and loaded the data in that way.

@catsarisky to your point this is what I have currently, unfortunately it doesn’t work. I have also tried including a DataViewer Refresh call which makes no difference. In all cases I’m left with null even if I try to reference row “1”

1 Like

Please note that when using the local table created by the “+” of the Data Sources option, the row ID is a unique 32 alphanumeric character and the count loop will not do.

(by the way, I use the term local table to avoid confusion with local DB and local storage which both are available in the legacy UI)

To retrieve data from your local table, you need to use different techniques.

image
Start your loop with this (note that ID is a hidden column in every local table that saves the row ID)
you will continue retrieving the record using the “j” which gives the correct row IS.

1 Like

Hi @muneer ,

I’m going to respectfully disagree with you - local tables can be referenced with row number instead of the 32 alphanumeric character. This works (and is a local table created by hitting the + button under data sources)
image

The code pasted above has the problem that it starts counting from zero, not 1.

Correction: I don’t know if you can user integer row numbers with the DVL blocks. Integers do work with the purple data source blocks.

2 Likes

Thanks both,

Appreciate your feedback, I’ll test both and let you know the outcome.
Cheers!

Ok quick update…
@muneer
Tried the option below and no luck, now data loaded hence just a blank screen.

@catsarisky I tried the loop below and also tried referencing just a number to see if it would work and I get the same null results


As nothing seems to work I’m abandoning this option, its quite frustrating as I seem to spend more time trying to find work around to things that should work than on the concept :disappointed:

By any chance does anyone know of an alternative solution to showing content within the data viewer list, after clicking to a separate page, then returning to the DVL page, without having to reload the data from scratch?? :weary:

1 Like

@ukhollywood29l

You are trying to dynamically change the values of the data viewer rows which is not necessary at all.

DVL would always be bound to a table at design time. You only need to be sure this table has values and that’s it. Nothing else is required.

2 Likes

@catsarisky
I have seen this working in some cases and not in others. I have my blocks working with Google sheet using counter numbers for months and suddenly it stopped and the issue was row IDs so instead of using direct counter numbers I use the list of values for column ID just to be in the safe side.

I just tested a quick List Viewer with list of values for column ID and I got all long numbers for my local table.

1 Like

how would you use the DVL in this case? Or would just populate the Data Bindings fields?

I have tried this method, but its still quite slow in populating the DVL which I guess is the same as what I’m attempting to do with the loops…

Is there an alternative to maintaining the data in the DVL?

1 Like

Once you select the Data Source for the DVL and the Layout then you bind the columns of the Data Source to the columns of the DVL and the rest is automated by Thunkable.

1 Like

Thanks @muneer, I have tried this method and it did provide a way to populate the fields, so definitely a solution. But I was hoping it would have the DVL preloaded on open, rather than it populating the fields like its the first time as its quite slow.
I guess a better query would be, how to cache the DVL data so I dont have to reload it on return to the page.

1 Like