WebConnectionFactory
An asynchronous connection factory opening databases hosted in a web worker.
Note that web support in the Kotlin SDK is currently both experimental and incomplete and should only be used for testing.
To open a SQLiteConnectionPool that can be used with com.powersync.PowerSyncDatabase.opened classes, use WebConnectionFactory.openPool, e.g. like this:
fun openPowerSyncDatabase(): PowerSyncDatabase {
val scope = GlobalScope
val identifier = "demo.db"
val factory = WebConnectionFactory(scope)
return PowerSyncDatabase.opened(
pool = factory.openPool { open(identifier) }
scope = scope
schema = Schema(...),
identifier = identifier,
logger = Logger(loggerConfigInit(platformLogWriter()))
)
}Content copied to clipboard
Constructors
Link copied to clipboard
constructor(coroutineScope: CoroutineScope = GlobalScope, wasmUri: String = sqlite3WasmUri(), workers: PowerSyncWorkerConnector = PowerSyncWorkerConnector())
Functions
Link copied to clipboard
Opens a database with the recommended implementation.
suspend fun open(databaseName: String, implementation: DatabaseImplementation): SQLiteConnectionPool
Opens a database with a known DatabaseImplementation.
suspend fun open(databaseName: String, pickImplementation: (RawFeatureDetectionResult) -> DatabaseImplementation): SQLiteConnectionPool
Starts a feature detection for available DatabaseImplementations in the current browser, then runs pickImplementation to query with implementation to use.
Link copied to clipboard
fun openPool(openInner: suspend WebConnectionFactory.() -> SQLiteConnectionPool): SQLiteConnectionPool
Turns the asynchronous open methods on this class into a method that can return as connection pool synchronously.