File tree Expand file tree Collapse file tree 4 files changed +72
-2
lines changed Expand file tree Collapse file tree 4 files changed +72
-2
lines changed Submodule prv updated from 9058c11 to dbd0c10
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ module Functora.Cfg
13
13
14
14
-- * TOML
15
15
-- $toml
16
+ unToml ,
16
17
decodeToml ,
17
18
encodeToml ,
18
19
@@ -131,6 +132,22 @@ encodeJson =
131
132
-- $toml
132
133
-- TOML
133
134
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
+
134
151
decodeToml ::
135
152
( Generic a ,
136
153
Typeable a ,
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ module Functora.Sql
3
3
upsertBy ,
4
4
selectOneRequired ,
5
5
runMigrationPool ,
6
+ PersistNat (.. ),
6
7
(^:) ,
7
8
)
8
9
where
@@ -117,24 +118,37 @@ import Database.Persist.TH as X
117
118
sqlSettings ,
118
119
)
119
120
import Functora.Prelude
120
- ( HasCallStack ,
121
+ ( Data ,
122
+ Eq ,
123
+ Generic ,
124
+ HasCallStack ,
125
+ Int64 ,
121
126
Maybe (.. ),
122
127
MonadIO ,
123
128
MonadThrow ,
124
129
MonadUnliftIO ,
130
+ Natural ,
125
131
NonEmpty ,
132
+ Ord ,
133
+ Read ,
126
134
ReaderT ,
135
+ Show ,
127
136
Text ,
128
137
Type ,
129
138
Typeable ,
139
+ bimap ,
140
+ either ,
130
141
flip ,
142
+ impureThrow ,
143
+ inspect ,
131
144
inspectType ,
132
145
liftIO ,
133
146
maybeM ,
134
147
pure ,
135
148
runReaderT ,
136
149
throwString ,
137
150
toList ,
151
+ tryFrom ,
138
152
($) ,
139
153
(.) ,
140
154
(<>) ,
@@ -213,6 +227,29 @@ runMigrationPool r pconn =
213
227
runReaderT `flip` conn $ act
214
228
whenSqlite _ _ = pure ()
215
229
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
+
216
253
-- | Project a field of an entity.
217
254
-- Alias exists to remove interference with Lens.
218
255
(^:) ::
Original file line number Diff line number Diff line change
1
+ {-# LANGUAGE TemplateHaskell #-}
1
2
{-# LANGUAGE UndecidableInstances #-}
2
3
{-# OPTIONS_GHC -Wno-orphans #-}
3
4
@@ -7,6 +8,7 @@ import qualified Data.Data as Data
7
8
import Data.UUID (UUID )
8
9
import qualified Data.UUID as UUID
9
10
import Database.Esqueleto.Legacy hiding (from )
11
+ import Database.Persist.TH
10
12
import Functora.Money
11
13
import Functora.Prelude hiding (Key )
12
14
import qualified Text.URI as URI
@@ -86,3 +88,17 @@ instance (PersistField rep) => PersistField (NonEmpty rep) where
86
88
87
89
instance (PersistFieldSql rep ) => PersistFieldSql (NonEmpty rep ) where
88
90
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
You can’t perform that action at this time.
0 commit comments