Skip to content

Commit cb1373d

Browse files
committed
Add docs
1 parent c87e079 commit cb1373d

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

core/src/commonMain/kotlin/com/powersync/PowerSyncDatabase.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ public interface PowerSyncDatabase : Queries {
216216
*
217217
* In this case, PowerSync will not open its own SQLite connections, but rather refer to
218218
* connections in the [pool].
219+
*
220+
* The `group` parameter should likely be teh result of calling [databaseGroup] - this is
221+
* responsible for ensuring two instances of the same database file don't sync at the same
222+
* time. So, a value that uniquely identifies the database should be passed to
223+
* [databaseGroup].
219224
*/
220225
@ExperimentalPowerSyncAPI
221226
public fun opened(
@@ -234,6 +239,7 @@ public interface PowerSyncDatabase : Queries {
234239
)
235240
}
236241

242+
@ExperimentalPowerSyncAPI
237243
public fun databaseGroup(logger: Logger, identifier: String): Pair<ActiveDatabaseResource, Any> {
238244
return ActiveDatabaseGroup.referenceDatabase(logger, identifier)
239245
}

core/src/commonMain/kotlin/com/powersync/db/driver/SQLiteConnectionPool.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,45 @@ import com.powersync.ExperimentalPowerSyncAPI
55
import kotlinx.coroutines.flow.SharedFlow
66
import kotlinx.coroutines.runBlocking
77

8+
/**
9+
* An implementation of a connection pool providing asynchronous access to a single writer
10+
* and multiple readers.
11+
*
12+
* This is the underlying pool implementation on which the higher-level PowerSync Kotlin SDK is
13+
* built on. The SDK provides its own pool, but can also use existing implementations (via
14+
* [com.powersync.PowerSyncDatabase.opened]).
15+
*/
816
@ExperimentalPowerSyncAPI()
917
public interface SQLiteConnectionPool {
18+
/**
19+
* Calls the callback with a read-only connection temporarily leased from the pool.
20+
*/
1021
public suspend fun <T> read(callback: suspend (SQLiteConnectionLease) -> T): T
22+
23+
/**
24+
* Calls the callback with a read-write connection temporarily leased from the pool.
25+
*/
1126
public suspend fun <T> write(callback: suspend (SQLiteConnectionLease) -> T): T
1227

28+
/**
29+
* Invokes the callback with all connections leased from the pool.
30+
*/
1331
public suspend fun <R> withAllConnections(action: suspend (
1432
writer: SQLiteConnectionLease,
1533
readers: List<SQLiteConnectionLease>
1634
) -> R)
1735

36+
/**
37+
* Returns a flow of table updates made on the [write] connection.
38+
*/
1839
public val updates: SharedFlow<Set<String>>
1940

41+
/**
42+
* Closes the connection pool and associated resources.
43+
*
44+
* Calling [read], [write] and [withAllConnections] after calling [close] should result in an
45+
* exception.
46+
*/
2047
public suspend fun close()
2148
}
2249

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ kotlinx-datetime = "0.7.1"
1616
kotlinx-io = "0.8.0"
1717
ktor = "3.2.3"
1818
uuid = "0.8.4"
19-
powersync-core = "0.4.4"
19+
powersync-core = "0.4.5"
2020
turbine = "1.2.1"
2121
kotest = "5.9.1" # we can't upgrade to 6.x because that requires Java 11 or above (we need Java 8 support)
2222

0 commit comments

Comments
 (0)