"INSERT INTO photo_preferences(source_id,item_id,starred,excluded) VALUES(?,?,?,?) ON CONFLICT(source_id,item_id) DO UPDATE SET starred=coalesce(?,starred),excluded=coalesce(?,excluded)",
(
source_id,
item_id,
int(starredorFalse),
int(excludedorFalse),
NoneifstarredisNoneelseint(starred),
NoneifexcludedisNoneelseint(excluded),
),
)
returnflags(db,source_id,item_id)
defannotate(db,source_id,items):
preferences={
row["item_id"]:row
forrowindb.all(
"SELECT item_id,starred,excluded FROM photo_preferences WHERE source_id=?",
(source_id,),
)
}
return[
{
**item,
**{
key:bool(preferences.get(item["id"],{}).get(key))
forkeyin("starred","excluded")
},
}
foriteminitems
]
defeligible(db,source_id,items):
excluded={
row["item_id"]
forrowindb.all(
"SELECT item_id FROM photo_preferences WHERE source_id=? AND excluded=1",