hasbolt-extras 0.0.2.2 → 0.0.3.0
raw patch · 4 files changed
+25/−4 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Database.Bolt.Extras.Graph: relations :: forall n_agbj a_agbk b_agbl b_agEd. Lens (Graph n_agbj a_agbk b_agbl) (Graph n_agbj a_agbk b_agEd) (Map (n_agbj, n_agbj) b_agbl) (Map (n_agbj, n_agbj) b_agEd)
+ Database.Bolt.Extras.Graph: relations :: forall n_agbw a_agbx b_agby b_agEq. Lens (Graph n_agbw a_agbx b_agby) (Graph n_agbw a_agbx b_agEq) (Map (n_agbw, n_agbw) b_agby) (Map (n_agbw, n_agbw) b_agEq)
- Database.Bolt.Extras.Graph: vertices :: forall n_agbj a_agbk b_agbl a_agEe. Lens (Graph n_agbj a_agbk b_agbl) (Graph n_agbj a_agEe b_agbl) (Map n_agbj a_agbk) (Map n_agbj a_agEe)
+ Database.Bolt.Extras.Graph: vertices :: forall n_agbw a_agbx b_agby a_agEr. Lens (Graph n_agbw a_agbx b_agby) (Graph n_agbw a_agEr b_agby) (Map n_agbw a_agbx) (Map n_agbw a_agEr)
Files
- CHANGELOG.md +6/−0
- hasbolt-extras.cabal +1/−1
- src/Database/Bolt/Extras/DSL/Internal/Instances.hs +12/−3
- src/Database/Bolt/Extras/DSL/Internal/Types.hs +6/−0
CHANGELOG.md view
@@ -6,6 +6,12 @@ ## [Unreleased] +## [0.0.3.0] - 2023-08-17+### Added+- `IsString` instance for `Cond` and `Conds`.+### Fixed+- `:&&:` and `:||:` render to Cypher with correct operator precedence.+ ## [0.0.2.2] - 2023-05-05 ### Changed - Add `HasCallStack` to a lot of unpacking functions.
hasbolt-extras.cabal view
@@ -1,5 +1,5 @@ name: hasbolt-extras-version: 0.0.2.2+version: 0.0.3.0 synopsis: Extras for hasbolt library description: Extras for hasbolt library homepage: https://github.com/biocad/hasbolt-extras#readme
src/Database/Bolt/Extras/DSL/Internal/Instances.hs view
@@ -11,6 +11,7 @@ import Control.Monad.Writer (execWriter, tell) import Data.Function ((&))+import Data.String (IsString(..)) import Data.Proxy (Proxy (..)) import Data.Text (intercalate, pack) import Database.Bolt.Extras (ToCypher (..),@@ -127,14 +128,22 @@ instance ToCypher Selectors where toCypher = intercalate ", " . fmap toCypher +instance IsString Cond where+ fromString str = TC $ pack str+ instance ToCypher Cond where toCypher (ID t bId) = pack $ printf "ID(%s)=%d" t (fromInt bId) toCypher (IDs t bIds) = pack $ printf "ID(%s) in [%s]" t (intercalate ", " $ fmap (pack . show) bIds) toCypher (IN t txts) = pack $ printf "%s in [%s]" t (intercalate ", " $ fmap (\s -> [text|"$s"|]) txts) toCypher (TC txt) = txt +instance IsString Conds where+ fromString str = C $ TC $ pack str+ instance ToCypher Conds where- toCypher (fcp :&&: scp) = toCypher fcp <> " AND " <> toCypher scp- toCypher (fcp :||: scp) = toCypher fcp <> " OR " <> toCypher scp- toCypher (Not cp) = "NOT " <> toCypher cp+ -- Adding "(" ")" to have correct precedence in Cypher+ -- "(a :&&: b) :||: c" should mean "(a AND b) OR c", not "a AND b OR c"+ toCypher (fcp :&&: scp) = "(" <> toCypher fcp <> ") AND (" <> toCypher scp <> ")"+ toCypher (fcp :||: scp) = "(" <> toCypher fcp <> ") OR (" <> toCypher scp <> ")"+ toCypher (Not cp) = "NOT (" <> toCypher cp <> ")" toCypher (C cp) = toCypher cp
src/Database/Bolt/Extras/DSL/Internal/Types.hs view
@@ -133,6 +133,12 @@ infixr 3 :&&: infixr 2 :||:+-- | Conditional expressions in Cypher.+--+-- Can be used with @OverloadedStrings@ to include atomic text conditions.+--+-- > toCypher $ ("x = 5" :&&: "y = 10") :||: Not "z = 20"+-- > "((x = 5) AND (y = 10)) OR (NOT (z = 20))" data Conds = Conds :&&: Conds -- ^ 'condition' AND 'condition' | Conds :||: Conds -- ^ 'condition' OR 'condition' | C Cond -- ^ single 'condition'