Skip to content

Instantly share code, notes, and snippets.

@lierdakil
Created December 4, 2018 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lierdakil/16c2520a08ba6167629eebe483faf786 to your computer and use it in GitHub Desktop.
Save lierdakil/16c2520a08ba6167629eebe483faf786 to your computer and use it in GitHub Desktop.
Example of TutorialD quasiquoter syntax
{-# LANGUAGE DeriveGeneric, DeriveAnyClass, OverloadedStrings, QuasiQuotes, TemplateHaskell #-}
module Main where
import ProjectM36.Client
import ProjectM36.Relation.Show.Term
import GHC.Generics
import Data.Text
import Data.Binary
import Control.DeepSeq
import qualified Data.Map as M
import qualified Data.Text.IO as TIO
import Data.Proxy
import TutorialD.QQ
data Hair = Bald | Brown | Blond | OtherColor Text
deriving (Generic, Show, Eq, Binary, NFData, Atomable)
main :: IO ()
main = do
--connect to the database
let connInfo = InProcessConnectionInfo NoPersistence emptyNotificationCallback []
eCheck v = do
x <- v
case x of
Left err -> error (show err)
Right x' -> pure x'
conn <- eCheck $ connectProjectM36 connInfo
--create a database session at the default branch of the fresh database
sessionId <- eCheck $ createSessionAtHead conn "master"
--create the data type in the database context
eCheck $ executeDatabaseContextExpr sessionId conn (toAddTypeExpr (Proxy :: Proxy Hair))
--create a relation with the new Hair AtomType
let blond = Blond
grey = OtherColor "Grey"
eCheck $ executeDatabaseContextExpr sessionId conn
[tutdctx|people := relation{
tuple{hair $blond, name "Colin"},
tuple{hair $grey, name "Greg"}
}|]
peopleRel <- eCheck $ executeRelationalExpr sessionId conn
[tutdrel|people where hair = $grey|]
TIO.putStrLn (showRelation peopleRel)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment