Data Sync
Syncing Data
this article provides instructions on how to create, retrieve, and cancel sync subscriptions dql sync subscriptions are supported for devices on version 4 5 or later devices on ditto versions 4 4 or earlier are supported, however, they do not sync data through dql subscriptions to get your active subscriptions, call the subscriptions method on the ditto sync namespace ( /#retrieving subscriptions ) to cancel a subscription, call cancel on its subscription object you instantiated when setting up your subscription ( /#canceling subscriptions ) to confirm cancelation, call the iscancelled field on the subscription object ( /#canceling subscriptions ) creating subscriptions to register a new sync subscription in your app for example, the following snippet demonstrates how to establish a subscription to sync updates to documents in the cars collection with a field of color set to the value blue ditto sync registersubscription("select from cars")ditto sync registersubscription("select from cars")ditto sync registersubscription("select from cars")ditto sync registersubscription("select from cars")ditto sync registersubscription("select from cars");auto subscription = ditto sync() register subscription("select from cars");let subscription = ditto sync() register subscription("select from cars", none);await ditto sync registersubscription("select from cars"); sync subscriptions also support argument injection using the \ argument syntax in dql ditto sync registersubscription(""" select from cars where color = \ color """, \[ "color" "blue" ])ditto sync registersubscription(""" select from cars where color = \ color """, mapof("color" to "blue"))ditto sync registersubscription(` select from cars where color = \ color`, { color 'blue' })ditto sync registersubscription( "select from cars where color = \ color", collections singletonmap("color", "blue"))var queryarguments = new dictionary\<string, object>(){{"color", "blue" }}; ditto sync registersubscription( "select from cars where color = 'blue'", queryarguments);ditto sync() register subscription( "select from cars where color = \ color", {{"color", "blue"}});struct args { color string, } // let args = args { color "blue" to string(), }; ditto sync() register subscription( "select from cars where color = \ color", args);await ditto sync registersubscription(""" select from cars where color = \ color""", arguments {"color" "blue"}, ); retrieving subscriptions retrieve active sync subscriptions by calling the subscriptions method on the ditto sync namespace let activesubscriptions = ditto sync subscriptions;val activesubscriptions = ditto sync subscriptionsconst activesubscriptions = ditto sync subscriptionsdittosyncsubscription\[] activesubscriptions = ditto sync subscriptions;var activesubscriptions = ditto sync subscriptions;// not supported hold the reference to the syncsubscription object // not supported hold the reference to the syncsubscription object final activesubscriptions = ditto sync subscriptions; canceling subscriptions to cancel a subscription, call cancel on the subscription object you set up to establish your subscription subscription cancel()subscription close()subscription cancel()subscription close()subscription cancel();// // await subscription cancel() check if a sync subscription is canceled by using the iscancelled field on the subscription object subscription iscancelledsubscription isclosedsubscription iscancelledsubscription iscancelledsubscription iscancelled// // subscription iscancelled