Skip to content

Commit 44e106f

Browse files
committed
wip
1 parent e5a0bf0 commit 44e106f

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

prv

Submodule prv updated from 9058c11 to dbd0c10

pub/functora/src/cfg/Functora/Cfg.hs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module Functora.Cfg
1313

1414
-- * TOML
1515
-- $toml
16+
unToml,
1617
decodeToml,
1718
encodeToml,
1819

@@ -131,6 +132,22 @@ encodeJson =
131132
-- $toml
132133
-- TOML
133134

135+
unToml ::
136+
( Generic a,
137+
Typeable a,
138+
Toml.GenericCodec (Rep a),
139+
MonadThrow m
140+
) =>
141+
Text ->
142+
m a
143+
unToml =
144+
either
145+
( throwString
146+
. prettyTomlDecodeErrors
147+
)
148+
pure
149+
. decodeToml
150+
134151
decodeToml ::
135152
( Generic a,
136153
Typeable a,

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Functora.Sql
33
upsertBy,
44
selectOneRequired,
55
runMigrationPool,
6+
PersistNat (..),
67
(^:),
78
)
89
where
@@ -117,24 +118,37 @@ import Database.Persist.TH as X
117118
sqlSettings,
118119
)
119120
import Functora.Prelude
120-
( HasCallStack,
121+
( Data,
122+
Eq,
123+
Generic,
124+
HasCallStack,
125+
Int64,
121126
Maybe (..),
122127
MonadIO,
123128
MonadThrow,
124129
MonadUnliftIO,
130+
Natural,
125131
NonEmpty,
132+
Ord,
133+
Read,
126134
ReaderT,
135+
Show,
127136
Text,
128137
Type,
129138
Typeable,
139+
bimap,
140+
either,
130141
flip,
142+
impureThrow,
143+
inspect,
131144
inspectType,
132145
liftIO,
133146
maybeM,
134147
pure,
135148
runReaderT,
136149
throwString,
137150
toList,
151+
tryFrom,
138152
($),
139153
(.),
140154
(<>),
@@ -213,6 +227,29 @@ runMigrationPool r pconn =
213227
runReaderT `flip` conn $ act
214228
whenSqlite _ _ = pure ()
215229

230+
newtype PersistNat = PersistNat
231+
{ unPersistNat :: Natural
232+
}
233+
deriving stock
234+
( Eq,
235+
Ord,
236+
Show,
237+
Read,
238+
Data,
239+
Generic
240+
)
241+
242+
instance PersistField PersistNat where
243+
toPersistValue =
244+
either impureThrow toPersistValue
245+
. tryFrom @Natural @Int64
246+
. unPersistNat
247+
fromPersistValue raw = do
248+
int <- fromPersistValue raw
249+
bimap inspect PersistNat $ tryFrom @Int64 @Natural int
250+
251+
deriving via Int64 instance PersistFieldSql PersistNat
252+
216253
-- | Project a field of an entity.
217254
-- Alias exists to remove interference with Lens.
218255
(^:) ::

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE TemplateHaskell #-}
12
{-# LANGUAGE UndecidableInstances #-}
23
{-# OPTIONS_GHC -Wno-orphans #-}
34

@@ -7,6 +8,7 @@ import qualified Data.Data as Data
78
import Data.UUID (UUID)
89
import qualified Data.UUID as UUID
910
import Database.Esqueleto.Legacy hiding (from)
11+
import Database.Persist.TH
1012
import Functora.Money
1113
import Functora.Prelude hiding (Key)
1214
import qualified Text.URI as URI
@@ -86,3 +88,17 @@ instance (PersistField rep) => PersistField (NonEmpty rep) where
8688

8789
instance (PersistFieldSql rep) => PersistFieldSql (NonEmpty rep) where
8890
sqlType = const . sqlType $ Proxy @[rep]
91+
92+
derivePersistField "BuyOrSell"
93+
94+
deriving newtype instance PersistField MoneyAmount
95+
96+
deriving newtype instance PersistFieldSql MoneyAmount
97+
98+
deriving newtype instance PersistField QuotePerBase
99+
100+
deriving newtype instance PersistFieldSql QuotePerBase
101+
102+
deriving newtype instance PersistField CurrencyCode
103+
104+
deriving newtype instance PersistFieldSql CurrencyCode

0 commit comments

Comments
 (0)