mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-06-08 08:49:55 +00:00
Update: Complete the DAOs
This commit is contained in:
parent
dedbaefef5
commit
9235ed6e0d
@ -14,7 +14,7 @@ interface BaseDao<T> {
|
|||||||
fun insert(vararg product: T)
|
fun insert(vararg product: T)
|
||||||
|
|
||||||
@Update(onConflict = OnConflictStrategy.REPLACE)
|
@Update(onConflict = OnConflictStrategy.REPLACE)
|
||||||
fun update(vararg obj: T)
|
fun update(vararg obj: T): Int
|
||||||
|
|
||||||
@Delete
|
@Delete
|
||||||
fun delete(obj: T)
|
fun delete(obj: T)
|
||||||
@ -22,21 +22,28 @@ interface BaseDao<T> {
|
|||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface RepositoryDao : BaseDao<Repository> {
|
interface RepositoryDao : BaseDao<Repository> {
|
||||||
fun put(repository: com.looker.droidify.entity.Repository) {
|
fun put(repository: com.looker.droidify.entity.Repository): com.looker.droidify.entity.Repository {
|
||||||
repository.let {
|
repository.let {
|
||||||
val dbRepo = Repository().apply {
|
val dbRepo = Repository().apply {
|
||||||
id = it.id
|
id = it.id
|
||||||
enabled = if (it.enabled) 1 else 0
|
enabled = if (it.enabled) 1 else 0
|
||||||
deleted = 0
|
deleted = false
|
||||||
data = it
|
data = it
|
||||||
}
|
}
|
||||||
if (repository.id >= 0L) update(dbRepo) else insert(dbRepo)
|
val newId = if (repository.id >= 0L) update(dbRepo).toLong() else returnInsert(dbRepo)
|
||||||
|
return if (newId != repository.id) repository.copy(id = newId) else repository
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
fun returnInsert(product: Repository): Long
|
||||||
|
|
||||||
@Query("SELECT * FROM repository WHERE _id = :id and deleted == 0")
|
@Query("SELECT * FROM repository WHERE _id = :id and deleted == 0")
|
||||||
fun get(id: Long): Repository?
|
fun get(id: Long): Repository?
|
||||||
|
|
||||||
|
@get:Query("SELECT * FROM repository WHERE deleted == 0 ORDER BY _id ASC")
|
||||||
|
val allCursor: Cursor
|
||||||
|
|
||||||
@get:Query("SELECT * FROM repository WHERE deleted == 0 ORDER BY _id ASC")
|
@get:Query("SELECT * FROM repository WHERE deleted == 0 ORDER BY _id ASC")
|
||||||
val all: List<Repository>
|
val all: List<Repository>
|
||||||
|
|
||||||
@ -49,7 +56,7 @@ interface RepositoryDao : BaseDao<Repository> {
|
|||||||
// TODO optimize
|
// TODO optimize
|
||||||
@Update(onConflict = OnConflictStrategy.REPLACE)
|
@Update(onConflict = OnConflictStrategy.REPLACE)
|
||||||
fun markAsDeleted(id: Long) {
|
fun markAsDeleted(id: Long) {
|
||||||
get(id).apply { this?.deleted = 1 }?.let { update(it) }
|
get(id).apply { this?.deleted = true }?.let { update(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +66,7 @@ interface ProductDao : BaseDao<Product> {
|
|||||||
fun countForRepository(id: Long): Long
|
fun countForRepository(id: Long): Long
|
||||||
|
|
||||||
@Query("SELECT * FROM product WHERE package_name = :packageName")
|
@Query("SELECT * FROM product WHERE package_name = :packageName")
|
||||||
fun get(packageName: String): Product?
|
fun get(packageName: String): List<Product?>
|
||||||
|
|
||||||
@Query("DELETE FROM product WHERE repository_id = :id")
|
@Query("DELETE FROM product WHERE repository_id = :id")
|
||||||
fun deleteById(vararg id: Long): Int
|
fun deleteById(vararg id: Long): Int
|
||||||
@ -158,7 +165,7 @@ interface ProductDao : BaseDao<Product> {
|
|||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface CategoryDao : BaseDao<Category> {
|
interface CategoryDao : BaseDao<Category> {
|
||||||
@Query(
|
@get:Query(
|
||||||
"""SELECT DISTINCT category.name
|
"""SELECT DISTINCT category.name
|
||||||
FROM category AS category
|
FROM category AS category
|
||||||
JOIN repository AS repository
|
JOIN repository AS repository
|
||||||
@ -166,7 +173,7 @@ interface CategoryDao : BaseDao<Category> {
|
|||||||
WHERE repository.enabled != 0 AND
|
WHERE repository.enabled != 0 AND
|
||||||
repository.deleted == 0"""
|
repository.deleted == 0"""
|
||||||
)
|
)
|
||||||
fun getAll(): List<String>
|
val allNames: List<String>
|
||||||
|
|
||||||
@Query("DELETE FROM category WHERE repository_id = :id")
|
@Query("DELETE FROM category WHERE repository_id = :id")
|
||||||
fun deleteById(vararg id: Long): Int
|
fun deleteById(vararg id: Long): Int
|
||||||
@ -174,8 +181,18 @@ interface CategoryDao : BaseDao<Category> {
|
|||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface InstalledDao : BaseDao<Installed> {
|
interface InstalledDao : BaseDao<Installed> {
|
||||||
|
fun put(vararg isntalled: com.looker.droidify.entity.InstalledItem) {
|
||||||
|
isntalled.forEach {
|
||||||
|
insert(Installed(it.packageName).apply {
|
||||||
|
version = it.version
|
||||||
|
version_code = it.versionCode
|
||||||
|
signature = it.signature
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Query("SELECT * FROM `memory.installed` WHERE package_name = :packageName")
|
@Query("SELECT * FROM `memory.installed` WHERE package_name = :packageName")
|
||||||
fun get(packageName: String): Installed?
|
fun get(packageName: String): Cursor
|
||||||
|
|
||||||
@Query("DELETE FROM 'memory.installed' WHERE package_name = :packageName")
|
@Query("DELETE FROM 'memory.installed' WHERE package_name = :packageName")
|
||||||
fun delete(packageName: String)
|
fun delete(packageName: String)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user