Skip to content

Commit

Permalink
chore: show on ReadPlan and MediaType
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-chavez committed Jul 5, 2023
1 parent 7508230 commit 20b06ef
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 51 deletions.
17 changes: 0 additions & 17 deletions src/PostgREST/ApiRequest/QueryParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,6 @@ import Protolude hiding (try)
-- Setup for doctests
-- >>> import Text.Pretty.Simple (pPrint)
-- >>> deriving instance Show QPError
-- >>> deriving instance Show TrileanVal
-- >>> deriving instance Show FtsOperator
-- >>> deriving instance Show QuantOperator
-- >>> deriving instance Show SimpleOperator
-- >>> deriving instance Show OpQuantifier
-- >>> deriving instance Show Operation
-- >>> deriving instance Show OpExpr
-- >>> deriving instance Show JsonOperand
-- >>> deriving instance Show JsonOperation
-- >>> deriving instance Show Filter
-- >>> deriving instance Show JoinType
-- >>> deriving instance Show SelectItem
-- >>> deriving instance Show OrderDirection
-- >>> deriving instance Show OrderNulls
-- >>> deriving instance Show OrderTerm
-- >>> deriving instance Show LogicOperator
-- >>> deriving instance Show LogicTree

data QueryParams =
QueryParams
Expand Down
34 changes: 17 additions & 17 deletions src/PostgREST/ApiRequest/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ data SelectItem
, selHint :: Maybe Hint
, selJoinType :: Maybe JoinType
}
deriving (Eq)
deriving (Eq, Show)

data ApiRequestError
= AmbiguousRelBetween Text Text [Relationship]
Expand Down Expand Up @@ -108,17 +108,17 @@ data OrderTerm
, otDirection :: Maybe OrderDirection
, otNullOrder :: Maybe OrderNulls
}
deriving Eq
deriving (Eq, Show)

data OrderDirection
= OrderAsc
| OrderDesc
deriving (Eq)
deriving (Eq, Show)

data OrderNulls
= OrderNullsFirst
| OrderNullsLast
deriving (Eq)
deriving (Eq, Show)

type Field = (FieldName, JsonPath)
type Cast = Text
Expand All @@ -135,7 +135,7 @@ data EmbedParam
data JoinType
= JTInner
| JTLeft
deriving Eq
deriving (Eq, Show)

-- | Path of the embedded levels, e.g "clients.projects.name=eq.." gives Path
-- ["clients", "projects"]
Expand All @@ -149,15 +149,15 @@ type JsonPath = [JsonOperation]
data JsonOperation
= JArrow { jOp :: JsonOperand }
| J2Arrow { jOp :: JsonOperand }
deriving (Eq, Ord)
deriving (Eq, Show, Ord)

