diff options
author | Ben Sima <ben@bsima.me> | 2021-01-19 18:52:41 -0500 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2021-01-22 08:00:27 -0500 |
commit | 92d3ab89ffd6e65d5a79de0cf5907aad3786ce44 (patch) | |
tree | 29fdaa8a40f6a31f6298f15673a60e9e356c0239 /Biz/Id.hs | |
parent | e9578a7bb7c116cf71aea0313e64e64abb650f9e (diff) |
Persist Analysis runs
Keep Analysis runs, with a unique id, and index them based on ID, which user
asked for the analysis, and commit sha.
Diffstat (limited to 'Biz/Id.hs')
-rw-r--r-- | Biz/Id.hs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Biz/Id.hs b/Biz/Id.hs new file mode 100644 index 0000000..89c74bf --- /dev/null +++ b/Biz/Id.hs @@ -0,0 +1,42 @@ +{-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE NoImplicitPrelude #-} + +-- Integer-based identifier. +module Biz.Id + ( Id (..), + mk, + untag, + ) +where + +import Alpha +import Data.Aeson (FromJSON (..), ToJSON (..)) +import Data.Binary (Binary) +import Data.Data (Data) + +newtype Id entity = Id Int + deriving (Eq, Ord, Show, Generic, Typeable, Data) + +mk :: proxy entity -> Int -> Id entity +mk _ = Id + +untag :: Id entity -> Int +untag (Id i) = i + +instance Hashable (Id entity) + +instance Binary (Id entity) + +instance Enum (Id entity) where + toEnum n = mk (Proxy :: Proxy entity) n + fromEnum = untag + +instance NFData (Id entity) where + rnf (Id s) = rnf s + +instance FromJSON (Id entity) where + parseJSON = fmap Id <. parseJSON + +instance ToJSON (Id entity) where + toJSON = toJSON <. untag |