How to query data from airtable

App link: https://x.thunkable.com/copy/67ded111ba679802a9ed0977b4fb8479

In this example, I will be querying a database that receives multiple types of data from various users. This query is based on two qualifiers, both of which are text strings. This process could be applied to any number of items such as name, date, birthday, score, age, SSN, flavor, favorite thing, shoe size, etc. In my case, the qualifiers are ‘user’ and ‘data recording format.’ The data are fed into a graph for both myself and the user to see. I use the same process in another app to only see user data/graphs and edit the DB. The “admin app.” I will post another when I figure out how to filter based on date. This date filtering process should be similar. This tutorial should also be attributed to @actech for the help he provided in the process!

When the app opens, five variables are initialized. One variable is for the raw data. The other four are for the specific lists of values that I want to grab and display based on some qualifiers.

Screen Shot 2019-12-23 at 11.11.29 AM

Each time this screen is opened, all rows (the entire table) are grabbed from the AirtableDB and stored in the variable "raw data.” If there is an error, it will be displayed in ‘label 3’ on the same screen.

Screen Shot 2019-12-23 at 11.12.03 AM

When ‘button 2’ is pushed, the following occurs in order:

All 4 “_templists’ are set to be ‘empty lists’ in case there is old data in them. These will be used for any variety of things. in my case it was to be used as paired coordinates to display data visually in a line graph
Screen Shot 2019-12-23 at 11.13.46 AM

Then the app creates a list variable ‘j.’ all of ‘raw data’ goes into ‘j,’ allowing for each row to be looked at as an individual object.

Screen Shot 2019-12-23 at 11.14.15 AM

then the query occurs

Something helpful to think about is that in this process, a ‘property’ is synonymous with the name of a column in a database. Something to notice is this process is filtering all data not only for one qualifier but 2. my app doesn’t utilize all columns of data for every data entry that the user completes. You could avoid this by using multiple tables, but I didn’t want to do that.

First, the app takes out any ‘rows’ or objects in which the cell corresponding with the property ‘name’ doesn’t = [email protected]. if it does, that object is passed on to the next filter

The app takes out any object or ‘row’ in which the cell corresponding with the ‘column’ or property ‘count 1’ is empty. If that object’s ‘count 1’ property is not vacant, that object is passed on to the next set of blocks. For my purposes, if count 1 was empty, then some other data recording format was used, and therefore, that row should not be used. If row 1 had a value, there is no way for another format to have been used, and therefore, I want that row.

At last! I have only the rows that are relevant, based on my two qualifiers 1: name and 2: ‘not an empty cell.’ each of the 4 ‘in list’ blocks pulls out a specific property from the current object and saves it to its own variable.

because this app was for learning and experimenting purposes, the data are only then sent into labels to verify that you are receiving the correct filtered data from your database.

the screen i use


the blocks i use

this is how it is utilized in my bigger app.

and this is what the Airtable looks like

1 Like

Hello,

With your permission, I have a few comments about improving the project:

  1. If you remove duplicate blocks, then the number of blocks can be reduced by at least 2 times. Fewer blocks -> fewer errors and easier to work with blocks

  2. App variables are used in loops. This at least 10 times reduces the speed of the cycles. If there is a lot of data in the table, then the speed of the cycle may decrease by 100 or more times.

2 Likes

I would love any support here. It is slowing sown at times I think.

I can throw the duplicates into function. What can I do about number 2?

number 2 - replace app-variable variable from function parameters.

@actech Here I was able to follow your advice from #1. I was able to remove around 54 blocks total.

can you give me an example of how to implement your second piece of advice?

On your screen, I still see a lot of duplicate blocks to work with the list, as well as 3 identical functions.

Add a function block to the screen and add a parameter to the function - this parameter will become a variable. You can then delete this function block.