mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-22 19:02:12 +00:00
Fix: UNIQUE id failure for Repository
This commit is contained in:
parent
5db9aa2591
commit
3e4aa20c3d
@ -10,7 +10,7 @@ import com.looker.droidify.entity.ProductItem
|
|||||||
|
|
||||||
|
|
||||||
interface BaseDao<T> {
|
interface BaseDao<T> {
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert
|
||||||
fun insert(vararg product: T)
|
fun insert(vararg product: T)
|
||||||
|
|
||||||
@Update(onConflict = OnConflictStrategy.REPLACE)
|
@Update(onConflict = OnConflictStrategy.REPLACE)
|
||||||
@ -22,20 +22,23 @@ interface BaseDao<T> {
|
|||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface RepositoryDao : BaseDao<Repository> {
|
interface RepositoryDao : BaseDao<Repository> {
|
||||||
|
@get:Query("SELECT COUNT(_id) FROM repository")
|
||||||
|
val count: Int
|
||||||
|
|
||||||
fun put(repository: com.looker.droidify.entity.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
|
if (it.id >= 0L) id = it.id
|
||||||
enabled = if (it.enabled) 1 else 0
|
enabled = if (it.enabled) 1 else 0
|
||||||
deleted = false
|
deleted = false
|
||||||
data = it
|
data = it
|
||||||
}
|
}
|
||||||
val newId = if (repository.id >= 0L) update(dbRepo).toLong() else returnInsert(dbRepo)
|
val newId = if (it.id > 0L) update(dbRepo).toLong() else returnInsert(dbRepo)
|
||||||
return if (newId != repository.id) repository.copy(id = newId) else repository
|
return if (newId != repository.id) repository.copy(id = newId) else repository
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert
|
||||||
fun returnInsert(product: Repository): Long
|
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")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user