Skip to content

Commit

Permalink
keyToId function, use type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhus committed Mar 5, 2012
1 parent 18758c5 commit 807d960
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Snap/Snaplet/Redson/CRUD.hs
Expand Up @@ -35,6 +35,15 @@ instanceKey :: ModelName -> InstanceId -> B.ByteString
instanceKey model id = B.concat [model, ":", id]


------------------------------------------------------------------------------
-- | Cut instance model and id from Redis key
--
-- >>> keyToId "case:32198"
-- 32198
keyToId :: B.ByteString -> InstanceId
keyToId key = B.tail $ B.dropWhile (/= 0x3a) key


------------------------------------------------------------------------------
-- | Get Redis key which stores id counter for model
modelIdKey :: ModelName -> B.ByteString
Expand Down Expand Up @@ -128,7 +137,7 @@ deleteIndices mname id commit =
create :: ModelName -- ^ Model name
-> Commit -- ^ Key-values of instance data
-> [FieldName] -- ^ Index fields
-> Redis (Either Error B.ByteString)
-> Redis (Either Error InstanceId)
create mname commit findices = do
-- Take id from global:model:id
Right n <- incr $ modelIdKey mname
Expand Down

0 comments on commit 807d960

Please sign in to comment.