Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -1,12 +1,13 @@
package com.powersync.db.internal

import app.cash.sqldelight.db.Closeable
import com.persistence.PowersyncQueries
import com.powersync.PsSqlDriver
import com.powersync.db.Queries
import com.powersync.persistence.PsDatabase
import kotlinx.coroutines.flow.Flow

internal interface InternalDatabase : Queries {
internal interface InternalDatabase : Queries, Closeable {
val driver: PsSqlDriver
val transactor: PsDatabase
val queries: PowersyncQueries
Expand Down
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
Loading