connect
Connect to the PowerSync service, and keep the databases in sync.
The connection is automatically re-opened if it fails for any reason.
Use @param connector to specify the PowerSyncBackendConnector. Use @param options for additional options configuring the connection to the PowerSync service. See SyncOptions for details.
Example usage:
connect(
connector = connector,
options = SyncOptions(
crudThrottle = 2.seconds,
retryDelay = 10.seconds,
params = mapOf(
"name" to JsonParam.String("John Doe"),
"age" to JsonParam.Number(30),
"isStudent" to JsonParam.Boolean(false)
),
appMetadata = mapOf(
"appVersion" to "1.0.0",
"deviceId" to "device456"
)
),
)Connects to a PowerSync endpoint.
Unlike the method accepting a PowerSyncBackendConnector, this allows passing independent Authenticator and MutationUploaders. Passing only one of them connects the database for downloads or uploads only.
Each call replaces all prior connections. In particular, calling this method once with only an Authenticator (for download-only sync) and later with only a MutationUploader (for upload-only sync) would put the database into upload-only mode. They aren't combined into a full bidirectional sync mode.
Connects in upload-only mode.
This doesn't require a PowerSync endpoint or authenticator resolving JWT. It does not connect to a PowerSync service at all. It only observes local mutations, which are forwarded to MutationUploader.
Deprecated
Use connect() method without crudThrottleMs, retryDelayMs, params and appMetadata parameters (pass them via SyncOptions instead).
Connect to the PowerSync service, and keep the databases in sync.
The connection is automatically re-opened if it fails for any reason.
Use @param connector to specify the PowerSyncBackendConnector. Use @param crudThrottleMs to specify the time between CRUD operations. Defaults to 1000ms. Use @param retryDelayMs to specify the delay between retries after failure. Defaults to 5000ms. Use @param params to specify sync parameters from the client. Use @param appMetadata to specify application metadata that will be displayed in PowerSync service logs.
Example usage:
val params = JsonParam.Map(
mapOf(
"name" to JsonParam.String("John Doe"),
"age" to JsonParam.Number(30),
"isStudent" to JsonParam.Boolean(false)
)
)
val appMetadata = mapOf(
"appVersion" to "1.0.0",
"deviceId" to "device456"
)
connect(
connector = connector,
crudThrottleMs = 2000L,
retryDelayMs = 10000L,
params = params,
appMetadata = appMetadata
)