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 ...@@ -331,15 +331,21 @@ getEntityByUUID conn uuid = (query conn selectQuery (Only uuid) :: IO [WithID 'U
instance SQLEntityStore SQLiteEntityStore where instance SQLEntityStore SQLiteEntityStore where
create store (Validated entity) = withActiveConn store _work create store (Validated entity) = withActiveConn store _work
where where
_work c = ensureUUID entity _work conn = ensureUUID entity
>>= rightOrThrow >>= rightOrThrow
-- | Generate an insert query for the `WithID entity` -- | Generate an insert query for the `WithID entity`
>>= insertAndReturnEntity c >>= insertAndReturnEntity conn
>>= rightOrThrow >>= rightOrThrow
-- | We need to obscure the type to match for "any" ident -- | We need to obscure the type to match for "any" ident
>>= pure . Right . uuidToGenericIdent >>= 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 updateByID store eid (Validated partial) = undefined
......
...@@ -287,6 +287,7 @@ data EntityStoreError = NoSuchEntityES EntityID DT.Text ...@@ -287,6 +287,7 @@ data EntityStoreError = NoSuchEntityES EntityID DT.Text
| UnexpectedErrorES DT.Text | UnexpectedErrorES DT.Text
| DisconnectedES DT.Text | DisconnectedES DT.Text
| ConnectionFailureES DT.Text | ConnectionFailureES DT.Text
| UnsupportedOperationES DT.Text
deriving (Eq, Show, Read) deriving (Eq, Show, Read)
instance Exception EntityStoreError instance Exception EntityStoreError
...@@ -315,7 +316,8 @@ class SQLEntityStore store where ...@@ -315,7 +316,8 @@ class SQLEntityStore store where
-- | Get an entity by ID -- | Get an entity by ID
getByID :: forall (ident :: Identifier) (entity :: FBounded). getByID :: forall (ident :: Identifier) (entity :: FBounded).
FromRow (Complete entity) ( SQLInsertable (Complete entity)
, FromRow (Complete entity))
=> store => store
-> EntityID -> EntityID
-> IO (Either EntityStoreError (WithID ident (Complete entity))) -> 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