module Grakn.Query
( IsQuery(queryString)
, MatchQuery
, match
, select
, limit
, distinct
) where
import Grakn.Pattern
import Grakn.Property
import Grakn.Util
class IsQuery q where
queryString :: q -> String
data MatchQuery
= Match [Pattern]
| Select MatchQuery
[Var]
| Limit MatchQuery
Integer
| Distinct MatchQuery
match :: Convert a Pattern => [a] -> MatchQuery
match = Match . map convert
select :: [Var] -> MatchQuery -> MatchQuery
select = flip Select
limit :: Integer -> MatchQuery -> MatchQuery
limit = flip Limit
distinct :: MatchQuery -> MatchQuery
distinct = Distinct
instance Show MatchQuery where
show (Match patts) = "match " ++ spaces patts
show (Select mq vars) = show mq ++ " select " ++ commas vars ++ ";"
show (Limit mq lim) = show mq ++ " limit " ++ show lim ++ ";"
show (Distinct mq) = show mq ++ " distinct;"
instance IsQuery MatchQuery where
queryString = show
instance IsQuery String where
queryString = id