fix bug, make cassava optional

This commit is contained in:
Ville Tirronen 2022-07-28 12:30:13 +03:00
parent 7994085581
commit b8ee3fa019
2 changed files with 19 additions and 3 deletions

View File

@ -4,6 +4,11 @@ name: id
version: 0.1.0.0
license-file: LICENSE
Flag cassava
Description: Enable Postgresql support
Default: True
Manual: False
Flag postgres
Description: Enable Postgresql support
@ -42,9 +47,10 @@ library
build-depends:
postgresql-simple
cpp-options: -DUSE_POSTGRES
if !impl(ghcjs)
if flag(cassava) && !impl(ghcjs)
build-depends:
cassava
cpp-options: -DUSE_CASSAVA
if flag(flat)
build-depends:
flat,

View File

@ -25,7 +25,9 @@ import Data.UUID (UUID)
import qualified Data.UUID as UUID
import qualified Data.UUID.V4 as UUID.V4
#ifndef ghcjs_HOST_OS
#ifdef USE_CASSAVA
import Data.Csv as Csv hiding(Name)
#endif
#ifdef USE_POSTGRES
import Database.PostgreSQL.Simple.FromField as PG (FromField)
import Database.PostgreSQL.Simple.ToField as PG (ToField)
@ -102,12 +104,14 @@ instance PathPiece (Id t) where
#ifndef ghcjs_HOST_OS
#ifdef USE_CASSAVA
instance Csv.FromField (Id tag) where
parseField = parseField
>=> fmap mkId . maybe (fail "invalid UUID in CSV") pure . UUID.fromText
instance Csv.ToField (Id tag) where
toField = Csv.toField . UUID.toText . coerce
#endif
#endif
@ -135,7 +139,10 @@ newtype IntId t = IntId { unIntId :: Integer }
( Eq, Ord, Binary
#ifndef ghcjs_HOST_OS
#ifdef USE_POSTGRES
, PG.ToField, PG.FromField, Csv.ToField, Csv.FromField
, PG.ToField, PG.FromField
#endif
#ifdef USE_CASSAVA
, Csv.ToField, Csv.FromField
#endif
#endif
, FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
@ -175,7 +182,10 @@ newtype Name t = Name { unName :: Text }
( Eq, Ord, Binary
#ifndef ghcjs_HOST_OS
#ifdef USE_POSTGRES
, PG.ToField, PG.FromField, Csv.ToField, Csv.FromField
, PG.ToField, PG.FromField
#endif
#ifdef USE_CASSAVA
, Csv.ToField, Csv.FromField
#endif
#endif
, FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema