Local Storage - How to have structure tables from a SQL query on local storage

Local Storage - How to have structure tables from a SQL query on local storage

  

I have a mobile app that's fetching data from a structurre table following a sql query joing multiple tables.Now I want to create local storages on the device and somehow want to have that structure table copied in the local storage which is not possible).Does anyone know how to tackle this problem? Doing it with aggregate is hell of a pain.

Thanks

Hi Gael, 

I'm not sure if I understand your "pain". You want to copy the structure itself or the data returned by the SQL query? 


Can't you create a local entity for each entity you are using, copy the data asynchronously and then fetch the data from local storage?


Vera 

Hey Vera,

Good to see you after so long.

I think Gael, wants a local table equivalent to the structure and then push query result to that table. Correct Gael?

Thank and Regards,

Suraj Borade

Suraj Borade wrote:

Hey Vera,

Good to see you after so long.

I think Gael, wants a local table equivalent to the structure and then push query result to that table. Correct Gael?

Thank and Regards,

Suraj Borade

Hi Both, thanks for the replies.

I want the equivalent structure in local with the exact same data. where i'm now stuck is that we can't have any sql in local and i cant find a way to get the data i want using aggregates


Could you please share a snapshot of your data model? 

How many tables are you trying to query? Why can't you use aggregates? 

Gael Bielo wrote:

Suraj Borade wrote:

Hey Vera,

Good to see you after so long.

I think Gael, wants a local table equivalent to the structure and then push query result to that table. Correct Gael?

Thank and Regards,

Suraj Borade

Hi Both, thanks for the replies.

I want the equivalent structure in local with the exact same data. where i'm now stuck is that we can't have any sql in local and i cant find a way to get the data i want using aggregates


Hi Gael,

It is not a good practice to push all the data from the server to the device since it would deteriorate the performance of the application. 

Evaluate if you really need to do it. To help, you check the mobile best practices and the Design a Local Storage section.

As someone suggested before, you can design a local storage entity with same attributes of your structure and then you just need to sync the data from the server to the local entity.

Regards,

António Pereira


Vera Tiago wrote:

Could you please share a snapshot of your data model? 

How many tables are you trying to query? Why can't you use aggregates? 

As you can see on the screenshot, I'm using as source data structure tables created from sql queries. Each attributs in those structures come from different existing tables. 

Now i need to have a local storage and was wondering if there was a way I could transform these structure into for example "LocalGetBreadTypes" in order to fetch my data from the local storage?


Solution

Hi Gael,

So, you have already a server action to retreive the data, right? Next, you can create a Local Entity with those attributes (the same that you have on your output structure) and create a new action to copy the data to that local entity/ies.

For your use case you need to:

- create two local entities: LocalBreadType and LocalGrains

- create a sync action to get data from the server and copy it to the local storage. You will probably need two local variables (LocalBreadType List and LocalGrains List) to assign the values and use them to create the records.

- call this action whenever you need to update that data - preferably asynchronously.

- then, on the screens, you just need to retreive data from the local storage entities.


Regarding sync patterns, you are in a "Read-only" scenario - check this post for more information:

https://success.outsystems.com/Documentation/10/Developing_an_Application/Use_Data/Offline/Offline_Data_Synchronization_Patterns/Read-Only_Data


...and let me know if that helps :-) 

Vera


Solution

Vera Tiago wrote:

Hi Gael,

So, you have already a server action to retreive the data, right? Next, you can create a Local Entity with those attributes (the same that you have on your output structure) and create a new action to copy the data to that local entity/ies.

For your use case you need to:

- create two local entities: LocalBreadType and LocalGrains

- create a sync action to get data from the server and copy it to the local storage. You will probably need two local variables (LocalBreadType List and LocalGrains List) to assign the values and use them to create the records.

- call this action whenever you need to update that data - preferably asynchronously.

- then, on the screens, you just need to retreive data from the local storage entities.


Regarding sync patterns, you are in a "Read-only" scenario - check this post for more information:

https://success.outsystems.com/Documentation/10/Developing_an_Application/Use_Data/Offline/Offline_Data_Synchronization_Patterns/Read-Only_Data


...and let me know if that helps :-) 

Vera



Hello Vera,

Thanks for your reply.

I realised that I didn't mention it earlier, but I think the best sync pattern for my app is the "Read/Write Data With Conflict Detection" as the app is a survey. will this influence the above steps you described?

Well, you still need a sync action but with a different logic.

Instead of just copying data from server to local storage, you need also to detect and handle conflicts.  

Read this before you try to apply to your use case:
https://success.outsystems.com/Documentation/10/Developing_an_Application/Use_Data/Offline/Offline_Data_Synchronization_Patterns/Read%2F%2FWrite_Data_With_Conflict_Detection

Note: if you scroll down the page you'll find a sample with this pattern implemented - take a look :)

Vera Tiago wrote:

Well, you still need a sync action but with a different logic.

Instead of just copying data from server to local storage, you need also to detect and handle conflicts.  

Read this before you try to apply to your use case:
https://success.outsystems.com/Documentation/10/Developing_an_Application/Use_Data/Offline/Offline_Data_Synchronization_Patterns/Read%2F%2FWrite_Data_With_Conflict_Detection

Note: if you scroll down the page you'll find a sample with this pattern implemented - take a look :)

Brigado :)