Skip to content

Commit aa4e7bc

Browse files
committed
Fix lints
1 parent cb1373d commit aa4e7bc

File tree

18 files changed

+112
-113
lines changed

18 files changed

+112
-113
lines changed

core/src/androidMain/kotlin/com/powersync/DatabaseDriverFactory.android.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import androidx.sqlite.driver.bundled.BundledSQLiteDriver
77
public actual class DatabaseDriverFactory(
88
private val context: Context,
99
) {
10-
internal actual fun resolveDefaultDatabasePath(dbFilename: String): String {
11-
return context.getDatabasePath(dbFilename).path
12-
}
10+
internal actual fun resolveDefaultDatabasePath(dbFilename: String): String = context.getDatabasePath(dbFilename).path
1311
}
1412

1513
public actual fun BundledSQLiteDriver.addPowerSyncExtension() {

core/src/appleMain/kotlin/com/powersync/DatabaseDriverFactory.apple.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package com.powersync
22

33
import kotlinx.cinterop.UnsafeNumber
44
import platform.Foundation.NSApplicationSupportDirectory
5+
import platform.Foundation.NSBundle
56
import platform.Foundation.NSFileManager
67
import platform.Foundation.NSSearchPathForDirectoriesInDomains
78
import platform.Foundation.NSUserDomainMask
9+
import kotlin.getValue
810

911
@OptIn(UnsafeNumber::class)
1012
internal fun appleDefaultDatabasePath(dbFilename: String): String {
@@ -22,3 +24,17 @@ internal fun appleDefaultDatabasePath(dbFilename: String): String {
2224

2325
return databaseDirectory
2426
}
27+
28+
internal val powerSyncExtensionPath: String by lazy {
29+
// Try and find the bundle path for the SQLite core extension.
30+
val bundlePath =
31+
NSBundle.bundleWithIdentifier("co.powersync.sqlitecore")?.bundlePath
32+
?: // The bundle is not installed in the project
33+
throw PowerSyncException(
34+
"Please install the PowerSync SQLite core extension",
35+
cause = Exception("The `co.powersync.sqlitecore` bundle could not be found in the project."),
36+
)
37+
38+
// Construct full path to the shared library inside the bundle
39+
bundlePath.let { "$it/powersync-sqlite-core" }
40+
}

core/src/appleNonWatchOsMain/kotlin/com/powersync/DatabaseDriverFactory.appleNonWatchOs.kt

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,9 @@ import kotlin.getValue
66

77
@Suppress(names = ["EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING"])
88
public actual class DatabaseDriverFactory {
9-
internal actual fun resolveDefaultDatabasePath(dbFilename: String): String {
10-
return appleDefaultDatabasePath(dbFilename)
11-
}
9+
internal actual fun resolveDefaultDatabasePath(dbFilename: String): String = appleDefaultDatabasePath(dbFilename)
1210
}
1311

1412
public actual fun BundledSQLiteDriver.addPowerSyncExtension() {
1513
addExtension(powerSyncExtensionPath, "sqlite3_powersync_init")
1614
}
17-
18-
private val powerSyncExtensionPath: String by lazy {
19-
// Try and find the bundle path for the SQLite core extension.
20-
val bundlePath =
21-
NSBundle.bundleWithIdentifier("co.powersync.sqlitecore")?.bundlePath
22-
?: // The bundle is not installed in the project
23-
throw PowerSyncException(
24-
"Please install the PowerSync SQLite core extension",
25-
cause = Exception("The `co.powersync.sqlitecore` bundle could not be found in the project."),
26-
)
27-
28-
// Construct full path to the shared library inside the bundle
29-
bundlePath.let { "$it/powersync-sqlite-core" }
30-
}

core/src/appleTest/kotlin/com/powersync/DatabaseDriverFactoryTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class DatabaseDriverFactoryTest {
1010
if (Platform.osFamily != OsFamily.WATCHOS) {
1111
// On watchOS targets, there's no special extension path because we expect to link the
1212
// PowerSync extension statically due to platform restrictions.
13-
DatabaseDriverFactory.powerSyncExtensionPath
13+
powerSyncExtensionPath
1414
}
1515
}
1616
}

core/src/commonIntegrationTest/kotlin/com/powersync/DatabaseTest.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.powersync
22

3-
import app.cash.turbine.test
43
import androidx.sqlite.SQLiteConnection
54
import androidx.sqlite.execSQL
5+
import app.cash.turbine.test
66
import app.cash.turbine.turbineScope
77
import co.touchlab.kermit.ExperimentalKermitApi
88
import com.powersync.db.ActiveDatabaseGroup
@@ -527,21 +527,22 @@ class DatabaseTest {
527527
databaseTest {
528528
val didWrite = CompletableDeferred<Unit>()
529529

530-
val job = scope.launch {
531-
database.useConnection(readOnly = false) { raw ->
532-
raw.usePrepared("INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)") { stmt ->
533-
stmt.bindText(1, "name")
534-
stmt.bindText(2, "email")
535-
stmt.step() shouldBe false
530+
val job =
531+
scope.launch {
532+
database.useConnection(readOnly = false) { raw ->
533+
raw.usePrepared("INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)") { stmt ->
534+
stmt.bindText(1, "name")
535+
stmt.bindText(2, "email")
536+
stmt.step() shouldBe false
536537

537-
stmt.reset()
538-
stmt.step() shouldBe false
539-
}
538+
stmt.reset()
539+
stmt.step() shouldBe false
540+
}
540541

541-
didWrite.complete(Unit)
542-
awaitCancellation()
542+
didWrite.complete(Unit)
543+
awaitCancellation()
544+
}
543545
}
544-
}
545546

546547
didWrite.await()
547548
database.getAll("SELECT * FROM users") { it.getString("name") } shouldHaveSize 2

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ internal fun openDatabase(
3737
}
3838

3939
driver.addPowerSyncExtension()
40-
return driver.open(dbPath, if (readOnly) {
41-
SQLITE_OPEN_READONLY
42-
} else {
43-
SQLITE_OPEN_READWRITE or SQLITE_OPEN_CREATE
44-
})
40+
return driver.open(
41+
dbPath,
42+
if (readOnly) {
43+
SQLITE_OPEN_READONLY
44+
} else {
45+
SQLITE_OPEN_READWRITE or SQLITE_OPEN_CREATE
46+
},
47+
)
4548
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,19 +229,19 @@ public interface PowerSyncDatabase : Queries {
229229
schema: Schema,
230230
group: Pair<ActiveDatabaseResource, Any>,
231231
logger: Logger,
232-
): PowerSyncDatabase {
233-
return PowerSyncDatabaseImpl(
232+
): PowerSyncDatabase =
233+
PowerSyncDatabaseImpl(
234234
schema,
235235
scope,
236236
pool,
237237
logger,
238238
group,
239239
)
240-
}
241240

242241
@ExperimentalPowerSyncAPI
243-
public fun databaseGroup(logger: Logger, identifier: String): Pair<ActiveDatabaseResource, Any> {
244-
return ActiveDatabaseGroup.referenceDatabase(logger, identifier)
245-
}
242+
public fun databaseGroup(
243+
logger: Logger,
244+
identifier: String,
245+
): Pair<ActiveDatabaseResource, Any> = ActiveDatabaseGroup.referenceDatabase(logger, identifier)
246246
}
247247
}

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,14 @@ internal fun createPowerSyncDatabaseImpl(
5454
val identifier = dbDirectory + dbFilename
5555
val activeDatabaseGroup = ActiveDatabaseGroup.referenceDatabase(logger, identifier)
5656

57-
val pool = InternalConnectionPool(
58-
factory,
59-
scope,
60-
dbFilename,
61-
dbDirectory,
62-
activeDatabaseGroup.first.group.writeLockMutex
63-
)
57+
val pool =
58+
InternalConnectionPool(
59+
factory,
60+
scope,
61+
dbFilename,
62+
dbDirectory,
63+
activeDatabaseGroup.first.group.writeLockMutex,
64+
)
6465

6566
return PowerSyncDatabase.opened(
6667
pool,

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,12 @@ internal class PowerSyncDatabaseImpl(
325325
@ExperimentalPowerSyncAPI
326326
override suspend fun <T> useConnection(
327327
readOnly: Boolean,
328-
block: suspend (SQLiteConnectionLease) -> T
328+
block: suspend (SQLiteConnectionLease) -> T,
329329
): T {
330330
waitReady()
331331
return internalDb.useConnection(readOnly, block)
332332
}
333333

334-
335334
override suspend fun <RowType : Any> get(
336335
sql: String,
337336
parameters: List<Any?>?,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,5 +198,8 @@ public interface Queries {
198198
*/
199199
@ExperimentalPowerSyncAPI()
200200
@HiddenFromObjC()
201-
public suspend fun <T> useConnection(readOnly: Boolean = false, block: suspend (SQLiteConnectionLease) -> T): T
201+
public suspend fun <T> useConnection(
202+
readOnly: Boolean = false,
203+
block: suspend (SQLiteConnectionLease) -> T,
204+
): T
202205
}

0 commit comments

Comments
 (0)