-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
다대다 구조 Relation을 이용해서 구현 / Fix: Foreign Key Constraint Fail… #53
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
감사합니다 👏
@@ -37,15 +52,20 @@ class MomentRepositoryImpl @Inject constructor( | |||
return | |||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분에 else
가 필요 없어 보입니다. 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
맞네요 early return
OR detailAddress LIKE '%' || :query || '%' | ||
OR content LIKE '%' || :query || '%' | ||
ORDER BY | ||
CASE WHEN :sortType = 0 THEN date END DESC, | ||
CASE WHEN :sortType = 1 THEN date END ASC | ||
""" | ||
) | ||
fun getMoments(sortType: Int = 0, query: String): PagingSource<Int, MomentEntity> | ||
fun getMoments(sortType: Int = 0, query: String): PagingSource<Int, MomentWithGlobesAndPictures> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
검색 기능이 이미 구현된건가요? 제 담당이긴 한데 😅
query
없이 모먼트를 가져오려면, query = ""
를 파라미터 값으로 넘겨줘야 할까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
검색 기능이 재민님이 구현하신 내용인데 검색 없이는 ""
맞습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
엇 검색 쿼리는 원래 있었는데 저는 정렬만 추가했습니다!
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun saveMoment(moment: MomentEntity): Long | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
@Insert(onConflict = OnConflictStrategy.IGNORE) | ||
suspend fun savePicture(picture: List<PictureEntity>): List<Long> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
헷갈리지 않도록 s
를 추가해서 savePictures()
로 변경하는게 어떨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 좋습니다!
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun saveMoment(moment: MomentEntity): Long | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
@Insert(onConflict = OnConflictStrategy.IGNORE) | ||
suspend fun savePicture(picture: List<PictureEntity>): List<Long> | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun saveMomentPicture(momentPictures: List<MomentPictureEntity>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기도 같은 맥락으로 s
를 추가해서 saveMomentPictures()
어떨까요?
뭔가 Picture
에만 s
가 붙는게 이상하게 느껴지신다면,
MomentPictureCrossRefEntity
또는 MomentPictureXRefEntity
와 같이 Entity
이름을 변경하신다면
saveMomentPictureCrossRefs()
로 표기할 수 도 있을 것 같습니다.
공식 문서에도 사용하는 네이밍 방식입니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
최대한 폴더 이름과 같게 하려고 했어요 entity
폴더니까 entitiy
로 끝내야된다..? 따라서 그런데 공식 문서처럼 바꾸는 것이 좋은 네이밍 같아요. 뒤에만 s
붙이는건 오해의 여지가 있으니까..? 변경하겠습니다.
MomentGlobeEntity
-> MomentGlobeXRef
MomentPictureEntity
-> MomentPictureXRef
함수 네이밍
suspend fun saveMomentPictures(momentPictures: List<MomentPictureXRef>)
->
suspend fun saveMomentPictureXRefs(momentPictures: List<MomentPictureXRef>)
suspend fun saveMomentGlobe(momentGlobe: MomentGlobeXRef)
->
suspend fun saveMomentGlobeXRef(momentGlobe: MomentGlobeXRef)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다 🙂
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun saveMoment(moment: MomentEntity): Long | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
@Insert(onConflict = OnConflictStrategy.IGNORE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IGNORE 가 존재했군요!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 들어가는 걸 update
하는 것이 아니라 ignore
하는 겁니다! 들어간다면, 업데이트된 id
를 다시 잇는 과정보다는 찾는 과정이 더 빠를 것 같아서 선택했습니다
@@ -10,6 +10,6 @@ import androidx.room.PrimaryKey | |||
indices = [Index(value = ["name"], unique = true)] | |||
) | |||
data class GlobeEntity( | |||
@PrimaryKey(autoGenerate = true) val id: Long = 0L, | |||
@PrimaryKey(autoGenerate = true) @ColumnInfo(name = "globe_entity_id") val id: Long = 0L, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
모든 entity 의 id 를 동일하게 한다면, 중간에 entity 를 빼고 동일하게 해도 좋을 것 같습니다!🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 아까 이야기한 것처럼 id
이름에 entity
모두 제거했습니다!
val indexResult = momentDao.savePicture(pictures).toMutableList() | ||
indexResult.forEachIndexed { pictureIndex, id -> | ||
if (id == EXIST_INSERT_ERROR_CODE) { | ||
indexResult[pictureIndex] = momentDao.getPictureByByteArray(pictures[pictureIndex].bitmap) | ||
} | ||
} | ||
return indexResult.toList() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저장 한 Picture 들의 아이디를 들고 와서 충돌이 났다면 해당 인덱스는 업데이트된 아이디를 넣어주는 듯 하군요!! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 충돌 난 것만 다시 가져오고 리스트로 반환하는 방식으로 로직을 변경했습니다. ignore
당한 id
는 -1
로 받아서요!
…ed 에러 해결 (#52 (comment))
🚀 Issue #5 + #52
@Insert(onConflict = OnConflictStrategy.REPLACE)
로 인해서, SQLite Foreign Key Constraint Failed (code 787) 에러 발생-> 해결:
@Insert(onConflict = OnConflictStrategy.IGNORE)
이후, 중복 값이 들어온다면 체크 후, id를 바꿔서 보내주는 형태👨🔧 개요
📝 작업 내용
📢 특이 사항