connect
abstract suspend fun connect(connector: PowerSyncBackendConnector, crudThrottleMs: Long = 1000, retryDelayMs: Long = 5000, params: Map<String, JsonParam?> = emptyMap(), options: SyncOptions = SyncOptions(), appMetadata: Map<String, String> = emptyMap())(source)
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
)Content copied to clipboard