Skip to content

Commit

Permalink
Backend: Add Clickhouse Currency Instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuldeep Kumawat authored and khuzema786 committed May 3, 2024
1 parent 1a2b7d7 commit 132ee93
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import qualified Data.Scientific as Sci
import qualified Data.Text as T
import qualified Data.Time as Time
import Kernel.Prelude
import Kernel.Types.Common (Centesimal, HighPrecMeters, HighPrecMoney)
import Kernel.Types.Common (Centesimal, Currency, HighPrecMeters, HighPrecMoney)
import Kernel.Types.Id
import qualified Text.Read as T

Expand Down Expand Up @@ -54,6 +54,9 @@ class (Show a, Read a) => ClickhouseValue a where
instance ClickhouseValue HighPrecMoney where
fromClickhouseValue = parseAsStringOrNumber @HighPrecMoney

instance ClickhouseValue Currency where
fromClickhouseValue = parseAsEnum @Currency

instance ClickhouseValue HighPrecMeters where
fromClickhouseValue = parseAsStringOrNumber @HighPrecMeters

Expand All @@ -71,6 +74,11 @@ parseAsStringOrNumber (String str) = parseAsString @a str
parseAsStringOrNumber (Number num) = parseAsNumber @a num
parseAsStringOrNumber Null = fail "Unexpected Null"

parseAsEnum :: forall a. Read a => Value a -> Except a
parseAsEnum (String str) = parseAsString @a str
parseAsEnum (Number _) = fail "Unexpected Number"
parseAsEnum Null = fail "Unexpected Null"

parseAsString :: forall a. Read a => String -> Except a
parseAsString = Except . T.readEither @a

Expand Down

0 comments on commit 132ee93

Please sign in to comment.