Skip to content

Commit 279193e

Browse files
authored
Merge pull request #43 from biocad/maksbotan/version-0.0.1.6
version 0.0.1.6: fix makeNodeLike for Maybe fields
2 parents d970e62 + 48013e4 commit 279193e

File tree

4 files changed

+46
-16
lines changed

4 files changed

+46
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
## [0.0.1.6] - 2020-12-26
10+
### Fixed
11+
- Fix `makeNodeLike` for `Maybe` fields, bug introduced in previous version.
12+
913
## [0.0.1.5] - 2020-12-22
1014
### Fixed
1115
- Compatibility of `makeNodeLike` / `makeURelationLike` with `DuplicateRecordFields`, thanks to

hasbolt-extras.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: hasbolt-extras
2-
version: 0.0.1.5
2+
version: 0.0.1.6
33
synopsis: Extras for hasbolt library
44
description: Extras for hasbolt library
55
homepage: https://github.com/biocad/hasbolt-extras#readme

src/Database/Bolt/Extras/Template/Internal/Converters.hs

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,40 @@ uRelationLikeClass = BiClassInfo { className = ''URelationLike
6565
-- | Make an instance of 'NodeLike' class.
6666
-- Only data types with one constructor are currently supported.
6767
-- Each field is transformed into 'Text' key and its value is transformed into a 'Value'.
68-
-- For example, we have a structure
68+
-- For example, we have a structure and define an instance:
6969
--
70-
-- > data Foo = Bar { baz :: Double
71-
-- > , quux :: Text
72-
-- > , quuz :: Int
73-
-- > }
70+
-- >>> :{
71+
-- data Foo = Bar
72+
-- { baz :: Double
73+
-- , quux :: Text
74+
-- , quuz :: Maybe Int
75+
-- } deriving (Show)
76+
-- makeNodeLike ''Foo
77+
-- :}
7478
--
75-
-- You can make it instance of 'NodeLike' by writing
79+
-- Then you may create example and convert it to and from Node:
7680
--
77-
-- > makeNodeLike ''Foo
81+
-- >>> let foo = Bar 42.0 "Loren ipsum" (Just 7)
82+
-- >>> toNode foo
83+
-- Node {nodeIdentity = -1, labels = ["Foo"], nodeProps = fromList [("baz",F 42.0),("quux",T "Loren ipsum"),("quuz",I 7)]}
84+
-- >>> fromNode . toNode $ foo :: Foo
85+
-- Bar {baz = 42.0, quux = "Loren ipsum", quuz = Just 7}
7886
--
79-
-- Then you may create example and convert it into from from Node:
87+
-- 'Maybe' fields are handled correctly:
8088
--
81-
-- > ghci> :set -XOverloadedStrings
82-
-- > ghci> let foo = Bar 42.0 "Loren ipsum" 7
83-
-- > ghci> toNode foo
84-
-- > Node {nodeIdentity = -1, labels = ["Foo"], nodeProps = fromList [("baz",F 42.0),("quux",T "Loren ipsum"),("quuz",I 7)]}
85-
-- > ghci> fromNode . toNode $ foo :: Foo
86-
-- > Bar {baz = 42.0, quux = "Loren ipsum", quuz = 7}
89+
-- >>> let bar = Bar 42.0 "Hello world" Nothing
90+
-- >>> toNode bar
91+
-- Node {nodeIdentity = -1, labels = ["Foo"], nodeProps = fromList [("baz",F 42.0),("quux",T "Hello world"),("quuz",N ())]}
92+
-- >>> :{
93+
-- let barNode = Node
94+
-- { nodeIdentity = -1
95+
-- , labels = ["Foo"]
96+
-- , nodeProps = fromList [("baz", F 42.0), ("quux", T "Hello world")] -- No "quuz" here
97+
-- }
98+
-- :}
8799
--
100+
-- >>> fromNode barNode :: Foo
101+
-- Bar {baz = 42.0, quux = "Hello world", quuz = Nothing}
88102
makeNodeLike :: Name -> Q [Dec]
89103
makeNodeLike name = makeBiClassInstance nodeLikeClass name id
90104

@@ -308,3 +322,9 @@ getProp container (fieldName, fieldMaybe) | fieldMaybe && fieldName `notMember`
308322

309323
unpackError :: Show c => c -> String -> a
310324
unpackError container label = error $ $currentLoc ++ " could not unpack " ++ label ++ " from " ++ show container
325+
326+
{- $setup
327+
>>> :set -XTemplateHaskell
328+
>>> :set -XOverloadedStrings
329+
>>> import Data.Text (Text)
330+
-}

test/Doctest.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ import Test.DocTest (doctest)
55
-- Taken from https://github.com/kowainik/membrain/blob/master/test/Doctest.hs
66

77
main :: IO ()
8-
main =
8+
main = do
99
doctest
1010
[ "-isrc"
1111
, "src/Database/Bolt/Extras/DSL/Typed.hs"
1212
, "src/Database/Bolt/Extras/DSL/Typed/Types.hs"
1313
, "src/Database/Bolt/Extras/DSL/Typed/Parameters.hs"
1414
]
15+
-- This has to be run separately due to some complications with TH and/or internal modules
16+
-- See here: https://github.com/sol/doctest/issues/160
17+
doctest
18+
[ "-isrc"
19+
, "src/Database/Bolt/Extras/Template/Internal/Converters.hs"
20+
]

0 commit comments

Comments
 (0)