Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose close method #103

Merged
merged 5 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
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
18 changes: 18 additions & 0 deletions demos/hello-powersync/iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
7555FF79242A565900829871 /* Resources */,
EF8A45596C10845FBC80C40F /* Frameworks */,
BDEF1F2128374088F98D10FB /* [CP] Embed Pods Frameworks */,
2A09661A10CA625857E1B999 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
Loading