问题描述
刚刚开始使用Kotlin Flow。
如果记录是唯一的,我基本上只想将一个项目插入房间数据库。
我以为我可以使用.as-console-wrapper { max-height: 100% !important; top: 0; }
来做到这一点,但是@Insert(onConflict = OnConflictStrategy.REPLACE)
将永远是唯一的。我总是需要检查PlateText。
到目前为止,我已经掌握了这一点,我正在寻找可以对其进行优化的方法。
imageUrl
欢迎任何想法。
解决方法
为什么不使用
if exists select 1 from (table name) where (id or imageUrl) = :(your parameter i.e imageUrl)
在函数中查询并返回布尔值
如果存在,它将返回true否则为false