Skip to content

Commit db15c9b

Browse files
committed
Review feedback
1 parent 51521d8 commit db15c9b

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,30 @@ public interface PowerSyncDatabase : Queries {
217217
* In this case, PowerSync will not open its own SQLite connections, but rather refer to
218218
* connections in the [pool].
219219
*
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].
220+
* The `identifier` parameter should be a name identifying the path of the database. The
221+
* PowerSync SDK will emit a warning if multiple databases are opened with the same
222+
* identifier, and uses internal locks to ensure these two databases are not synced at the
223+
* same time (which would be inefficient and can cause consistency issues).
224224
*/
225225
@ExperimentalPowerSyncAPI
226226
public fun opened(
227227
pool: SQLiteConnectionPool,
228228
scope: CoroutineScope,
229229
schema: Schema,
230-
group: Pair<ActiveDatabaseResource, Any>,
230+
identifier: String,
231231
logger: Logger,
232+
): PowerSyncDatabase {
233+
val group = ActiveDatabaseGroup.referenceDatabase(logger, identifier)
234+
return openedWithGroup(pool, scope, schema, logger, group)
235+
}
236+
237+
@ExperimentalPowerSyncAPI
238+
internal fun openedWithGroup(
239+
pool: SQLiteConnectionPool,
240+
scope: CoroutineScope,
241+
schema: Schema,
242+
logger: Logger,
243+
group: Pair<ActiveDatabaseResource, Any>,
232244
): PowerSyncDatabase =
233245
PowerSyncDatabaseImpl(
234246
schema,
@@ -237,11 +249,5 @@ public interface PowerSyncDatabase : Queries {
237249
logger,
238250
group,
239251
)
240-
241-
@ExperimentalPowerSyncAPI
242-
public fun databaseGroup(
243-
logger: Logger,
244-
identifier: String,
245-
): Pair<ActiveDatabaseResource, Any> = ActiveDatabaseGroup.referenceDatabase(logger, identifier)
246252
}
247253
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ internal fun createPowerSyncDatabaseImpl(
6666
)
6767
}
6868

69-
return PowerSyncDatabase.opened(
69+
return PowerSyncDatabase.openedWithGroup(
7070
pool,
7171
scope,
7272
schema,
73-
activeDatabaseGroup,
7473
logger,
74+
activeDatabaseGroup,
7575
) as PowerSyncDatabaseImpl
7676
}

core/src/commonMain/kotlin/com/powersync/db/ActiveInstanceStore.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ internal class ActiveDatabaseGroup(
8282
}
8383
}
8484

85-
public class ActiveDatabaseResource internal constructor(
86-
internal val group: ActiveDatabaseGroup,
85+
internal class ActiveDatabaseResource(
86+
val group: ActiveDatabaseGroup,
8787
) {
88-
internal val disposed = AtomicBoolean(false)
88+
val disposed = AtomicBoolean(false)
8989

90-
internal fun dispose() {
90+
fun dispose() {
9191
if (disposed.compareAndSet(false, true)) {
9292
group.removeUsage()
9393
}

0 commit comments

Comments
 (0)