mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
refactor: migrate nodeDB to Room database (#717)
This commit is contained in:
parent
99d7147efe
commit
83722159be
14 changed files with 742 additions and 148 deletions
|
|
@ -0,0 +1,21 @@
|
|||
package com.geeksville.mesh.database.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.geeksville.mesh.MyNodeInfo
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface MyNodeInfoDao {
|
||||
|
||||
@Query("SELECT * FROM MyNodeInfo")
|
||||
fun getMyNodeInfo(): Flow<MyNodeInfo?>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun setMyNodeInfo(myInfo: MyNodeInfo?)
|
||||
|
||||
@Query("DELETE FROM MyNodeInfo")
|
||||
fun clearMyNodeInfo()
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package com.geeksville.mesh.database.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.Upsert
|
||||
import com.geeksville.mesh.NodeInfo
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface NodeInfoDao {
|
||||
|
||||
@Query("SELECT * FROM NodeInfo")
|
||||
fun getNodes(): Flow<List<NodeInfo>>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insert(node: NodeInfo)
|
||||
|
||||
@Upsert
|
||||
fun upsert(node: NodeInfo)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun putAll(nodes: List<NodeInfo>)
|
||||
|
||||
@Query("DELETE FROM NodeInfo")
|
||||
fun clearNodeInfo()
|
||||
|
||||
@Query("SELECT * FROM NodeInfo WHERE num=:num")
|
||||
fun getNodeInfo(num: Int): NodeInfo?
|
||||
|
||||
// @Transaction
|
||||
// suspend fun updateUser(num: Int, updatedUser: MeshUser) {
|
||||
// getNodeInfo(num)?.let {
|
||||
// val updatedNodeInfo = it.copy(user = updatedUser)
|
||||
// upsert(updatedNodeInfo)
|
||||
// }
|
||||
// }
|
||||
|
||||
// @Query("Update node_info set position=:position WHERE num=:num")
|
||||
// fun updatePosition(num: Int, position: MeshProtos.Position)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue