Skip to content

Commit

Permalink
feat: expose close method
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicGBauer committed Jan 13, 2025
1 parent aea2ac9 commit 4ead569
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/src/commonMain/kotlin/com/powersync/PowerSyncDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,12 @@ public interface PowerSyncDatabase : Queries {
* To preserve data in local-only tables, set clearLocal to false.
*/
public suspend fun disconnectAndClear(clearLocal: Boolean = true)

/**
* Close the database, releasing resources.
* Also disconnects any active connection.
*
* Once close is called, this database cannot be used again - a new one must be constructed.
*/
public suspend fun close()
}
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ internal class PowerSyncDatabaseImpl(
}
}

override suspend fun close() {
disconnect()
internalDb.close()
}

/**
* Check that a supported version of the powersync extension is loaded.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ internal interface InternalDatabase : Queries {
fun getExistingTableNames(tableGlob: String): List<String>

fun updatesOnTable(tableName: String): Flow<Unit>

fun close()
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ internal class InternalDatabaseImpl(
return existingTableNames
}

override fun close() {
this.driver.close()
}

internal data class ExplainQueryResult(
val addr: String,
val opcode: String,
Expand Down

0 comments on commit 4ead569

Please sign in to comment.