mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 11:22:12 +00:00
Refactor Database
This commit is contained in:
parent
98d62df36b
commit
d40cb77a9b
24
src/main/kotlin/com/looker/droidify/database/dao/BaseDao.kt
Normal file
24
src/main/kotlin/com/looker/droidify/database/dao/BaseDao.kt
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package com.looker.droidify.database.dao
|
||||||
|
|
||||||
|
import androidx.room.*
|
||||||
|
import com.looker.droidify.database.entity.Ignored
|
||||||
|
|
||||||
|
interface BaseDao<T> {
|
||||||
|
@Insert
|
||||||
|
fun insert(vararg product: T)
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
fun insertReplace(vararg product: T)
|
||||||
|
|
||||||
|
@Update(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
fun update(vararg obj: T): Int
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
fun delete(obj: T)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface LockDao : BaseDao<Ignored> {
|
||||||
|
@Query("DELETE FROM memory_lock WHERE packageName = :packageName")
|
||||||
|
fun delete(packageName: String)
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.looker.droidify.database.dao
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Query
|
||||||
|
import com.looker.droidify.database.entity.Category
|
||||||
|
import com.looker.droidify.database.entity.CategoryTemp
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface CategoryDao : BaseDao<Category> {
|
||||||
|
@get:Query(
|
||||||
|
"""SELECT DISTINCT category.label
|
||||||
|
FROM category AS category
|
||||||
|
JOIN repository AS repository
|
||||||
|
ON category.repositoryId = repository._id
|
||||||
|
WHERE repository.enabled != 0"""
|
||||||
|
)
|
||||||
|
val allNames: List<String>
|
||||||
|
|
||||||
|
@get:Query(
|
||||||
|
"""SELECT DISTINCT category.label
|
||||||
|
FROM category AS category
|
||||||
|
JOIN repository AS repository
|
||||||
|
ON category.repositoryId = repository._id
|
||||||
|
WHERE repository.enabled != 0"""
|
||||||
|
)
|
||||||
|
val allNamesLive: LiveData<List<String>>
|
||||||
|
|
||||||
|
@Query("DELETE FROM category WHERE repositoryId = :id")
|
||||||
|
fun deleteById(id: Long): Int
|
||||||
|
}
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface CategoryTempDao : BaseDao<CategoryTemp> {
|
||||||
|
@get:Query("SELECT * FROM temporary_category")
|
||||||
|
val all: Array<CategoryTemp>
|
||||||
|
|
||||||
|
@Query("DELETE FROM temporary_category")
|
||||||
|
fun emptyTable()
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.looker.droidify.database.dao
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Query
|
||||||
|
import com.looker.droidify.database.entity.Installed
|
||||||
|
|
||||||
|
// TODO make sure that apps that not uninstalled by Droid-ify still get removed
|
||||||
|
@Dao
|
||||||
|
interface InstalledDao : BaseDao<Installed> {
|
||||||
|
fun put(vararg installed: Installed) {
|
||||||
|
installed.forEach { insertReplace(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@get:Query("SELECT * FROM memory_installed")
|
||||||
|
val allLive: LiveData<List<Installed>>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM memory_installed WHERE packageName = :packageName")
|
||||||
|
fun get(packageName: String): Installed?
|
||||||
|
|
||||||
|
@Query("SELECT * FROM memory_installed WHERE packageName = :packageName")
|
||||||
|
fun getLive(packageName: String): LiveData<Installed?>
|
||||||
|
|
||||||
|
@Query("DELETE FROM memory_installed WHERE packageName = :packageName")
|
||||||
|
fun delete(packageName: String)
|
||||||
|
|
||||||
|
@Query("DELETE FROM memory_installed")
|
||||||
|
fun emptyTable()
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.looker.droidify.database.dao
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Query
|
||||||
|
import com.looker.droidify.database.entity.Release
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface ReleaseDao : BaseDao<Release> {
|
||||||
|
// This one for the mode combining releases of different sources
|
||||||
|
@Query("SELECT * FROM `release` WHERE packageName = :packageName")
|
||||||
|
fun get(packageName: String): List<Release?>
|
||||||
|
|
||||||
|
// This one for the separating releases of different sources
|
||||||
|
@Query("SELECT * FROM `release` WHERE packageName = :packageName AND signature = :signature")
|
||||||
|
fun get(packageName: String, signature: String): List<Release?>
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package com.looker.droidify.database.dao
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.Query
|
||||||
|
import com.looker.droidify.database.entity.Repository
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface RepositoryDao : BaseDao<Repository> {
|
||||||
|
@get:Query("SELECT COUNT(_id) FROM repository")
|
||||||
|
val count: Int
|
||||||
|
|
||||||
|
fun put(repository: Repository): Repository {
|
||||||
|
repository.let { item ->
|
||||||
|
val newId = if (item.id > 0L) update(item).toLong() else returnInsert(item)
|
||||||
|
return if (newId != repository.id) repository.copy(id = newId) else repository
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Insert
|
||||||
|
fun returnInsert(product: Repository): Long
|
||||||
|
|
||||||
|
@Query("SELECT * FROM repository WHERE _id = :id")
|
||||||
|
fun get(id: Long): Repository?
|
||||||
|
|
||||||
|
@Query("SELECT * FROM repository WHERE _id = :id")
|
||||||
|
fun getLive(id: Long): LiveData<Repository?>
|
||||||
|
|
||||||
|
@get:Query("SELECT * FROM repository ORDER BY _id ASC")
|
||||||
|
val all: List<Repository>
|
||||||
|
|
||||||
|
@get:Query("SELECT * FROM repository ORDER BY _id ASC")
|
||||||
|
val allLive: LiveData<List<Repository>>
|
||||||
|
|
||||||
|
@get:Query("SELECT _id FROM repository WHERE enabled == 0 ORDER BY _id ASC")
|
||||||
|
val allDisabled: List<Long>
|
||||||
|
|
||||||
|
// TODO clean up products and other tables afterwards
|
||||||
|
@Query("DELETE FROM repository WHERE _id = :id")
|
||||||
|
fun deleteById(id: Long): Int
|
||||||
|
|
||||||
|
@Query("SELECT MAX(_id) FROM repository")
|
||||||
|
fun latestAddedId(): Long
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user