packages feed

hasbolt-extras 0.0.1.5 → 0.0.1.6

raw patch · 4 files changed

+50/−20 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -6,6 +6,10 @@  ## [Unreleased] +## [0.0.1.6] - 2020-12-26+### Fixed+- Fix `makeNodeLike` for `Maybe` fields, bug introduced in previous version.+ ## [0.0.1.5] - 2020-12-22 ### Fixed - Compatibility of `makeNodeLike` / `makeURelationLike` with `DuplicateRecordFields`, thanks to
hasbolt-extras.cabal view
@@ -1,5 +1,5 @@ name:           hasbolt-extras-version:        0.0.1.5+version:        0.0.1.6 synopsis:       Extras for hasbolt library description:    Extras for hasbolt library homepage:       https://github.com/biocad/hasbolt-extras#readme
src/Database/Bolt/Extras/Template/Internal/Converters.hs view
@@ -65,26 +65,40 @@ -- | Make an instance of 'NodeLike' class. -- Only data types with one constructor are currently supported. -- Each field is transformed into 'Text' key and its value is transformed into a 'Value'.--- For example, we have a structure+-- For example, we have a structure and define an instance: ----- > data Foo = Bar { baz  :: Double--- >                , quux :: Text--- >                , quuz :: Int--- >                }+-- >>> :{+-- data Foo = Bar+--   { baz  :: Double+--   , quux :: Text+--   , quuz :: Maybe Int+--   } deriving (Show)+-- makeNodeLike ''Foo+-- :} ----- You can make it instance of 'NodeLike' by writing+-- Then you may create example and convert it to and from Node: ----- > makeNodeLike ''Foo+-- >>> let foo = Bar 42.0 "Loren ipsum" (Just 7)+-- >>> toNode foo+-- Node {nodeIdentity = -1, labels = ["Foo"], nodeProps = fromList [("baz",F 42.0),("quux",T "Loren ipsum"),("quuz",I 7)]}+-- >>> fromNode . toNode $ foo :: Foo+-- Bar {baz = 42.0, quux = "Loren ipsum", quuz = Just 7} ----- Then you may create example and convert it into from from Node:+-- 'Maybe' fields are handled correctly: ----- > ghci> :set -XOverloadedStrings--- > ghci> let foo = Bar 42.0 "Loren ipsum" 7--- > ghci> toNode foo--- > Node {nodeIdentity = -1, labels = ["Foo"], nodeProps = fromList [("baz",F 42.0),("quux",T "Loren ipsum"),("quuz",I 7)]}--- > ghci> fromNode . toNode $ foo :: Foo--- > Bar {baz = 42.0, quux = "Loren ipsum", quuz = 7}+-- >>> let bar = Bar 42.0 "Hello world" Nothing+-- >>> toNode bar+-- Node {nodeIdentity = -1, labels = ["Foo"], nodeProps = fromList [("baz",F 42.0),("quux",T "Hello world"),("quuz",N ())]}+-- >>> :{+-- let barNode = Node+--       { nodeIdentity = -1+--       , labels = ["Foo"]+--       , nodeProps = fromList [("baz", F 42.0), ("quux", T "Hello world")] -- No "quuz" here+--       }+-- :} --+-- >>> fromNode barNode :: Foo+-- Bar {baz = 42.0, quux = "Hello world", quuz = Nothing} makeNodeLike :: Name -> Q [Dec] makeNodeLike name = makeBiClassInstance nodeLikeClass name id @@ -287,11 +301,11 @@   pure $ Clause [VarP varName] (GuardedB [successCase, failCase]) []  --- | Check whether given type is '_ -> Maybe _'--- It pattern matches arrow type applied to any argument ant 'T _' and checks if T is ''Maybe+-- | Check whether given type is 'Maybe _'+-- It pattern matches type T applied to any argument and checks if T is ''Maybe isMaybe :: Type -> Bool-isMaybe (AppT (AppT ArrowT _) (AppT (ConT t) _)) = t == ''Maybe-isMaybe _                                        = False+isMaybe (AppT (ConT t) _) = t == ''Maybe+isMaybe _                 = False  strToTextE :: String -> Exp strToTextE str = AppE (VarE 'pack) (LitE . StringL $ str)@@ -308,3 +322,9 @@  unpackError :: Show c => c -> String -> a unpackError container label = error $ $currentLoc ++ " could not unpack " ++ label ++ " from " ++ show container++{- $setup+>>> :set -XTemplateHaskell+>>> :set -XOverloadedStrings+>>> import Data.Text (Text)+-}
test/Doctest.hs view
@@ -5,10 +5,16 @@ -- Taken from https://github.com/kowainik/membrain/blob/master/test/Doctest.hs  main :: IO ()-main =+main = do   doctest     [ "-isrc"     , "src/Database/Bolt/Extras/DSL/Typed.hs"     , "src/Database/Bolt/Extras/DSL/Typed/Types.hs"     , "src/Database/Bolt/Extras/DSL/Typed/Parameters.hs"+    ]+  --  This has to be run separately due to some complications with TH and/or internal modules+  --  See here: https://github.com/sol/doctest/issues/160+  doctest+    [ "-isrc"+    , "src/Database/Bolt/Extras/Template/Internal/Converters.hs"     ]