-- | Represents the key(`->'key'`) or index(`->'1`::int`), the index is Text
-- because we reuse our escaping functons and let pg do the casting with
-- '1'::int
data JsonOperand
= JKey { jVal :: Text }
| JIdx { jVal :: Text }
deriving (Eq, Ord)
deriving (Eq, Show, Ord)

-- | Boolean logic expression tree e.g. "and(name.eq.N,or(id.eq.1,id.eq.2))" is:
--
Expand All @@ -169,28 +169,28 @@ data JsonOperand
data LogicTree
= Expr Bool LogicOperator [LogicTree]
| Stmnt Filter
deriving (Eq)
deriving (Eq, Show)

data LogicOperator
= And
| Or
deriving Eq
deriving (Eq, Show)

data Filter
= Filter
{ field :: Field
, opExpr :: OpExpr
}
| FilterNullEmbed Bool FieldName
deriving (Eq)
deriving (Eq, Show)

data OpExpr
= OpExpr Bool Operation
| NoOpExpr Text
deriving (Eq)
deriving (Eq, Show)

data OpQuantifier = QuantAny | QuantAll
deriving Eq
deriving (Eq, Show)

data Operation
= Op SimpleOperator SingleVal
Expand All @@ -199,7 +199,7 @@ data Operation
| Is TrileanVal
| IsDistinctFrom SingleVal
| Fts FtsOperator (Maybe Language) SingleVal
deriving (Eq)
deriving (Eq, Show)

type Language = Text

Expand All @@ -215,7 +215,7 @@ data TrileanVal
| TriFalse
| TriNull
| TriUnknown
deriving Eq
deriving (Eq, Show)

-- Operators that are quantifiable, i.e. they can be used with the any/all modifiers
data QuantOperator
Expand All @@ -228,7 +228,7 @@ data QuantOperator
| OpILike
| OpMatch
| OpIMatch
deriving Eq
deriving (Eq, Show)

data SimpleOperator
= OpNotEqual
Expand All @@ -240,7 +240,7 @@ data SimpleOperator
| OpNotExtendsRight
| OpNotExtendsLeft
| OpAdjacent
deriving Eq
deriving (Eq, Show)

--
-- | Operators for full text search operators
Expand All @@ -249,4 +249,4 @@ data FtsOperator
| FilterFtsPlain
| FilterFtsPhrase
| FilterFtsWebsearch
deriving Eq
deriving (Eq, Show)
11 changes: 3 additions & 8 deletions src/PostgREST/MediaType.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ import Network.HTTP.Types.Header (Header, hContentType)

import Protolude

--
-- $setup
-- Setup for doctests
-- >>> import Text.Pretty.Simple (pPrint)
-- >>> deriving instance Show MTPlanFormat
-- >>> deriving instance Show MTPlanOption
-- >>> deriving instance Show MediaType

-- | Enumeration of currently supported media types
data MediaType
= MTApplicationJSON
Expand All @@ -39,6 +31,7 @@ data MediaType
| MTAny
| MTOther ByteString
| MTPlan MediaType MTPlanFormat [MTPlanOption]
deriving Show
instance Eq MediaType where
MTApplicationJSON == MTApplicationJSON = True
MTSingularJSON == MTSingularJSON = True
Expand All @@ -56,9 +49,11 @@ instance Eq MediaType where

data MTPlanOption
= PlanAnalyze | PlanVerbose | PlanSettings | PlanBuffers | PlanWAL
deriving (Eq, Show)

data MTPlanFormat
= PlanJSON | PlanText
deriving (Eq, Show)

-- | Convert MediaType to a Content-Type HTTP Header
toContentType :: MediaType -> Header
Expand Down
4 changes: 2 additions & 2 deletions src/PostgREST/Plan/ReadPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ data JoinCondition =
JoinCondition
(QualifiedIdentifier, FieldName)
(QualifiedIdentifier, FieldName)
deriving (Eq)
deriving (Eq, Show)

data ReadPlan = ReadPlan
{ select :: [(CoercibleField, Maybe Cast, Maybe Alias)]
Expand All @@ -45,4 +45,4 @@ data ReadPlan = ReadPlan
, depth :: Depth
-- ^ used for aliasing
}
deriving (Eq)
deriving (Eq, Show)
6 changes: 3 additions & 3 deletions src/PostgREST/Plan/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ data CoercibleField = CoercibleField
, cfIRType :: Text -- ^ The native Postgres type of the field, the intermediate (IR) type before mapping.
, cfTransform :: Maybe TransformerProc -- ^ The optional mapping from irType -> targetType.
, cfDefault :: Maybe Text
} deriving Eq
} deriving (Eq, Show)

unknownField :: FieldName -> JsonPath -> CoercibleField
unknownField name path = CoercibleField name path "" Nothing Nothing
Expand All @@ -40,11 +40,11 @@ unknownField name path = CoercibleField name path "" Nothing Nothing
data CoercibleLogicTree
= CoercibleExpr Bool LogicOperator [CoercibleLogicTree]
| CoercibleStmnt CoercibleFilter
deriving (Eq)
deriving (Eq, Show)

data CoercibleFilter = CoercibleFilter
{ field :: CoercibleField
, opExpr :: OpExpr
}
| CoercibleFilterNullEmbed Bool FieldName
deriving (Eq)
deriving (Eq, Show)
2 changes: 1 addition & 1 deletion src/PostgREST/SchemaCache/Identifiers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data QualifiedIdentifier = QualifiedIdentifier
{ qiSchema :: Schema
, qiName :: TableName
}
deriving (Eq, Ord, Generic, JSON.ToJSON, JSON.ToJSONKey)
deriving (Eq, Show, Ord, Generic, JSON.ToJSON, JSON.ToJSONKey)

instance Hashable QualifiedIdentifier

Expand Down
6 changes: 3 additions & 3 deletions src/PostgREST/SchemaCache/Relationship.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ data Relationship = Relationship
, relToOne :: Bool
, relIsSelf :: Bool
}
deriving (Eq, Ord, Generic, JSON.ToJSON)
deriving (Eq, Show, Ord, Generic, JSON.ToJSON)

-- | The relationship cardinality
-- | https://en.wikipedia.org/wiki/Cardinality_(data_modeling)
Expand All @@ -47,7 +47,7 @@ data Cardinality
-- ^ one-to-one, this is a refinement over M2O so operating on it is pretty much the same as M2O
| M2M Junction
-- ^ many-to-many
deriving (Eq, Ord, Generic, JSON.ToJSON)
deriving (Eq, Show, Ord, Generic, JSON.ToJSON)

type FKConstraint = Text

Expand All @@ -59,7 +59,7 @@ data Junction = Junction
, junColsSource :: [(FieldName, FieldName)]
, junColsTarget :: [(FieldName, FieldName)]
}
deriving (Eq, Ord, Generic, JSON.ToJSON)
deriving (Eq, Show, Ord, Generic, JSON.ToJSON)

-- | Key based on the source table and the foreign table schema
type RelationshipsMap = HM.HashMap (QualifiedIdentifier, Schema) [Relationship]
Expand Down

0 comments on commit 20b06ef

Please sign in to comment.