diff --git a/CHANGELOG.md b/CHANGELOG.md index 79b5d4f..d7e7c24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.0.0-BETA16 + +* Add `close` method to database methods + ## 1.0.0-BETA15 * Update powersync-sqlite-core to 0.3.8 diff --git a/core/src/commonMain/kotlin/com/powersync/PowerSyncDatabase.kt b/core/src/commonMain/kotlin/com/powersync/PowerSyncDatabase.kt index 27c6adf..888751e 100644 --- a/core/src/commonMain/kotlin/com/powersync/PowerSyncDatabase.kt +++ b/core/src/commonMain/kotlin/com/powersync/PowerSyncDatabase.kt @@ -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() } diff --git a/core/src/commonMain/kotlin/com/powersync/db/PowerSyncDatabaseImpl.kt b/core/src/commonMain/kotlin/com/powersync/db/PowerSyncDatabaseImpl.kt index edabc3b..9db82c2 100644 --- a/core/src/commonMain/kotlin/com/powersync/db/PowerSyncDatabaseImpl.kt +++ b/core/src/commonMain/kotlin/com/powersync/db/PowerSyncDatabaseImpl.kt @@ -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. */ diff --git a/core/src/commonMain/kotlin/com/powersync/db/internal/InternalDatabase.kt b/core/src/commonMain/kotlin/com/powersync/db/internal/InternalDatabase.kt index d894e24..672dda4 100644 --- a/core/src/commonMain/kotlin/com/powersync/db/internal/InternalDatabase.kt +++ b/core/src/commonMain/kotlin/com/powersync/db/internal/InternalDatabase.kt @@ -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 diff --git a/core/src/commonMain/kotlin/com/powersync/db/internal/InternalDatabaseImpl.kt b/core/src/commonMain/kotlin/com/powersync/db/internal/InternalDatabaseImpl.kt index 9c5fb36..956dd09 100644 --- a/core/src/commonMain/kotlin/com/powersync/db/internal/InternalDatabaseImpl.kt +++ b/core/src/commonMain/kotlin/com/powersync/db/internal/InternalDatabaseImpl.kt @@ -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, diff --git a/demos/hello-powersync/iosApp/iosApp.xcodeproj/project.pbxproj b/demos/hello-powersync/iosApp/iosApp.xcodeproj/project.pbxproj index 9481617..1625063 100644 --- a/demos/hello-powersync/iosApp/iosApp.xcodeproj/project.pbxproj +++ b/demos/hello-powersync/iosApp/iosApp.xcodeproj/project.pbxproj @@ -106,6 +106,7 @@ 7555FF79242A565900829871 /* Resources */, EF8A45596C10845FBC80C40F /* Frameworks */, BDEF1F2128374088F98D10FB /* [CP] Embed Pods Frameworks */, + 2A09661A10CA625857E1B999 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -162,6 +163,23 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ + 2A09661A10CA625857E1B999 /* [CP] Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Copy Pods Resources"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources-${CONFIGURATION}-output-files.xcfilelist", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; BDEF1F2128374088F98D10FB /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; diff --git a/gradle.properties b/gradle.properties index 65452f4..3fd4fbb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ development=true RELEASE_SIGNING_ENABLED=true # Library config GROUP=com.powersync -LIBRARY_VERSION=1.0.0-BETA15 +LIBRARY_VERSION=1.0.0-BETA16 GITHUB_REPO=https://github.com/powersync-ja/powersync-kotlin.git # POM POM_URL=https://github.com/powersync-ja/powersync-kotlin/