Update instance if it already exists (to enable multiple accounts of same instance)
This commit is contained in:
parent
960eb0cdc1
commit
0fdcdf3c21
@ -49,5 +49,5 @@ fun storeInstance(db: AppDatabase, nodeInfo: NodeInfo?, instance: Instance? = nu
|
|||||||
)
|
)
|
||||||
} ?: throw IllegalArgumentException("Cannot store instance where both are null")
|
} ?: throw IllegalArgumentException("Cannot store instance where both are null")
|
||||||
|
|
||||||
db.instanceDao().insertInstance(dbInstance)
|
db.instanceDao().insertOrUpdate(dbInstance)
|
||||||
}
|
}
|
@ -1,9 +1,6 @@
|
|||||||
package com.h.pixeldroid.utils.db.dao
|
package com.h.pixeldroid.utils.db.dao
|
||||||
|
|
||||||
import androidx.room.Dao
|
import androidx.room.*
|
||||||
import androidx.room.Insert
|
|
||||||
import androidx.room.OnConflictStrategy
|
|
||||||
import androidx.room.Query
|
|
||||||
import com.h.pixeldroid.utils.db.entities.InstanceDatabaseEntity
|
import com.h.pixeldroid.utils.db.entities.InstanceDatabaseEntity
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
@ -11,6 +8,19 @@ interface InstanceDao {
|
|||||||
@Query("SELECT * FROM instances")
|
@Query("SELECT * FROM instances")
|
||||||
fun getAll(): List<InstanceDatabaseEntity>
|
fun getAll(): List<InstanceDatabaseEntity>
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
/**
|
||||||
fun insertInstance(instance: InstanceDatabaseEntity)
|
* Insert an instance, if it already exists return -1
|
||||||
|
*/
|
||||||
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
|
fun insertInstance(instance: InstanceDatabaseEntity): Long
|
||||||
|
|
||||||
|
@Update
|
||||||
|
fun updateInstance(instance: InstanceDatabaseEntity)
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
fun insertOrUpdate(instance: InstanceDatabaseEntity) {
|
||||||
|
if (insertInstance(instance) == -1L) {
|
||||||
|
updateInstance(instance)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user