Skip to content

Commit a318aea

Browse files
committed
Ignore generated code for linting
1 parent bff3fd7 commit a318aea

File tree

9 files changed

+137
-123
lines changed

9 files changed

+137
-123
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ public fun BundledSQLiteDriver.addPowerSyncExtension() {
2222
addExtension("libpowersync.so", "sqlite3_powersync_init")
2323
}
2424

25+
@ExperimentalPowerSyncAPI
2526
public actual fun resolvePowerSyncLoadableExtensionPath(): String? = "libpowersync.so"

integrations/room/build.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import com.powersync.plugins.sonatype.setupGithubRepository
22
import com.powersync.plugins.utils.powersyncTargets
3+
import org.jmailen.gradle.kotlinter.tasks.FormatTask
4+
import org.jmailen.gradle.kotlinter.tasks.LintTask
35

46
plugins {
57
alias(libs.plugins.kotlinMultiplatform)
@@ -87,3 +89,11 @@ setupGithubRepository()
8789
dokka {
8890
moduleName.set("PowerSync Room Integration")
8991
}
92+
93+
tasks.withType<LintTask> {
94+
exclude { it.file.path.contains("build/generated") }
95+
}
96+
97+
tasks.withType<FormatTask> {
98+
exclude { it.file.path.contains("build/generated") }
99+
}
File renamed without changes.

integrations/room/src/commonMain/kotlin/com/powersync/integrations/room/RoomConnectionPool.kt

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import kotlin.coroutines.CoroutineContext
2929
*/
3030
public class RoomConnectionPool(
3131
private val db: RoomDatabase,
32-
): SQLiteConnectionPool {
32+
) : SQLiteConnectionPool {
3333
private val _updates = MutableSharedFlow<Set<String>>()
3434
private var hasInstalledUpdateHook = false
3535

@@ -41,11 +41,10 @@ public class RoomConnectionPool(
4141
}
4242
}
4343

44-
override suspend fun <T> read(callback: suspend (SQLiteConnectionLease) -> T): T {
45-
return db.useReaderConnection {
44+
override suspend fun <T> read(callback: suspend (SQLiteConnectionLease) -> T): T =
45+
db.useReaderConnection {
4646
callback(RoomTransactionLease(it, currentCoroutineContext()))
4747
}
48-
}
4948

5049
/**
5150
* Makes pending updates tracked by Room's invalidation tracker available to the PowerSync
@@ -57,8 +56,8 @@ public class RoomConnectionPool(
5756
}
5857
}
5958

60-
override suspend fun <T> write(callback: suspend (SQLiteConnectionLease) -> T): T {
61-
return db.useWriterConnection {
59+
override suspend fun <T> write(callback: suspend (SQLiteConnectionLease) -> T): T =
60+
db.useWriterConnection {
6261
if (!hasInstalledUpdateHook) {
6362
hasInstalledUpdateHook = true
6463
it.execSQL("SELECT powersync_update_hooks('install')")
@@ -67,14 +66,17 @@ public class RoomConnectionPool(
6766
try {
6867
callback(RoomTransactionLease(it, currentCoroutineContext()))
6968
} finally {
70-
val changed = it.usePrepared("SELECT powersync_update_hooks('get')") { stmt ->
71-
check(stmt.step())
72-
json.decodeFromString<Set<String>>(stmt.getText(0))
73-
}
74-
75-
val userTables = changed.filter { tbl ->
76-
!tbl.startsWith("ps_") && !tbl.startsWith("room_")
77-
}.toTypedArray()
69+
val changed =
70+
it.usePrepared("SELECT powersync_update_hooks('get')") { stmt ->
71+
check(stmt.step())
72+
json.decodeFromString<Set<String>>(stmt.getText(0))
73+
}
74+
75+
val userTables =
76+
changed
77+
.filter { tbl ->
78+
!tbl.startsWith("ps_") && !tbl.startsWith("room_")
79+
}.toTypedArray()
7880

7981
if (userTables.isNotEmpty()) {
8082
db.invalidationTracker.refresh(*userTables)
@@ -83,7 +85,6 @@ public class RoomConnectionPool(
8385
_updates.emit(changed)
8486
}
8587
}
86-
}
8788

8889
override val updates: SharedFlow<Set<String>>
8990
get() = _updates
@@ -103,28 +104,25 @@ private class RoomTransactionLease(
103104
* The context to use for [runBlocking] calls to avoid the "Attempted to use connection on a
104105
* different coroutine" error.
105106
*/
106-
private val context: CoroutineContext
107-
): SQLiteConnectionLease {
108-
override suspend fun isInTransaction(): Boolean {
109-
return transactor.inTransaction()
110-
}
107+
private val context: CoroutineContext,
108+
) : SQLiteConnectionLease {
109+
override suspend fun isInTransaction(): Boolean = transactor.inTransaction()
111110

112111
override suspend fun <R> usePrepared(
113112
sql: String,
114-
block: (SQLiteStatement) -> R
115-
): R {
116-
return transactor.usePrepared(sql, block)
117-
}
113+
block: (SQLiteStatement) -> R,
114+
): R = transactor.usePrepared(sql, block)
118115

119-
override fun isInTransactionSync(): Boolean {
120-
return runBlocking(context) {
116+
override fun isInTransactionSync(): Boolean =
117+
runBlocking(context) {
121118
isInTransaction()
122119
}
123-
}
124120

125-
override fun <R> usePreparedSync(sql: String, block: (SQLiteStatement) -> R): R {
126-
return runBlocking(context) {
121+
override fun <R> usePreparedSync(
122+
sql: String,
123+
block: (SQLiteStatement) -> R,
124+
): R =
125+
runBlocking(context) {
127126
usePrepared(sql, block)
128127
}
129-
}
130128
}

integrations/room/src/commonTest/kotlin/com/powersync/integrations/room/PowerSyncRoomTest.kt

Lines changed: 95 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import kotlin.test.BeforeTest
1414
import kotlin.test.Test
1515

1616
class PowerSyncRoomTest {
17-
1817
lateinit var database: TestDatabase
1918

2019
@BeforeTest
2120
fun setup() {
22-
val driver = BundledSQLiteDriver().also {
23-
it.loadPowerSyncExtension()
24-
}
21+
val driver =
22+
BundledSQLiteDriver().also {
23+
it.loadPowerSyncExtension()
24+
}
2525

2626
database = createDatabaseBuilder().setDriver(driver).build()
2727
}
@@ -32,96 +32,107 @@ class PowerSyncRoomTest {
3232
}
3333

3434
@Test
35-
fun roomWritePowerSyncRead() = runTest {
36-
database.userDao().create(User(id = "test", name = "Test user"))
37-
val logger = Logger(loggerConfigInit())
38-
39-
val powersync = PowerSyncDatabase.opened(
40-
pool = RoomConnectionPool(database),
41-
scope = this,
42-
schema = TestDatabase.schema,
43-
identifier = "test",
44-
logger = logger,
45-
)
46-
47-
val row = powersync.get("SELECT * FROM user") {
48-
User(
49-
id = it.getString("id"),
50-
name = it.getString("name")
51-
)
52-
}
53-
row shouldBe User(id = "test", name = "Test user")
35+
fun roomWritePowerSyncRead() =
36+
runTest {
37+
database.userDao().create(User(id = "test", name = "Test user"))
38+
val logger = Logger(loggerConfigInit())
39+
40+
val powersync =
41+
PowerSyncDatabase.opened(
42+
pool = RoomConnectionPool(database),
43+
scope = this,
44+
schema = TestDatabase.schema,
45+
identifier = "test",
46+
logger = logger,
47+
)
5448

55-
powersync.close()
56-
}
49+
val row =
50+
powersync.get("SELECT * FROM user") {
51+
User(
52+
id = it.getString("id"),
53+
name = it.getString("name"),
54+
)
55+
}
56+
row shouldBe User(id = "test", name = "Test user")
57+
58+
powersync.close()
59+
}
5760

5861
@Test
59-
fun roomWritePowerSyncWatch() = runTest {
60-
val logger = Logger(loggerConfigInit())
61-
val pool = RoomConnectionPool(database)
62-
63-
val powersync = PowerSyncDatabase.opened(
64-
pool = pool,
65-
scope = this,
66-
schema = TestDatabase.schema,
67-
identifier = "test",
68-
logger = logger,
69-
)
70-
71-
turbineScope {
72-
val turbine = powersync.watch("SELECT * FROM user") {
73-
User(
74-
id = it.getString("id"),
75-
name = it.getString("name")
62+
fun roomWritePowerSyncWatch() =
63+
runTest {
64+
val logger = Logger(loggerConfigInit())
65+
val pool = RoomConnectionPool(database)
66+
67+
val powersync =
68+
PowerSyncDatabase.opened(
69+
pool = pool,
70+
scope = this,
71+
schema = TestDatabase.schema,
72+
identifier = "test",
73+
logger = logger,
7674
)
77-
}.testIn(this)
7875

79-
turbine.awaitItem() shouldHaveSize 0
80-
database.userDao().create(User("id", "name"))
81-
pool.transferRoomUpdatesToPowerSync() // TODO: Would be cool if this wasn't necessary
82-
turbine.awaitItem() shouldHaveSize 1
83-
turbine.cancel()
76+
turbineScope {
77+
val turbine =
78+
powersync
79+
.watch("SELECT * FROM user") {
80+
User(
81+
id = it.getString("id"),
82+
name = it.getString("name"),
83+
)
84+
}.testIn(this)
85+
86+
turbine.awaitItem() shouldHaveSize 0
87+
database.userDao().create(User("id", "name"))
88+
pool.transferRoomUpdatesToPowerSync() // TODO: Would be cool if this wasn't necessary
89+
turbine.awaitItem() shouldHaveSize 1
90+
turbine.cancel()
91+
}
8492
}
85-
}
8693

8794
@Test
88-
fun powersyncWriteRoomRead() = runTest {
89-
val logger = Logger(loggerConfigInit())
90-
val pool = RoomConnectionPool(database)
91-
92-
val powersync = PowerSyncDatabase.opened(
93-
pool = pool,
94-
scope = this,
95-
schema = TestDatabase.schema,
96-
identifier = "test",
97-
logger = logger,
98-
)
99-
100-
database.userDao().getAll() shouldHaveSize 0
101-
powersync.execute("insert into user values (uuid(), ?)", listOf("PowerSync user"))
102-
database.userDao().getAll() shouldHaveSize 1
103-
}
95+
fun powersyncWriteRoomRead() =
96+
runTest {
97+
val logger = Logger(loggerConfigInit())
98+
val pool = RoomConnectionPool(database)
99+
100+
val powersync =
101+
PowerSyncDatabase.opened(
102+
pool = pool,
103+
scope = this,
104+
schema = TestDatabase.schema,
105+
identifier = "test",
106+
logger = logger,
107+
)
108+
109+
database.userDao().getAll() shouldHaveSize 0
110+
powersync.execute("insert into user values (uuid(), ?)", listOf("PowerSync user"))
111+
database.userDao().getAll() shouldHaveSize 1
112+
}
104113

105114
@Test
106-
fun powersyncWriteRoomWatch() = runTest {
107-
val logger = Logger(loggerConfigInit())
108-
val pool = RoomConnectionPool(database)
109-
110-
val powersync = PowerSyncDatabase.opened(
111-
pool = pool,
112-
scope = this,
113-
schema = TestDatabase.schema,
114-
identifier = "test",
115-
logger = logger,
116-
)
117-
118-
turbineScope {
119-
val turbine = database.userDao().watchAll().testIn(this)
120-
turbine.awaitItem() shouldHaveSize 0
115+
fun powersyncWriteRoomWatch() =
116+
runTest {
117+
val logger = Logger(loggerConfigInit())
118+
val pool = RoomConnectionPool(database)
119+
120+
val powersync =
121+
PowerSyncDatabase.opened(
122+
pool = pool,
123+
scope = this,
124+
schema = TestDatabase.schema,
125+
identifier = "test",
126+
logger = logger,
127+
)
121128

122-
powersync.execute("insert into user values (uuid(), ?)", listOf("PowerSync user"))
123-
turbine.awaitItem() shouldHaveSize 1
124-
turbine.cancel()
129+
turbineScope {
130+
val turbine = database.userDao().watchAll().testIn(this)
131+
turbine.awaitItem() shouldHaveSize 0
132+
133+
powersync.execute("insert into user values (uuid(), ?)", listOf("PowerSync user"))
134+
turbine.awaitItem() shouldHaveSize 1
135+
turbine.cancel()
136+
}
125137
}
126-
}
127138
}

integrations/room/src/commonTest/kotlin/com/powersync/integrations/room/TestDatabase.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ interface UserDao {
3434
suspend fun delete(user: User)
3535
}
3636

37-
3837
@Database(entities = [User::class], version = 1)
3938
@ConstructedBy(TestDatabaseConstructor::class)
40-
abstract class TestDatabase: RoomDatabase() {
39+
abstract class TestDatabase : RoomDatabase() {
4140
abstract fun userDao(): UserDao
4241

4342
companion object {
File renamed without changes.

integrations/room/src/jvmTest/kotlin/com/powersync/integrations/room/utils.jvm.kt renamed to integrations/room/src/jvmTest/kotlin/com/powersync/integrations/room/Utils.jvm.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,5 @@ package com.powersync.integrations.room
22

33
import androidx.room.Room
44
import androidx.room.RoomDatabase
5-
import androidx.sqlite.driver.bundled.BundledSQLiteDriver
65

7-
actual fun createDatabaseBuilder(): RoomDatabase.Builder<TestDatabase> {
8-
return Room.inMemoryDatabaseBuilder<TestDatabase>()
9-
}
6+
actual fun createDatabaseBuilder(): RoomDatabase.Builder<TestDatabase> = Room.inMemoryDatabaseBuilder<TestDatabase>()

integrations/room/src/nativeTest/kotlin/com/powersync/integrations/room/utils.native.kt renamed to integrations/room/src/nativeTest/kotlin/com/powersync/integrations/room/Utils.native.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@ package com.powersync.integrations.room
33
import androidx.room.Room
44
import androidx.room.RoomDatabase
55

6-
actual fun createDatabaseBuilder(): RoomDatabase.Builder<TestDatabase> {
7-
return Room.inMemoryDatabaseBuilder()
8-
}
6+
actual fun createDatabaseBuilder(): RoomDatabase.Builder<TestDatabase> = Room.inMemoryDatabaseBuilder()

0 commit comments

Comments
 (0)