module Database.Bolt.Extras.DSL.Internal.Language
  (
    CypherDSL
  , createF
  , matchF
  , optionalMatchF
  , mergeF
  , whereF
  , setF
  , deleteF
  , detachDeleteF
  , removeF
  , returnF
  , withF
  , textF
  ) where

import           Control.Monad.Free                      (Free (..), liftF)
import           Data.Text                               (Text)
import           Database.Bolt.Extras.DSL.Internal.Types (Conds (..), Expr (..),
                                                          Selectors)

-- | A synonym for 'Free' DSL.
--
type CypherDSL a = Free Expr a

-- | Prepare 'CREATE' query
--
createF :: Selectors -> Free Expr ()
createF :: Selectors -> Free Expr ()
createF Selectors
sels = forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (forall next. Selectors -> next -> Expr next
Create Selectors
sels ())

-- | Prepare 'MATCH' query
--
matchF :: Selectors -> Free Expr ()
matchF :: Selectors -> Free Expr ()
matchF Selectors
sels = forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (forall next. Selectors -> next -> Expr next
Match Selectors
sels ())

-- | Prepare 'OPTIONAL MATCH' query
--
optionalMatchF :: Selectors -> Free Expr ()
optionalMatchF :: Selectors -> Free Expr ()
optionalMatchF Selectors
sels = forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (forall next. Selectors -> next -> Expr next
OptionalMatch Selectors
sels ())

-- | Prepare 'MERGE' query
--
mergeF :: Selectors -> Free Expr ()
mergeF :: Selectors -> Free Expr ()
mergeF Selectors
sels = forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (forall next. Selectors -> next -> Expr next
Merge Selectors
sels ())

-- | Prepare 'WHERE' query
--
whereF :: Conds -> Free Expr ()
whereF :: Conds -> Free Expr ()
whereF Conds
conds = forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (forall next. Conds -> next -> Expr next
Where Conds
conds ())

-- | Prepare 'SET' query
--
setF :: [Text] -> Free Expr ()
setF :: [Text] -> Free Expr ()
setF [Text]
txts = forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (forall next. [Text] -> next -> Expr next
Set [Text]
txts ())

-- | Prepare 'DELETE' query
--
deleteF :: [Text] -> Free Expr ()
deleteF :: [Text] -> Free Expr ()
deleteF [Text]
txts = forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (forall next. [Text] -> next -> Expr next
Delete [Text]
txts ())

-- | Prepare 'DETACH DELETE' query
--
detachDeleteF :: [Text] -> Free Expr ()
detachDeleteF :: [Text] -> Free Expr ()
detachDeleteF [Text]
txts = forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (forall next. [Text] -> next -> Expr next
DetachDelete [Text]
txts ())

-- | Prepare 'REMOVE' query
--
removeF :: [Text] -> Free Expr ()
removeF :: [Text] -> Free Expr ()
removeF [Text]
txts = forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (forall next. [Text] -> next -> Expr next
Remove [Text]
txts ())

-- | Prepare 'RETURN' query
--
returnF :: [Text] -> Free Expr ()
returnF :: [Text] -> Free Expr ()
returnF [Text]
txts = forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (forall next. [Text] -> next -> Expr next
Return [Text]
txts ())

-- | Prepare 'WITH' query
--
withF :: [Text] -> Free Expr ()
withF :: [Text] -> Free Expr ()
withF [Text]
txts = forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (forall next. [Text] -> next -> Expr next
With [Text]
txts ())

-- | Prepare query with custom text
--
textF :: Text -> Free Expr ()
textF :: Text -> Free Expr ()
textF Text
txt = forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
liftF (forall next. Text -> next -> Expr next
Text Text
txt ())