-
Notifications
You must be signed in to change notification settings - Fork 0
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
🔧 SQLDelight の導入 #146
🔧 SQLDelight の導入 #146
Conversation
WalkthroughアプリケーションのAndroid、iOS、JSプラットフォームにわたるデータベース機能が強化されました。Kotlin Multiplatformプロジェクトにおいて、SQLDelightの設定が追加され、各プラットフォーム用のDriverFactoryが導入されました。Koinを使用した依存性注入が更新され、新しいデータベースモジュールが追加されています。これにより、アプリケーションのデータ管理能力が向上しました。 Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on X ? TipsChat with CodeRabbit Bot (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 3
Configuration used: CodeRabbit UI
Files ignored due to filter (1)
- gradle/libs.versions.toml
Files selected for processing (18)
- app/android/src/androidMain/kotlin/club/nito/app/MainActivity.kt (3 hunks)
- app/ios-combined/src/commonMain/kotlin/club/nito/ios/combined/KmpEntryPoint.kt (2 hunks)
- app/ios/App/Nito/Nito.xcodeproj/project.pbxproj (6 hunks)
- app/shared/build.gradle.kts (1 hunks)
- app/shared/src/commonMain/kotlin/club/nito/app/shared/NitoApp.kt (2 hunks)
- build-logic/build.gradle.kts (1 hunks)
- build-logic/src/main/kotlin/club/nito/primitive/KmpSqlDelightPlugin.kt (1 hunks)
- core/database/build.gradle.kts (2 hunks)
- core/database/src/androidMain/kotlin/club/nito/core/database/Database.android.kt (1 hunks)
- core/database/src/androidMain/kotlin/club/nito/core/database/di/DatabaseModule.android.kt (1 hunks)
- core/database/src/commonMain/kotlin/club/nito/core/database/Database.kt (1 hunks)
- core/database/src/commonMain/kotlin/club/nito/core/database/adapter/ParticipantStatus.kt (1 hunks)
- core/database/src/commonMain/kotlin/club/nito/core/database/di/DatabaseModule.kt (1 hunks)
- core/database/src/commonMain/sqldelight/club/nito/core/database/Participants.sq (1 hunks)
- core/database/src/iosMain/kotlin/club/nito/core/database/Database.ios.kt (1 hunks)
- core/database/src/iosMain/kotlin/club/nito/core/database/di/DatabaseModule.ios.kt (1 hunks)
- core/database/src/jsMain/kotlin/club/nito/core/database/Database.js.kt (1 hunks)
- core/database/src/jsMain/kotlin/club/nito/core/database/di/DatabaseModule.js.kt (1 hunks)
Files skipped from review due to trivial changes (1)
- app/ios/App/Nito/Nito.xcodeproj/project.pbxproj
Additional comments: 27
app/android/src/androidMain/kotlin/club/nito/app/MainActivity.kt (3)
3-3: インポートされた
android.content.Context
は、Koinモジュール内でContext
のインスタンスを提供するために使用されています。16-16: インポートされた
org.koin.dsl.module
は、KoinのDI設定においてモジュールを定義するために使用されています。42-45:
initKoin
メソッド内で追加されたKoinモジュールは、アプリケーションのContext
をシングルインスタンスとして提供するためのものです。これにより、アプリケーション全体でContext
を簡単に注入できるようになります。app/ios-combined/src/commonMain/kotlin/club/nito/ios/combined/KmpEntryPoint.kt (3)
5-11:
databaseModule
のインポートが追加されています。これはSQLDelightの統合に必要な変更であり、適切に行われているようです。36-42:
databaseModule
がKoinのモジュールリストに追加されています。これにより、アプリケーションの依存性注入セットアップにSQLDelightが含まれるようになります。38-38: コメントアウトされた
fakeRemoteDataSourceModule
について、これが意図的な変更であるかどうかを確認してください。もし意図的でない場合は、削除またはコメントアウトを解除する必要があります。app/shared/build.gradle.kts (1)
- 15-21:
projects.core.database
への依存関係の追加が確認されました。この変更が他のモジュールやプラットフォームに影響を与えないか、また、バージョンの互換性があるかを確認してください。app/shared/src/commonMain/kotlin/club/nito/app/shared/NitoApp.kt (2)
11-17:
databaseModule
のインポートが追加されており、これはSQLDelightの統合に必要な変更であることを確認しました。46-52:
databaseModule
がKoinApplication
のmodules
関数内に追加されています。これにより、SQLDelightのデータベースインスタンスが依存性注入に含まれるようになりました。この変更は、プロジェクトのインフラストラクチャにSQLDelightを統合するというPRの目的に沿っています。build-logic/build.gradle.kts (1)
- 65-68: プラグインの登録が正しく行われており、プロジェクトのSQLDelight統合目的に沿っています。プラグインIDと実装クラスがプロジェクトの命名規則に従っており、他のプラグインと一貫性があります。
core/database/build.gradle.kts (3)
3-8: プラグインブロックに
nito.primitive.kmp.sqldelight
プラグインが追加されています。これはPRの目的であるSQLDelightの統合と一致しています。15-25:
commonMain
ソースセットに依存関係が追加されています。これはKotlin Multiplatformプロジェクトに期待される動作です。ただし、追加された依存関係がデータベースモジュールに必要かどうかを確認する必要があります。29-36: SQLDelightの設定ブロックが追加され、データベースのプロパティを定義しています。データベース名とパッケージ名が指定されており、これはSQLDelightのコード生成に不可欠です。
core/database/src/androidMain/kotlin/club/nito/core/database/Database.android.kt (3)
8-24:
DATABASE_NAME
の定義を確認してください。この変数はこのファイル内で定義されていないようですが、他の場所で定義されている必要があります。17-20:
onConfigure
メソッド内のenableWriteAheadLogging
とsetForeignKeyConstraintsEnabled
の呼び出しは、データベースのパフォーマンスと整合性を向上させるための適切な設定です。8-8:
DriverFactory
クラスはinternal
修飾子で適切に宣言されており、モジュール内部でのみアクセス可能です。core/database/src/androidMain/kotlin/club/nito/core/database/di/DatabaseModule.android.kt (1)
- 6-8:
Scope.createDriverFactory
関数内でget()
を使用してcontext
を取得していますが、get()
が期待する型のオブジェクトがScope
に存在することを確認してください。また、DriverFactory
のコンストラクタがcontext
をどのように使用するかも確認する必要があります。core/database/src/commonMain/kotlin/club/nito/core/database/Database.kt (3)
6-8:
DriverFactory
クラスが追加されており、これはプラットフォーム固有の SQL ドライバーを生成するためのものです。各プラットフォームに対してactual
実装が存在することを確認してください。12-22:
createDatabase
関数はDriverFactory
を使用してデータベースインスタンスを生成しています。この関数の実装は問題ないように見えますが、EnumColumnAdapter
の使用がParticipants
のstatusAdapter
に対して適切であることを確認してください。21-21: コメントに「データベースでさらに作業を行う (下記参照)」とありますが、その詳細が提供されていません。このコメントが指す「下記」の部分がこのファイル内に存在するか、または別の場所にあるのかを確認してください。
core/database/src/commonMain/kotlin/club/nito/core/database/di/DatabaseModule.kt (2)
9-14:
databaseModule
の定義は、createDatabase
関数をsingle
スコープで呼び出しており、依存性注入のセットアップが適切に行われているようです。ただし、createDatabase
関数の引数が正しいかどうか、またcreateDriverFactory
が各プラットフォームモジュールで適切に実装されているかどうかを確認する必要があります。17-17:
createDriverFactory
関数のexpect
宣言は、マルチプラットフォーム対応のために各プラットフォームモジュールでactual
実装が提供されていることを期待しています。この実装が存在するかどうかを確認してください。core/database/src/commonMain/sqldelight/club/nito/core/database/Participants.sq (1)
- 3-7: SQLDelightテーブル定義において、
ParticipantStatus
をTEXT
型として扱うことは、ParticipantStatus
が適切にシリアライズされることを前提としています。ParticipantStatusAdapter
がこの変換を担当することを確認してください。core/database/src/iosMain/kotlin/club/nito/core/database/Database.ios.kt (1)
- 6-10:
DATABASE_NAME
定数がこのファイルに定義されていないようです。他の場所で定義されているか確認してください。core/database/src/iosMain/kotlin/club/nito/core/database/di/DatabaseModule.ios.kt (1)
- 1-6: iOSプラットフォーム用の
DriverFactory
インスタンスを生成するcreateDriverFactory
関数の実装が単純であり、特に問題は見受けられません。ただし、DriverFactory
がパラメーターや追加の設定を必要としないかどうかを確認する必要があります。iOS用のDriverFactory
がパラメーターや設定を必要とする場合は、その実装を追加する必要があります。core/database/src/jsMain/kotlin/club/nito/core/database/Database.js.kt (1)
- 7-14:
DriverFactory
クラスとcreateDriver
メソッドの実装は、JSプラットフォーム用のSQLドライバーを生成するためのものであり、WebWorkerDriver
を使用しています。ただし、Worker
のインスタンス化に使用されているnew URL
のパスが正しいかどうかは、レビューからは判断できません。このURLが実際に存在し、適切なリソースを指しているかを確認する必要があります。また、Database.Schema.create(it)
がalso
ブロック内で呼び出されており、これによりドライバーの生成と同時にデータベーススキーマが作成されることが保証されています。core/database/src/jsMain/kotlin/club/nito/core/database/di/DatabaseModule.js.kt (1)
- 1-6: この変更は、Kotlin Multiplatform プロジェクトの JS プラットフォーム固有の
DriverFactory
を生成するためのcreateDriverFactory
関数を適切に実装しています。DriverFactory
のコンストラクタがパラメータを必要としないことを確認してください。
import app.cash.sqldelight.ColumnAdapter | ||
import club.nito.core.model.participant.ParticipantStatus | ||
|
||
internal data object ParticipantStatusAdapter : ColumnAdapter<ParticipantStatus, String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data object
の宣言はKotlinでは無効です。シングルトンパターンを実装するためにはobject
のみを使用する必要があります。
- internal data object ParticipantStatusAdapter : ColumnAdapter<ParticipantStatus, String> {
+ internal object ParticipantStatusAdapter : ColumnAdapter<ParticipantStatus, String> {
Committable suggestion
❗ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
internal data object ParticipantStatusAdapter : ColumnAdapter<ParticipantStatus, String> { | |
internal object ParticipantStatusAdapter : ColumnAdapter<ParticipantStatus, String> { |
upsert { | ||
UPDATE participants SET | ||
`schedule_id` = :schedule_id, | ||
`user_id` = :user_id, | ||
`status` = :status | ||
WHERE schedule_id = :schedule_id AND user_id = :user_id; | ||
|
||
INSERT OR IGNORE INTO participants ( | ||
`schedule_id`, | ||
`user_id`, | ||
`status` | ||
) VALUES ( | ||
:schedule_id, | ||
:user_id, | ||
:status | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upsert
操作は、UPDATE
とINSERT OR IGNORE
の組み合わせで実装されていますが、UPDATE
が成功したかどうかに基づいてINSERT
をスキップするロジックが見当たりません。SQLDelightではINSERT
とUPDATE
の順序を逆にして、INSERT OR REPLACE
を使用することが一般的です。このロジックが意図した通りに動作するか確認してください。
- UPDATE participants SET
- `schedule_id` = :schedule_id,
- `user_id` = :user_id,
- `status` = :status
- WHERE schedule_id = :schedule_id AND user_id = :user_id;
-
- INSERT OR IGNORE INTO participants (
- `schedule_id`,
- `user_id`,
- `status`
- ) VALUES (
- :schedule_id,
- :user_id,
- :status
- );
+ INSERT OR REPLACE INTO participants (
+ `schedule_id`,
+ `user_id`,
+ `status`
+ ) VALUES (
+ :schedule_id,
+ :user_id,
+ :status
+ );
Committable suggestion
❗ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
upsert { | |
UPDATE participants SET | |
`schedule_id` = :schedule_id, | |
`user_id` = :user_id, | |
`status` = :status | |
WHERE schedule_id = :schedule_id AND user_id = :user_id; | |
INSERT OR IGNORE INTO participants ( | |
`schedule_id`, | |
`user_id`, | |
`status` | |
) VALUES ( | |
:schedule_id, | |
:user_id, | |
:status | |
); | |
} | |
upsert { | |
INSERT OR REPLACE INTO participants ( | |
`schedule_id`, | |
`user_id`, | |
`status` | |
) VALUES ( | |
:schedule_id, | |
:user_id, | |
:status | |
); | |
} |
package club.nito.primitive | ||
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
|
||
@Suppress("unused") | ||
class KmpSqlDelightPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
with(pluginManager) { | ||
apply("app.cash.sqldelight") | ||
} | ||
kotlin { | ||
with(sourceSets) { | ||
getByName("commonMain").apply { | ||
dependencies { | ||
implementation(libs.library("sqldelightPrimitiveAdapters")) | ||
implementation(libs.library("sqldelightCoroutinesExtensions")) | ||
} | ||
} | ||
findByName("androidMain")?.apply { | ||
dependencies { | ||
implementation(libs.library("sqldelightAndroidDriver")) | ||
} | ||
} | ||
findByName("iosMain")?.apply { | ||
dependencies { | ||
implementation(libs.library("sqldelightNativeDriver")) | ||
|
||
// Need to explicitly depend on these, otherwise the build fails. | ||
implementation(libs.library("statelyCommon")) | ||
implementation(libs.library("statelyIsolate")) | ||
implementation(libs.library("statelyIsoCollections")) | ||
} | ||
} | ||
findByName("jsMain")?.apply { | ||
dependencies { | ||
implementation(libs.library("sqldelightWebWorkerDriver")) | ||
implementation(npm("sql.js", "1.6.2")) | ||
implementation(devNpm("copy-webpack-plugin", "9.1.0")) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
プラグインの実装は適切に行われており、特に問題は見受けられません。ただし、jsMain
ソースセットにハードコードされたバージョン番号が含まれています。これはメンテナンスの観点から将来的に問題になる可能性があるため、バージョン管理の戦略を再検討することをお勧めします。また、エラーハンドリングやプラグインが正しく適用されていることを確認するための設定チェックを追加することも検討してください。
Issue
概要
SQLDelight を導入します。
レビュー観点
特になし
レビューレベル
レビュー優先度
参考リンク
スクリーンショット
Summary by CodeRabbit
新機能
バグ修正
ドキュメント
リファクタリング
スタイル
テスト
その他の作業
リバート