Add settings page to manage tags
This commit is contained in:
@@ -9,10 +9,10 @@ import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface CustomAttrsDao {
|
||||
@Query("SELECT * FROM CustomAttributes WHERE type = :type AND key = :key LIMIT 1")
|
||||
@Query("SELECT * FROM CustomAttributes WHERE type = :type AND `key` = :key LIMIT 1")
|
||||
fun getCustomAttribute(key: String, type: String) : Flow<CustomAttributeEntity?>
|
||||
|
||||
@Query("DELETE FROM CustomAttributes WHERE type = :type AND key = :key")
|
||||
@Query("DELETE FROM CustomAttributes WHERE type = :type AND `key` = :key")
|
||||
fun clearCustomAttribute(key: String, type: String)
|
||||
|
||||
@Insert
|
||||
@@ -21,10 +21,10 @@ interface CustomAttrsDao {
|
||||
@Insert
|
||||
suspend fun insertCustomAttributes(entities: List<CustomAttributeEntity>)
|
||||
|
||||
@Query("SELECT * FROM CustomAttributes WHERE type = :type AND key IN (:keys)")
|
||||
@Query("SELECT * FROM CustomAttributes WHERE type = :type AND `key` IN (:keys)")
|
||||
fun getCustomAttributes(keys: List<String>, type: String) : Flow<List<CustomAttributeEntity>>
|
||||
|
||||
@Query("SELECT DISTINCT key FROM CustomAttributes WHERE (type = 'label' OR type = 'tag') AND value LIKE :query")
|
||||
@Query("SELECT DISTINCT `key` FROM CustomAttributes WHERE (type = 'label' OR type = 'tag') AND value LIKE :query")
|
||||
fun search(query: String): Flow<List<String>>
|
||||
|
||||
@Transaction
|
||||
@@ -34,24 +34,30 @@ interface CustomAttrsDao {
|
||||
}
|
||||
|
||||
@Query("SELECT DISTINCT value FROM CustomAttributes WHERE type = 'tag' AND value LIKE :like ORDER BY value")
|
||||
suspend fun getAllTagsLike(like: String): List<String>
|
||||
fun getAllTagsLike(like: String): Flow<List<String>>
|
||||
|
||||
@Query("SELECT DISTINCT value FROM CustomAttributes WHERE type = 'tag' ORDER BY value")
|
||||
suspend fun getAllTags(): List<String>
|
||||
fun getAllTags(): Flow<List<String>>
|
||||
|
||||
@Query("SELECT key FROM CustomAttributes WHERE type = 'tag' AND value = :tag")
|
||||
@Query("SELECT `key` FROM CustomAttributes WHERE type = 'tag' AND value = :tag")
|
||||
fun getItemsWithTag(tag: String): Flow<List<String>>
|
||||
|
||||
@Transaction
|
||||
suspend fun setItemsWithTag(tag: String, items: List<String>) {
|
||||
deleteTag(tag)
|
||||
insertCustomAttributes(items.map { CustomAttributeEntity(it, "tag", tag) })
|
||||
}
|
||||
|
||||
@Transaction
|
||||
suspend fun addTag(key: String, tag: String) {
|
||||
removeTag(key, tag)
|
||||
insertTag(key, tag)
|
||||
}
|
||||
|
||||
@Query("DELETE FROM CustomAttributes WHERE type = 'tag' AND key = :key AND value = :tag")
|
||||
@Query("DELETE FROM CustomAttributes WHERE type = 'tag' AND `key` = :key AND value = :tag")
|
||||
suspend fun removeTag(key: String, tag: String)
|
||||
|
||||
@Query("INSERT INTO CustomAttributes (key, value, type) VALUES (:key, :tag, 'tag')")
|
||||
@Query("INSERT INTO CustomAttributes (`key`, value, type) VALUES (:key, :tag, 'tag')")
|
||||
suspend fun insertTag(key: String, tag: String)
|
||||
|
||||
@Query("UPDATE CustomAttributes SET value = :newName WHERE value = :oldName AND type = 'tag'")
|
||||
|
||||
Reference in New Issue
Block a user