yesodweb / yesodweb/persistent

No builtin support for UUID

Open
#579 18 comments 2 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.