Commit e0450606 authored by MrMan's avatar MrMan

Add getByID implementation

parent 5c9e849f
......@@ -331,15 +331,21 @@ getEntityByUUID conn uuid = (query conn selectQuery (Only uuid) :: IO [WithID 'U
instance SQLEntityStore SQLiteEntityStore where
create store (Validated entity) = withActiveConn store _work
where
_work c = ensureUUID entity
_work conn = ensureUUID entity
>>= rightOrThrow
-- | Generate an insert query for the `WithID entity`
>>= insertAndReturnEntity c
>>= insertAndReturnEntity conn
>>= rightOrThrow
-- | We need to obscure the type to match for "any" ident
>>= pure . Right . uuidToGenericIdent
getByID store eid = undefined
getByID store eid = withActiveConn store _work
where
_work conn = case eid of
(Left uuid) -> getEntityByUUID conn uuid
>>= rightOrThrow
>>= pure . Right . uuidToGenericIdent
_ -> pure $ Left $ UnsupportedOperationES "integer-identified entities are currently unsupported"
updateByID store eid (Validated partial) = undefined
......
......@@ -287,6 +287,7 @@ data EntityStoreError = NoSuchEntityES EntityID DT.Text
| UnexpectedErrorES DT.Text
| DisconnectedES DT.Text
| ConnectionFailureES DT.Text
| UnsupportedOperationES DT.Text
deriving (Eq, Show, Read)
instance Exception EntityStoreError
......@@ -315,7 +316,8 @@ class SQLEntityStore store where
-- | Get an entity by ID
getByID :: forall (ident :: Identifier) (entity :: FBounded).
FromRow (Complete entity)
( SQLInsertable (Complete entity)
, FromRow (Complete entity))
=> store
-> EntityID
-> IO (Either EntityStoreError (WithID ident (Complete entity)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment