Skip to content

Commit

Permalink
Fix typing issue between SQLite and Postgres
Browse files Browse the repository at this point in the history
SQLDelight returns the Long value directly on Postgres while it wraps it
in a result type on SQLDelight.
  • Loading branch information
antweb committed Oct 4, 2024
1 parent 8a1d24b commit 873f478
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,10 @@ class AsyncCheckProvider(private val config: ConfigStore, private val dataStore:
val filteredCandidates = if (!list.allItems) {
val items = db.checkInListQueries.selectItemIdsForList(list.id)
.executeAsList()
.map {
// Not-null assertion needed for SQLite
it.id!!
}
.toHashSet()
candidates.filter { candidate ->
val candidateItem = db.itemQueries.selectById(candidate.itemId).executeAsOne()
Expand Down Expand Up @@ -978,7 +982,13 @@ class AsyncCheckProvider(private val config: ConfigStore, private val dataStore:
).executeAsOneOrNull() ?: throw CheckException("Check-in list not found")

val itemIds = if (!list.all_items) {
db.checkInListQueries.selectItemIdsForList(list.id).executeAsList().ifEmpty { null }
db.checkInListQueries.selectItemIdsForList(list.id)
.executeAsList()
.map {
// Not-null assertion needed for SQLite
it.id!!
}
.ifEmpty { null }
} else {
null
}
Expand Down Expand Up @@ -1137,7 +1147,12 @@ class AsyncCheckProvider(private val config: ConfigStore, private val dataStore:
}

if (!list.allItems) {
val product_ids = db.checkInListQueries.selectItemIdsForList(list.id).executeAsList()
val product_ids = db.checkInListQueries.selectItemIdsForList(list.id)
.executeAsList()
.map {
// Not-null assertion needed for SQLite
it.id!!
}
lq = lq.and(OrderPosition.ITEM_ID.`in`(product_ids))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ DELETE FROM CheckInList_Item
WHERE CheckInListId = :checkin_list_id;

selectItemIdsForList:
SELECT ItemId
-- We must select at least two columns, otherwise we get different result types between
-- SQLite and Postgres since the ItemId column is only defined as NOT NULL in Postgres
SELECT ItemId AS id, CheckInListId
FROM CheckInList_Item
WHERE CheckInListId = :checkin_list_id;

Expand Down

0 comments on commit 873f478

Please sign in to comment.