Step-by-step DB Sync client app implementation
This guide outlines the step-by-step implementation process for creating a DB Sync client
application, detailing key components and functionalities required for seamless data
syncing.
Import the DB Sync API modules Import the necessary DB Sync API modules for DB Sync client app functionality.Initialize the DB Sync API Initialize the DB Sync API by calling the module's initialization function.Declare the database schema The DB Sync client application must declare the database schema by registering a JSON schema file using the dbsync_app.register_local_dbschema()
function.Initialize the SQLite local database To initialize an local SQLite database for a mobile app, check that the local database does not already exist; if it does not exist, retrieve a copy from the DB Sync server.Register sync source parameters Configure and register DB Sync source parameters by defining and loading a source record from a configuration file, then register the source parameters.User authentication in direct mode In direct mode, user authentication involves defining a DB Sync user record, registering the user ID and password (if applicable), with the password encrypted server-side during the process.User authenticating with GAS/SSO/GIP Provides a code example for initializing SSO user authentication using OAuthAPI, including fetching metadata, retrieving a password token, and initializing a native app with user credentials.Declare application SQL tables The DB Sync client app must declare (register) local tables for synchronization. Hardcoding the table list is recommended for offline scenarios.Data changes: Row creation (INSERT) To insert a new row with a serial or sequence primary key, generate a local unique negative ID, include the auto-incremented column in the INSERT statement, and register the change in the local sync log. Handle errors with rollback mechanisms to ensure data integrity.Data changes: Row change (UPDATE) To manage data row modifications, use dbsync_app.register_local_update()
for complete row changes or dbsync_app.register_local_change()
for field-specific updates to minimize conflicts. Compact the changes log with dbsync_app.compact_local_changes()
to optimize synchronization and resolve potential conflicts.Data changes: Row removal (DELETE) To delete a row with a DB Sync client app, first register the deletion, then perform the DELETE operation.Synchronizing with central database The database synchronization process involves fetching central changes and sending local updates to the server, ensuring data consistency across users and applications. It includes initializing each synchronization attempt, handling local changes, applying server updates, and managing failures through conflict resolution or database resets.Cleanup the DB Sync API Terminate the DB Sync client app by invoking the cleanup routine to release resources allocated by the DB Sync client API library.