Skip to content

Commit 28c3b4e

Browse files
committed
fix some persist instances
1 parent 2906ab8 commit 28c3b4e

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

prv

Submodule prv updated from 4550c15 to 41ac912

pub/functora/src/prelude/Functora/Prelude.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,15 @@ import Data.Generics.Product as X
202202
import Data.Generics.Sum as X
203203
import Data.Generics.Uniplate.Data as X ()
204204
import qualified Data.HMAC as HMAC
205-
import Data.List.Extra as X (enumerate, notNull, nubOrd, nubOrdBy, nubOrdOn)
205+
import Data.List.Extra as X
206+
( enumerate,
207+
escapeHTML,
208+
notNull,
209+
nubOrd,
210+
nubOrdBy,
211+
nubOrdOn,
212+
unescapeHTML,
213+
)
206214
import qualified Data.Map.Merge.Strict as Map
207215
import Data.Maybe as X (listToMaybe)
208216
import Data.MonoTraversable as X (omap)

pub/functora/src/sql/Functora/Sql.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ module Functora.Sql
88
where
99

1010
import Control.Monad.Logger as X
11-
( defaultOutput,
11+
( LoggingT (..),
12+
MonadLoggerIO,
13+
NoLoggingT (..),
14+
defaultOutput,
1215
runLoggingT,
1316
runNoLoggingT,
17+
runStdoutLoggingT,
1418
)
1519
import Data.Pool as X (Pool, destroyAllResources)
1620
import qualified Database.Esqueleto.Internal.Internal as Internal
@@ -37,13 +41,15 @@ import Database.Esqueleto.Legacy as X
3741
Unique,
3842
Value,
3943
asc,
44+
delete,
4045
deleteKey,
4146
desc,
4247
distinct,
4348
distinctOn,
4449
don,
4550
from,
4651
getBy,
52+
groupBy,
4753
in_,
4854
insertBy,
4955
insertUniqueEntity,

pub/functora/src/sql/Functora/SqlOrphan.hs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ deriving stock instance (Data a, Data (Key a)) => Data (Entity a)
1919

2020
instance PersistField (Ratio Natural) where
2121
toPersistValue = PersistRational . from @(Ratio Natural) @Rational
22-
fromPersistValue = \case
23-
PersistRational x ->
24-
first (const $ failure x) $ tryFrom @Rational @(Ratio Natural) x
25-
x ->
26-
Left $ failure x
22+
fromPersistValue raw = do
23+
rat <- fromPersistValue raw
24+
first (const failure) $ tryFrom @Rational @(Ratio Natural) rat
2725
where
28-
failure x =
29-
"Ratio Natural PersistValue is invalid " <> inspect @Text x
26+
failure =
27+
"Ratio Natural PersistValue is invalid " <> inspect @Text raw
3028

3129
deriving via Rational instance PersistFieldSql (Ratio Natural)
3230

@@ -78,3 +76,13 @@ instance (PersistField rep) => PersistField (Tagged tags rep) where
7876

7977
instance (PersistFieldSql rep) => PersistFieldSql (Tagged tags rep) where
8078
sqlType = const . sqlType $ Proxy @rep
79+
80+
instance (PersistField rep) => PersistField (NonEmpty rep) where
81+
toPersistValue =
82+
toPersistValue . toList
83+
fromPersistValue raw = do
84+
lst <- fromPersistValue raw
85+
maybe (Left "Unexpected empty persist value") Right $ nonEmpty lst
86+
87+
instance (PersistFieldSql rep) => PersistFieldSql (NonEmpty rep) where
88+
sqlType = const . sqlType $ Proxy @[rep]

0 commit comments

Comments
 (0)