-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: added base code for room db
- Loading branch information
1 parent
d568faa
commit a5f864d
Showing
4 changed files
with
67 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.arindom.koa2.di | ||
|
||
import android.content.Context | ||
import androidx.room.Room | ||
import com.arindom.koa2.infra.local.database.KaoDatabase | ||
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 AppModule { | ||
@Singleton | ||
@Provides | ||
fun providesRoomDb( | ||
@ApplicationContext context: Context | ||
): KaoDatabase { | ||
return Room.databaseBuilder( | ||
context, | ||
KaoDatabase::class.java, | ||
"kao_database" | ||
).build() | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/arindom/koa2/infra/local/database/KaoDatabase.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,14 @@ | ||
package com.arindom.koa2.infra.local.database | ||
|
||
import androidx.room.Database | ||
import androidx.room.RoomDatabase | ||
import com.arindom.koa2.infra.local.database.entities.FavoriteMovieDao | ||
import com.arindom.koa2.infra.local.database.entities.FavouriteMoviesEntity | ||
|
||
@Database( | ||
entities = [FavouriteMoviesEntity::class], | ||
version = 1 | ||
) | ||
abstract class KaoDatabase : RoomDatabase() { | ||
abstract fun getFavouriteMovieDao(): FavoriteMovieDao | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/arindom/koa2/infra/local/database/entities/FavoriteMovieDao.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.arindom.koa2.infra.local.database.entities | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Query | ||
|
||
@Dao | ||
interface FavoriteMovieDao { | ||
@Query("Select * from favourite_movies") | ||
suspend fun getMyFavorites(): List<FavouriteMoviesEntity> | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/arindom/koa2/infra/local/database/entities/FavouriteMoviesEntity.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,16 @@ | ||
package com.arindom.koa2.infra.local.database.entities | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity(tableName = "favourite_movies") | ||
data class FavouriteMoviesEntity( | ||
@PrimaryKey(autoGenerate = true) | ||
var id: Int, | ||
@ColumnInfo(name = "movie_name") val movieName: String, | ||
@ColumnInfo(name = "movie_id") val movieId: String, | ||
@ColumnInfo(name = "movie_poster") val poster: String, | ||
@ColumnInfo(name = "director") val director: String, | ||
@ColumnInfo(name = "year") val year: String, | ||
) |