-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from Team-HMH/feat/database
[feat/database] : Room Database 추가 작업
- Loading branch information
Showing
18 changed files
with
169 additions
and
9 deletions.
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
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