yesodweb / yesodweb/persistent
No builtin support for UUID
Open
Nobody has claimed this yet.
- Dominant language
- Haskell
- Stars
- 486
- Forks
- 306
- PR merge metrics
- No merged PRs in 30d
Description
Should support for UUIDs be built in to persistent or should it be its own package? FYI, the own package version might look something like
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Instances where
import Control.Error.Util
import Data.UUID (UUID)
import qualified Data.UUID as UUID
import qualified Data.ByteString.Lazy as BSL
import Database.Persist.Sql
import Web.HttpApiData
instance PersistField UUID where
toPersistValue = PersistDbSpecific . BSL.toStrict . UUID.toByteString
fromPersistValue (PersistDbSpecific t) =
case UUID.fromByteString $ BSL.fromStrict t of
Just x -> Right x
Nothing -> Left "Invalid UUID"
fromPersistValue _ = Left "Not PersistDBSpecific"
instance PersistFieldSql UUID where
sqlType _ = SqlOther "uuid"
instance PathPiece UUID where
toPathPiece = toUrlPiece
fromPathPiece = hush . parseUrlPiece
instance ToHttpApiData UUID where
toUrlPiece = UUID.toText
instance FromHttpApiData UUID where
parseUrlPiece uuid = note ("Error parsing UUID " <> uuid) . UUID.fromText $ uuid
instance ToJSON UUID where
toJSON = toJSON . UUID.toText
instance FromJSON UUID where
parseJSON uuid = maybe (fail $ "Error parsing UUID " <> show uuid) pure . UUID.fromText <=< parseJSON $ uuid
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the issue discussion and the proposed Instances module, including its Database.Persist.Sql UUID instances. Review the tradeoff between adding UUID support to persistent and maintaining it as a separate package; done requires a settled project direction and an agreed implementation scope.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100