-
Notifications
You must be signed in to change notification settings - Fork 1
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/database] : Room Database 추가 작업 #22
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...logic/convention/src/main/kotlin/com/hmh/hamyeonham/plugin/AndroidRoomConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.hmh.hamyeonham.plugin | ||
|
||
import com.google.devtools.ksp.gradle.KspExtension | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.api.artifacts.VersionCatalogsExtension | ||
import org.gradle.api.tasks.InputDirectory | ||
import org.gradle.api.tasks.PathSensitive | ||
import org.gradle.api.tasks.PathSensitivity | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.dependencies | ||
import org.gradle.kotlin.dsl.getByType | ||
import org.gradle.process.CommandLineArgumentProvider | ||
import java.io.File | ||
|
||
class AndroidRoomConventionPlugin : Plugin<Project> { | ||
|
||
override fun apply(target: Project) = with(target) { | ||
with(plugins) { | ||
apply("com.google.devtools.ksp") | ||
} | ||
|
||
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs") | ||
|
||
extensions.configure<KspExtension> { | ||
// The schemas directory contains a schema file for each version of the Room database. | ||
// This is required to enable Room auto migrations. | ||
// See https://developer.android.com/reference/kotlin/androidx/room/AutoMigration. | ||
arg(RoomSchemaArgProvider(File(projectDir, "schemas"))) | ||
} | ||
|
||
dependencies { | ||
add("implementation", libs.findLibrary("room.runtime").get()) | ||
add("implementation", libs.findLibrary("room.ktx").get()) | ||
add("ksp", libs.findLibrary("room.compiler").get()) | ||
} | ||
} | ||
|
||
|
||
/** | ||
* https://issuetracker.google.com/issues/132245929 | ||
* [Export schemas](https://developer.android.com/training/data-storage/room/migrating-db-versions#export-schemas) | ||
*/ | ||
class RoomSchemaArgProvider( | ||
@get:InputDirectory | ||
@get:PathSensitive(PathSensitivity.RELATIVE) | ||
val schemaDir: File, | ||
) : CommandLineArgumentProvider { | ||
override fun asArguments() = listOf("room.schemaLocation=${schemaDir.path}") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
core/common/src/main/java/com/hmh/hamyeonham/common/lifecycle/SingleLiveEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed | ||
plugins { | ||
hmh("feature") | ||
hmh("room") | ||
} | ||
|
||
android { | ||
namespace = "com.hmh.hamyeonham.core.database" | ||
} | ||
|
||
dependencies {} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
24 changes: 24 additions & 0 deletions
24
core/database/src/main/java/com/hmh/hamyeonham/core/database/DatabaseModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.hmh.hamyeonham.core.database | ||
|
||
import android.content.Context | ||
import androidx.room.Room | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object DatabaseModule { | ||
@Provides | ||
@Singleton | ||
fun providesNiaDatabase( | ||
@ApplicationContext context: Context, | ||
): HMHRoomDatabase = Room.databaseBuilder( | ||
context, | ||
HMHRoomDatabase::class.java, | ||
"hmh-android-database", | ||
).build() | ||
} |
11 changes: 11 additions & 0 deletions
11
core/database/src/main/java/com/hmh/hamyeonham/core/database/HMHRoomDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.hmh.hamyeonham.core.database | ||
|
||
import androidx.room.Database | ||
import androidx.room.RoomDatabase | ||
import com.hmh.hamyeonham.core.database.dao.SampleDao | ||
import com.hmh.hamyeonham.core.database.model.Sample | ||
|
||
@Database(entities = [Sample::class], version = 1, exportSchema = false) | ||
abstract class HMHRoomDatabase : RoomDatabase() { | ||
abstract fun sampleDao(): SampleDao | ||
} |
12 changes: 12 additions & 0 deletions
12
core/database/src/main/java/com/hmh/hamyeonham/core/database/dao/SampleDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.hmh.hamyeonham.core.database.dao | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import com.hmh.hamyeonham.core.database.model.Sample | ||
|
||
@Dao | ||
interface SampleDao { | ||
@Insert(onConflict = OnConflictStrategy.IGNORE) | ||
suspend fun insertSampleList(entities: List<Sample>): List<Long> | ||
} |
10 changes: 10 additions & 0 deletions
10
core/database/src/main/java/com/hmh/hamyeonham/core/database/model/Sample.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.hmh.hamyeonham.core.database.model | ||
|
||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity | ||
data class Sample( | ||
@PrimaryKey(autoGenerate = true) val id: Int, | ||
val sample: String | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ kotlinx-serialization-json = "1.6.0" | |
kotlinx-serialization-converter = "1.0.0" | ||
kotlinx-coroutines = "1.7.3" | ||
kotlinx-datetime = "0.4.1" | ||
ksp = "1.8.21-1.0.11" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kotlin 버전하고 맞춰야하지 않나요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 감사합니다! 해당 부분 다음 pr에서 수정하도록 하겠습니다😆 |
||
|
||
# android | ||
corektx = "1.12.0" | ||
|
@@ -68,7 +69,7 @@ flipper = "0.236.0" | |
soloader = "0.10.5" | ||
okhttp = "4.12.0" | ||
retrofit = "2.9.0" | ||
timber = "5.0.1" | ||
room = "2.6.1" | ||
coil = "2.5.0" | ||
lottie = "6.0.1" | ||
ktlint = "11.6.1" | ||
|
@@ -91,6 +92,7 @@ kotlin-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-s | |
kotlin-coroutines-google-play = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-play-services", version.ref = "kotlinx-coroutines" } | ||
kotlin-coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "kotlinx-coroutines" } | ||
kotlin-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version.ref = "kotlinx-datetime" } | ||
ksp-gradlePlugin = { group = "com.google.devtools.ksp", name = "com.google.devtools.ksp.gradle.plugin", version.ref = "ksp" } | ||
|
||
# android | ||
core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "corektx" } | ||
|
@@ -181,7 +183,10 @@ okhttp-logging-interceptor = { module = "com.squareup.okhttp3:logging-intercepto | |
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" } | ||
retrofit-kotlin-serialization-converter = { group = "com.jakewharton.retrofit", name = "retrofit2-kotlinx-serialization-converter", version.ref = "kotlinx-serialization-converter" } | ||
|
||
timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" } | ||
# Room | ||
room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" } | ||
room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" } | ||
room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" } | ||
|
||
coil-core = { module = "io.coil-kt:coil", version.ref = "coil" } | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
timber 추가 안했다고 했었는데 셋팅해두었다가 뺀건가용??
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.
init을 안했다는 얘기였습니당~!!