Syncing remote and loading local Data
Key:
- Sync data from the cloud Use a sync-entity or sync-entities actions to fetch data from the cloud and store it in the local SQLite database. Use the onLoad, onLoad, onRefresh, or any other event where actions are defined.
- Load data from SQLite to use on a Use the DATA_PROVIDER_LOCAL in the datasource defined in the or a global datasource to execute an SQLite query.
- Save data to SQLite ONLY To save data locally only and not sync to the cloud, use an execute-entity action with the DATA_PROVIDER_LOCAL.
- Save data to SQLite and sync data to the cloud Update the local SQLite and sync to the cloud in a single action to ensure high-performing user experiences without lag. Use execute-entity or execute-entities actions with DATA_PROVIDER_REST or DATA_PROVIDER_SQL. Specify the function call to make, the local entity/table to update, and the method to perform on the local table. If the method is an update, delete, or save, specify the record's ID.
- Save data to the cloud ONLY Use execute-entity or execute-entities actions with DATA_PROVIDER_REST or DATA_PROVIDER_SQL. Specify the function call to make; don't specify the local /table to update. Set the method to functionCall. The local tables will not be updated; you must sync the data from the cloud before it is available to display on a .
automatically syncs its data with the cloud when server-side or device-side updates are made to the tables, using DATA_PROVIDER_DYNAMIC
- Use the sync-entity/entities action to sync data from the remote data store (REST and SQL) to the local SQLite data provider. Syncing data locally results in hig performance with minimal lag and ensurese that all data is available in the app when the device is offline.
- Best practice is to configure a global action, the sync-entity/entities action, with the REST or SQL data provider, allowing reuse throughout the solution.
- Add the global sync action to the onFocus and onLoad events in the index.jigx file ensures data is synced to the local data provider as soon as the app loads or is focused on the device.
- Add the global sync action to the onRefresh or onFocus events in a when data is changed, for example, on the list of customers, this ensures that when a new customer is created, the list is updated immediately when navigating to it or refreshing the list with a downward swipe.
There are two options when using the execute-enitity and execute- entities actions with remote data such as REST or SQL.
Configure the actions to update BOTH the local SQLite table and the remote data store (REST and SQL). To update the local table, specify one of the CRUD methods in the method property of the data provider. To update the remote data store (REST or SQL), specify the function to use in the function property, and under functionParameters, specify the exact data to be updated.
Configure actions to ONLY update the remote data store (REST and SQL). To update the remote data store specify functionCall in the method property. Then specify the function to be called in the function property and under functionParameters specify the exact data to be updated. Note that the data will not be visible on the until a sync-entities action is executed.
- Using the save method in execute-entity/entities will perform an upsert in the local SQLite table.
- Dealing with offline remote data is fundamental to ensuring data synchronization and consistency between the mobile app and the remote data source, allowing users to continue using the app and performing actions without interruption. Offline remote data handling explains how to configure solutions to deal with data when the device is offline.
- Once the data has been synced using the sync actions the data is available in the local data provider.
- Reference the local data provider in the 's datasource property to define the data required in the .
- Write a SQLite query to define the exact data required.
- Use IntelliSence and expressions to reference the specific datasource values to use in each component, such as data: =@ctx.datasources.customers