Repository navigation
Migrate Kotlin Multiplatform SQLite and Room snippets - #1141
erikrodriguez-se wants to merge 6 commits into
Conversation
f0f34d7 to
f6d8553
Compare
kkuan2011
left a comment
There was a problem hiding this comment.
Looks like build is failing too, can you look into the error?
| // [END_EXCLUDE] | ||
| val database: RoomDatabase = ... | ||
| // [START_EXCLUDE silent] | ||
| */ |
There was a problem hiding this comment.
instead of leaving line 100 as a comment, can we use line 103 as the visible code and then call out the visible code different int/ he PR description?
There was a problem hiding this comment.
Done in 837b7d0. The write transaction snippet now shows val database: RoomDatabase = getRoomDatabase(builder) as visible code, and the PR description lists it under the rendered differences.
| // [START_EXCLUDE silent] | ||
| /* | ||
| // [END_EXCLUDE] | ||
| val database: RoomDatabase = ... |
There was a problem hiding this comment.
Same fix for the read transaction snippet in 837b7d0.
| // [START_EXCLUDE silent] | ||
| /* | ||
| // [END_EXCLUDE] | ||
| val connection: SQLiteConnection = ... |
There was a problem hiding this comment.
Done in 837b7d0. android_kmp_sqlite_transaction now shows val connection: SQLiteConnection = BundledSQLiteDriver().open("todos.db").
| // [START_EXCLUDE silent] | ||
| /* | ||
| // [END_EXCLUDE] | ||
| val connection: SQLiteConnection = ... |
There was a problem hiding this comment.
same here and everywhere else in the code
There was a problem hiding this comment.
Done everywhere in 837b7d0: the 3 SQLite snippets and the 2 Room transaction snippets show the real binding, and no commented-out placeholders are left. Each one is listed in the PR description.
| } | ||
|
|
||
| room3 { | ||
| schemaDirectory(project.layout.buildDirectory.dir("schemas")) |
There was a problem hiding this comment.
add newline at bottom of file - I think spotless may need it?
- Replace D23 block-comment twins with the visible compiling binding in the Room transaction and SQLite snippets. - Add kmp/shared/lint.xml to ignore RestrictedApi in KSP-generated Room *_Impl code (build/generated/**), which failed :kmp:shared:lintAndroidMain. - Add trailing newline to kmp/shared/build.gradle.kts.
|
All review comments are addressed in 837b7d0, replies inline. I ran |
The opt-in was file-level, outside the snippet region, so the code shown on the page doesn't compile when copied.
The page defines AppDatabase.getDao() earlier, so todoDao() in the raw query example pointed at a function readers never see.
Code snippets are for:
List of modifications:
android_kmp_sqlite_transaction,android_kmp_sqlite_query_no_result, andandroid_kmp_sqlite_query_result_no_args, the page's placeholderval connection: SQLiteConnection = ...is replaced with the visible bindingval connection: SQLiteConnection = BundledSQLiteDriver().open("todos.db")(per review).android_kmp_sqlite_transaction,android_kmp_sqlite_query_result_no_args, andandroid_kmp_sqlite_query_result_with_args, added trailing periods to inline comments per D29.android_kmp_room_migration,android_kmp_room_auto_migration_spec, andandroid_kmp_room_callback, added thesuspendmodifier required byandroidx.room3:room3-runtime:3.0.1(D17) and normalized Unicode horizontal ellipses (// …) to ASCII// ...(D22).android_kmp_room_suspend_transaction, normalized{ … }to multi-line// ...per D22 and Spotless formatting.android_kmp_room_write_transactionandandroid_kmp_room_read_transaction, the page's placeholderval database: RoomDatabase = …is replaced with the visible bindingval database: RoomDatabase = getRoomDatabase(builder)(per review), and added trailing periods to inline comments per D29.Build configuration:
kmp/shared/build.gradle.kts: added the KSP and Room 3 plugins,room3-runtimeandsqlite-bundleddependencies, the Room compiler for the Android and iOS KSP targets, and theroom3schema directory. Also added the missing newline at end of file (per review).kmp/shared/lint.xml(new): ignoresRestrictedApionly underbuild/generated/**. This fixes the failingbuildcheck::kmp:shared:lintAndroidMainreported 77RestrictedApierrors, all in Room's KSP-generatedAppDatabase_Impl(63) andTodoDao_Impl(14), which overrideandroidx.room3APIs annotated@RestrictTo(LIBRARY_GROUP_PREFIX). None were in the snippet sources, and hand-written code is still checked.:roomdoesn't need this: the KMP Android library plugin (com.android.kotlin.multiplatform.library) lists the KSP output directory as a regular source directory in the lint model, so lint analyzes the generated code.:roomusescom.android.library, where lint skips generated sources by default.lint.xmlpath-ignore pattern inwear/lint.xmlandcompose/snippets/lint.xml.kmp/shared/build.gradle.kts(kotlin { android { lint { disable += "RestrictedApi" } } }), similar todisable += "UseKtx"inxr/build.gradle.kts. That's a smaller diff with no new file, but it also hidesRestrictedApiin any future hand-written:kmp:sharedsnippet. I went with the narrowerlint.xmlapproach; happy to switch if you prefer.Snippets not migrated:
libs.versions.toml) block using DevSite template variable{{androidx_sqlite_stable}}(D27)SupportSQLiteDatabaseblocks written for an earlier version of an API as part of migration guidancejvmMain) target snippets are out of scope for:kmp:sharedSupportSQLiteDatabase, blocking DAO,LiveData, andwithTransaction) blocks written for an earlier version of an API as part of migration guidance