feat: use c++ library for json parsing from database
This commit is contained in:
parent
212e316c7e
commit
f22675189e
@ -159,6 +159,7 @@ dependencies:
|
||||
- insert-ordered-containers
|
||||
- topograph
|
||||
- network-uri
|
||||
- sajson
|
||||
|
||||
other-extensions:
|
||||
- GeneralizedNewtypeDeriving
|
||||
@ -252,6 +253,8 @@ when:
|
||||
else:
|
||||
ghc-options:
|
||||
- -O -fllvm
|
||||
- condition: flag(sajson)
|
||||
cpp-options: -DSAJSON
|
||||
|
||||
# The library contains all of our application code. The executable
|
||||
# defined below is just a thin wrapper.
|
||||
@ -363,3 +366,6 @@ flags:
|
||||
description: Be very pedantic about warnings and errors
|
||||
manual: false
|
||||
default: true
|
||||
sajson:
|
||||
manual: false
|
||||
default: true
|
||||
|
||||
@ -4,6 +4,7 @@ import ClassyPrelude.Yesod hiding (derivePersistFieldJSON, toPersistValueJSON, f
|
||||
import Data.List (foldl)
|
||||
import Database.Persist.Sql hiding (toPersistValueJSON, fromPersistValueJSON)
|
||||
|
||||
import qualified Data.ByteString as BS
|
||||
import qualified Data.ByteString.Lazy as LBS
|
||||
import qualified Data.Text.Encoding as Text
|
||||
|
||||
@ -14,6 +15,10 @@ import Language.Haskell.TH.Datatype
|
||||
|
||||
import Utils.PathPiece
|
||||
|
||||
#ifdef SAJSON
|
||||
import qualified Data.Sajson as Sajson
|
||||
#endif
|
||||
|
||||
|
||||
toPersistValueJSON :: ToJSON a => a -> PersistValue
|
||||
toPersistValueJSON = PersistDbSpecific . LBS.toStrict . JSON.encode
|
||||
@ -24,7 +29,15 @@ fromPersistValueJSON = \case
|
||||
PersistByteString bs -> decodeBS bs
|
||||
PersistText text -> decodeBS $ Text.encodeUtf8 text
|
||||
_other -> Left "JSON values must be converted from PersistDbSpecific, PersistText, or PersistByteString"
|
||||
#ifdef SAJSON
|
||||
where
|
||||
decodeBS bs
|
||||
| compatibleToplevel bs = first pack $ Sajson.eitherDecodeStrict bs
|
||||
| otherwise = first pack $ JSON.eitherDecodeStrict' bs
|
||||
compatibleToplevel bs = any (`BS.isPrefixOf` bs) ["[", "{"]
|
||||
#else
|
||||
where decodeBS = first pack . JSON.eitherDecodeStrict'
|
||||
#endif
|
||||
|
||||
sqlTypeJSON :: SqlType
|
||||
sqlTypeJSON = SqlOther "jsonb"
|
||||
|
||||
@ -56,6 +56,9 @@ extra-deps:
|
||||
- git: git@gitlab2.rz.ifi.lmu.de:uni2work/zip-stream.git
|
||||
commit: 843683d024f767de236f74d24a3348f69181a720
|
||||
|
||||
- git: https://github.com/kccqzy/haskell-sajson.git
|
||||
commit: ffc9670f24e308e32979f4e0343e6637a9f72cf4
|
||||
|
||||
- acid-state-0.16.0.1@sha256:d43f6ee0b23338758156c500290c4405d769abefeb98e9bc112780dae09ece6f,6207
|
||||
- commonmark-0.1.0.2@sha256:fbff7a2ade0ce7d699964a87f765e503a3a9e22542c05f0f02ba7aad64e38af4,3278
|
||||
- commonmark-extensions-0.2.0.1@sha256:647aa8dba5fd46984ddedc15c3693c9c4d9655503d42006576bd8f0dadf8cd39,3176
|
||||
|
||||
@ -233,6 +233,17 @@ packages:
|
||||
original:
|
||||
git: git@gitlab2.rz.ifi.lmu.de:uni2work/zip-stream.git
|
||||
commit: 843683d024f767de236f74d24a3348f69181a720
|
||||
- completed:
|
||||
name: sajson
|
||||
version: 0.1.0.0
|
||||
git: https://github.com/kccqzy/haskell-sajson.git
|
||||
pantry-tree:
|
||||
size: 651
|
||||
sha256: faff738ae449bf7046bc9775cf4ce4db115d7c52cbf40040e11e6a232f9d1187
|
||||
commit: ffc9670f24e308e32979f4e0343e6637a9f72cf4
|
||||
original:
|
||||
git: https://github.com/kccqzy/haskell-sajson.git
|
||||
commit: ffc9670f24e308e32979f4e0343e6637a9f72cf4
|
||||
- completed:
|
||||
hackage: acid-state-0.16.0.1@sha256:d43f6ee0b23338758156c500290c4405d769abefeb98e9bc112780dae09ece6f,6207
|
||||
pantry-tree:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user