main.com.sceyt.chatuikit.persistence.dao.UserDao.kt Maven / Gradle / Ivy
package com.sceyt.chatuikit.persistence.dao
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Update
import com.sceyt.chatuikit.persistence.entity.user.UserDb
import com.sceyt.chatuikit.persistence.entity.user.UserEntity
import com.sceyt.chatuikit.persistence.entity.user.UserMetadataEntity
import kotlinx.coroutines.flow.Flow
@Dao
interface UserDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertUser(user: UserEntity)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertUsers(users: List)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertMetadata(list: List)
@Transaction
suspend fun insertUserWithMetadata(user: UserDb) {
insertUser(user.user)
insertMetadata(user.metadata)
}
@Transaction
suspend fun insertUsersWithMetadata(users: List) {
insertUsers(users.map { it.user })
insertMetadata(users.flatMap { it.metadata })
}
@Transaction
@Query("select * from users where user_id =:id")
suspend fun getUserById(id: String): UserDb?
@Transaction
@Query("select * from users where user_id =:id")
fun getUserByIdAsFlow(id: String): Flow
@Transaction
@Query("select * from users where user_id in (:id)")
suspend fun getUsersById(id: List): List
@Query("select user_id from users where firstName like '%' || :searchQuery || '%' " +
"or lastName like '%' || :searchQuery || '%' or (firstName || ' ' || lastName) like :searchQuery || '%'")
suspend fun getUserIdsByDisplayName(searchQuery: String): List
@Update(onConflict = OnConflictStrategy.REPLACE)
suspend fun updateUser(user: UserEntity)
@Update(onConflict = OnConflictStrategy.REPLACE)
suspend fun updateUsers(users: List)
@Query("update users set status =:status where user_id =:userId")
suspend fun updateUserStatus(userId: String, status: String)
@Query("update users set blocked =:blocked where user_id =:userId")
suspend fun blockUnBlockUser(userId: String, blocked: Boolean)
@Query("DELETE FROM users")
suspend fun deleteAll()
}