Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Move database tables to tables package
Browse files Browse the repository at this point in the history
  • Loading branch information
M3DZIK committed Aug 3, 2024
1 parent 852a42e commit 95f4c6e
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 107 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ package dev.medzik.librepass.android.database
import androidx.room.AutoMigration
import androidx.room.Database
import androidx.room.RoomDatabase
import dev.medzik.librepass.android.database.tables.Credentials
import dev.medzik.librepass.android.database.tables.CredentialsDao
import dev.medzik.librepass.android.database.tables.CustomServer
import dev.medzik.librepass.android.database.tables.CustomServerDao
import dev.medzik.librepass.android.database.tables.LocalCipher
import dev.medzik.librepass.android.database.tables.LocalCipherDao

@Database(
version = 3,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package dev.medzik.librepass.android.database

import android.content.Context
import dev.medzik.librepass.android.database.tables.CredentialsDao
import dev.medzik.librepass.android.database.tables.CustomServerDao
import dev.medzik.librepass.android.database.tables.LocalCipherDao

/**
* Repository interface provides database DAOs.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package dev.medzik.librepass.android.database
package dev.medzik.librepass.android.database.tables

import androidx.room.Dao
import androidx.room.Entity
import androidx.room.Insert
import androidx.room.PrimaryKey
import androidx.room.Query
import androidx.room.Update
import java.util.*

@Entity
Expand All @@ -22,3 +26,18 @@ data class Credentials(
val biometricAesKeyIV: String? = null,
val biometricReSetup: Boolean = false
)

@Dao
interface CredentialsDao {
@Insert
suspend fun insert(credentials: Credentials)

@Query("SELECT * FROM credentials LIMIT 1")
fun get(): Credentials?

@Update
suspend fun update(credentials: Credentials)

@Query("DELETE FROM credentials")
suspend fun drop()
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package dev.medzik.librepass.android.database
package dev.medzik.librepass.android.database.tables

import androidx.room.Dao
import androidx.room.Entity
import androidx.room.Insert
import androidx.room.PrimaryKey
import androidx.room.Query

@Entity
data class CustomServer(
val name: String,
@PrimaryKey
val address: String
)

@Dao
interface CustomServerDao {
@Query("SELECT * FROM customserver")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package dev.medzik.librepass.android.database
package dev.medzik.librepass.android.database.tables

import androidx.room.Dao
import androidx.room.Entity
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.PrimaryKey
import androidx.room.Query
import androidx.room.TypeConverter
import androidx.room.TypeConverters
import androidx.room.Update
import dev.medzik.librepass.client.utils.JsonUtils
import dev.medzik.librepass.types.cipher.EncryptedCipher
import java.util.*
Expand Down Expand Up @@ -39,3 +44,30 @@ class EncryptedCipherConverter {
return JsonUtils.deserialize(json)
}
}

@Dao
interface LocalCipherDao {
@Query("SELECT * FROM localCipher WHERE id = :id")
fun get(id: UUID): LocalCipher?

@Query("SELECT * FROM localCipher WHERE owner = :owner")
fun getAll(owner: UUID): List<LocalCipher>

@Query("SELECT id FROM localCipher WHERE owner = :owner")
fun getAllIDs(owner: UUID): List<UUID>

@Query("DELETE FROM localCipher WHERE id = :id")
fun delete(id: UUID)

@Query("DELETE FROM localCipher WHERE id IN (:ids)")
fun delete(ids: List<UUID>)

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(cipherTable: LocalCipher)

@Update
fun update(cipherTable: LocalCipher)

@Query("DELETE FROM localCipher WHERE owner = :owner")
suspend fun drop(owner: UUID)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package dev.medzik.librepass.android.ui

import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import dev.medzik.librepass.android.database.Credentials
import dev.medzik.librepass.android.database.tables.Credentials
import dev.medzik.librepass.android.database.Repository
import javax.inject.Inject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import dev.medzik.android.compose.ui.bottomsheet.rememberBottomSheetState
import dev.medzik.android.compose.ui.textfield.AnimatedTextField
import dev.medzik.android.compose.ui.textfield.TextFieldValue
import dev.medzik.android.utils.showToast
import dev.medzik.librepass.android.database.CustomServer
import dev.medzik.librepass.android.database.tables.CustomServer
import dev.medzik.librepass.android.ui.R
import dev.medzik.librepass.client.Server
import dev.medzik.librepass.client.api.checkApiConnection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package dev.medzik.librepass.android.ui.auth

import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import dev.medzik.librepass.android.database.CustomServer
import dev.medzik.librepass.android.database.tables.CustomServer
import dev.medzik.librepass.android.database.Repository
import javax.inject.Inject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import dev.medzik.android.utils.showToast
import dev.medzik.librepass.android.common.haveNetworkConnection
import dev.medzik.librepass.android.database.Credentials
import dev.medzik.librepass.android.database.tables.Credentials
import dev.medzik.librepass.android.database.Repository
import dev.medzik.librepass.android.ui.R
import dev.medzik.librepass.client.Server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import dev.medzik.android.compose.theme.spacing
import dev.medzik.android.compose.ui.IconBox
import dev.medzik.android.compose.ui.bottomsheet.rememberBottomSheetState
import dev.medzik.common.extensions.truncate
import dev.medzik.librepass.android.database.Credentials
import dev.medzik.librepass.android.database.tables.Credentials
import dev.medzik.librepass.android.ui.R
import dev.medzik.librepass.client.api.CipherClient
import dev.medzik.librepass.types.cipher.Cipher
Expand Down

0 comments on commit 95f4c6e

Please sign in to comment.