summaryrefslogtreecommitdiff
path: root/Database
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-12-15 13:05:23 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-12-15 13:05:23 -0400
commit9ffa457d56b728ec19b05c918e035587ac638d44 (patch)
tree3b0005a398aceebc71199c162ff7fb5a4731ba89 /Database
parent40b2d8ce41d3f8032a5185962d72c8bb20d0352b (diff)
add getAssociatedKey
I guess this is just as efficient as the getAssociatedFiles query, but I have not tried to optimise the database yet.
Diffstat (limited to 'Database')
-rw-r--r--Database/Keys.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/Database/Keys.hs b/Database/Keys.hs
index 78d583d63..62c7c25eb 100644
--- a/Database/Keys.hs
+++ b/Database/Keys.hs
@@ -17,6 +17,7 @@ module Database.Keys (
shutdown,
addAssociatedFile,
getAssociatedFiles,
+ getAssociatedKey,
removeAssociatedFile,
storeInodeCaches,
addInodeCaches,
@@ -118,6 +119,19 @@ getAssociatedFiles' sk = do
return (r ^. AssociatedFile)
return $ map unValue l
+{- Gets any keys that are on record as having a particular associated file.
+ - (Should be one or none but the database doesn't enforce that.) -}
+getAssociatedKey :: FilePath -> Annex [Key]
+getAssociatedKey f = withDbHandle $ \h -> H.queryDb h $
+ getAssociatedKey' f
+
+getAssociatedKey' :: FilePath -> SqlPersistM [Key]
+getAssociatedKey' f = do
+ l <- select $ from $ \r -> do
+ where_ (r ^. AssociatedFile ==. val f)
+ return (r ^. AssociatedKey)
+ return $ map (fromSKey . unValue) l
+
removeAssociatedFile :: Key -> FilePath -> Annex ()
removeAssociatedFile k f = withDbHandle $ \h -> H.queueDb h (\_ _ -> pure True) $
delete $ from $ \r -> do