connect

abstract suspend fun connect(connector: PowerSyncBackendConnector, options: SyncOptions = SyncOptions())(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 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"
)
),
)

abstract suspend fun connect(connector: PowerSyncBackendConnector, crudThrottleMs: Long = SyncOptions.DEFAULT_CRUD_THROTTLE_MS, retryDelayMs: Long = SyncOptions.DEFAULT_RETRY_DELAY_MS, params: Map<String, JsonParam?> = emptyMap(), options: SyncOptions = SyncOptions(), appMetadata: Map<String, String> = emptyMap())(source)

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
)