postgrest-0.4.2.0: REST API for any Postgres database

Safe Haskell | None
Language | Haskell2010

PostgREST.Types

Synopsis

- data ContentType
  - = CTApplicationJSON
  - | CTTextCSV
  - | CTOpenAPI
  - | CTSingularJSON
  - | CTOctetStream
  - | CTAny
  - | CTOther ByteString
- data ApiRequestError
  - = ActionInappropriate
  - | InvalidBody ByteString
  - | InvalidRange
  - | ParseRequestError Text Text
  - | UnknownRelation
  - | NoRelationBetween Text Text
  - | UnsupportedVerb
- data DbStructure = DbStructure {
  - dbTables :: [Table]
  - dbColumns :: [Column]
  - dbRelations :: [Relation]
  - dbPrimaryKeys :: [PrimaryKey]
  - dbProcs :: HashMap Text ProcDescription
  }
- data PgArg = PgArg {
  - pgaName :: Text
  - pgaType :: Text
  - pgaReq :: Bool
  }
- data PgType
  - = Scalar QualifiedIdentifier
  - | Composite QualifiedIdentifier
  - | Pseudo Text
- data RetType
  - = Single PgType
  - | SetOf PgType
- data ProcVolatility
  - = Volatile
  - | Stable
  - | Immutable
- data ProcDescription = ProcDescription {
  - pdName :: Text
  - pdArgs :: [PgArg]
  - pdReturnType :: RetType
  - pdVolatility :: ProcVolatility
  }
- type Schema = Text
- type TableName = Text
- type SqlQuery = Text
- type SqlFragment = Text
- type RequestBody = ByteString
- data Table = Table {
  - tableSchema :: Schema
  - tableName :: TableName
  - tableInsertable :: Bool
  }
- newtype ForeignKey = ForeignKey {
  - fkCol :: Column
  }
- data Column = Column {
  - colTable :: Table
  - colName :: Text
  - colPosition :: Int32
  - colNullable :: Bool
  - colType :: Text
  - colUpdatable :: Bool
  - colMaxLen :: Maybe Int32
  - colPrecision :: Maybe Int32
  - colDefault :: Maybe Text
  - colEnum :: [Text]
  - colFK :: Maybe ForeignKey
  }
- type Synonym = (Column, Column)
- data PrimaryKey = PrimaryKey {
  - pkTable :: Table
  - pkName :: Text
  }
- data OrderDirection
  - = OrderAsc
  - | OrderDesc
- data OrderNulls
  - = OrderNullsFirst
  - | OrderNullsLast
- data OrderTerm = OrderTerm {
  - otTerm :: Field
  - otDirection :: Maybe OrderDirection
  - otNullOrder :: Maybe OrderNulls
  }
- data QualifiedIdentifier = QualifiedIdentifier {
  - qiSchema :: Schema
  - qiName :: TableName
  }
- data RelationType
  - = Child
  - | Parent
  - | Many
  - | Root
- data Relation = Relation {
  - relTable :: Table
  - relColumns :: [Column]
  - relFTable :: Table
  - relFColumns :: [Column]
  - relType :: RelationType
  - relLTable :: Maybe Table
  - relLCols1 :: Maybe [Column]
  - relLCols2 :: Maybe [Column]
  }
- newtype PayloadJSON = PayloadJSON (Vector Object)
- unPayloadJSON :: PayloadJSON -> Vector Object
- data Proxy = Proxy {
  - proxyScheme :: Text
  - proxyHost :: Text
  - proxyPort :: Integer
  - proxyPath :: Text
  }
- type Operator = Text
- operators :: HashMap Operator SqlFragment
- data Operation = Operation {
  - hasNot :: Bool
  - expr :: (Operator, Operand)
  }
- data Operand
  - = VText Text
  - | VTextL [Text]
  - | VForeignKey QualifiedIdentifier ForeignKey
- data LogicOperator
  - = And
  - | Or
- data LogicTree
  - = Expr Bool LogicOperator LogicTree LogicTree
  - | Stmnt Filter
- type FieldName = Text
- type JsonPath = [Text]
- type Field = (FieldName, Maybe JsonPath)
- type Alias = Text
- type Cast = Text
- type NodeName = Text
- type SelectItem = (Field, Maybe Cast, Maybe Alias)
- type EmbedPath = [Text]
- data Filter = Filter {
  - field :: Field
  - operation :: Operation
  }
- data ReadQuery = Select {
  - select :: [SelectItem]
  - from :: [TableName]
  - flt_ :: [Filter]
  - logic :: [LogicTree]
  - order :: Maybe [OrderTerm]
  - range_ :: NonnegRange
  }
- data MutateQuery
  - = Insert {
    - in_ :: TableName
    - qPayload :: PayloadJSON
    - returning :: [FieldName]
    }
  - | Delete {
    - in_ :: TableName
    - where_ :: [Filter]
    - logic :: [LogicTree]
    - returning :: [FieldName]
    }
  - | Update {
    - in_ :: TableName
    - qPayload :: PayloadJSON
    - where_ :: [Filter]
    - logic :: [LogicTree]
    - returning :: [FieldName]
    }
- type ReadNode = (ReadQuery, (NodeName, Maybe Relation, Maybe Alias))
- type ReadRequest = Tree ReadNode
- type MutateRequest = MutateQuery
- data DbRequest
  - = DbRead ReadRequest
  - | DbMutate MutateRequest
- toHeader :: ContentType -> Header
- toMime :: ContentType -> ByteString

# Documentation

data ContentType #

Enumeration of currently supported response content types

Constructors

CTApplicationJSON |
CTTextCSV |
CTOpenAPI |
CTSingularJSON |
CTOctetStream |
CTAny |
CTOther ByteString |

Instances

Eq ContentType # |
Methods (==) :: ContentType -> ContentType -> Bool # (/=) :: ContentType -> ContentType -> Bool #

data ApiRequestError #

Constructors

ActionInappropriate |
InvalidBody ByteString |
InvalidRange |
ParseRequestError Text Text |
UnknownRelation |
NoRelationBetween Text Text |
UnsupportedVerb |

Instances

Eq ApiRequestError # |
Methods (==) :: ApiRequestError -> ApiRequestError -> Bool # (/=) :: ApiRequestError -> ApiRequestError -> Bool #
Show ApiRequestError # |
Methods showsPrec :: Int -> ApiRequestError -> ShowS # show :: ApiRequestError -> String # showList :: [ApiRequestError] -> ShowS #

data DbStructure #

Constructors

DbStructure |
Fields dbTables :: [Table] dbColumns :: [Column] dbRelations :: [Relation] dbPrimaryKeys :: [PrimaryKey] dbProcs :: HashMap Text ProcDescription

Instances

Eq DbStructure # |
Methods (==) :: DbStructure -> DbStructure -> Bool # (/=) :: DbStructure -> DbStructure -> Bool #
Show DbStructure # |
Methods showsPrec :: Int -> DbStructure -> ShowS # show :: DbStructure -> String # showList :: [DbStructure] -> ShowS #

data PgArg #

Constructors

PgArg |
Fields pgaName :: Text pgaType :: Text pgaReq :: Bool

Instances

Eq PgArg # |
Methods (==) :: PgArg -> PgArg -> Bool # (/=) :: PgArg -> PgArg -> Bool #
Show PgArg # |
Methods showsPrec :: Int -> PgArg -> ShowS # show :: PgArg -> String # showList :: [PgArg] -> ShowS #

data PgType #

Constructors

Scalar QualifiedIdentifier |
Composite QualifiedIdentifier |
Pseudo Text |

Instances

Eq PgType # |
Methods (==) :: PgType -> PgType -> Bool # (/=) :: PgType -> PgType -> Bool #
Show PgType # |
Methods showsPrec :: Int -> PgType -> ShowS # show :: PgType -> String # showList :: [PgType] -> ShowS #

data RetType #

Constructors

Single PgType |
SetOf PgType |

Instances

Eq RetType # |
Methods (==) :: RetType -> RetType -> Bool # (/=) :: RetType -> RetType -> Bool #
Show RetType # |
Methods showsPrec :: Int -> RetType -> ShowS # show :: RetType -> String # showList :: [RetType] -> ShowS #

data ProcVolatility #

Constructors

Volatile |
Stable |
Immutable |

Instances

Eq ProcVolatility # |
Methods (==) :: ProcVolatility -> ProcVolatility -> Bool # (/=) :: ProcVolatility -> ProcVolatility -> Bool #
Show ProcVolatility # |
Methods showsPrec :: Int -> ProcVolatility -> ShowS # show :: ProcVolatility -> String # showList :: [ProcVolatility] -> ShowS #

data ProcDescription #

Constructors

ProcDescription |
Fields pdName :: Text pdArgs :: [PgArg] pdReturnType :: RetType pdVolatility :: ProcVolatility

Instances

Eq ProcDescription # |
Methods (==) :: ProcDescription -> ProcDescription -> Bool # (/=) :: ProcDescription -> ProcDescription -> Bool #
Show ProcDescription # |
Methods showsPrec :: Int -> ProcDescription -> ShowS # show :: ProcDescription -> String # showList :: [ProcDescription] -> ShowS #

type Schema = Text #

type TableName = Text #

type SqlQuery = Text #

type SqlFragment = Text #

type RequestBody = ByteString #

data Table #

Constructors

Table |
Fields tableSchema :: Schema tableName :: TableName tableInsertable :: Bool

Instances

Eq Table # |
Methods (==) :: Table -> Table -> Bool # (/=) :: Table -> Table -> Bool #
Ord Table # |
Methods compare :: Table -> Table -> Ordering # (<) :: Table -> Table -> Bool # (<=) :: Table -> Table -> Bool # (>) :: Table -> Table -> Bool # (>=) :: Table -> Table -> Bool # max :: Table -> Table -> Table # min :: Table -> Table -> Table #
Show Table # |
Methods showsPrec :: Int -> Table -> ShowS # show :: Table -> String # showList :: [Table] -> ShowS #
ToJSON Table # |
Methods toJSON :: Table -> Value # toEncoding :: Table -> Encoding # toJSONList :: [Table] -> Value # toEncodingList :: [Table] -> Encoding #

newtype ForeignKey #

Constructors

ForeignKey |
Fields fkCol :: Column

Instances

Eq ForeignKey # |
Methods (==) :: ForeignKey -> ForeignKey -> Bool # (/=) :: ForeignKey -> ForeignKey -> Bool #
Ord ForeignKey # |
Methods compare :: ForeignKey -> ForeignKey -> Ordering # (<) :: ForeignKey -> ForeignKey -> Bool # (<=) :: ForeignKey -> ForeignKey -> Bool # (>) :: ForeignKey -> ForeignKey -> Bool # (>=) :: ForeignKey -> ForeignKey -> Bool # max :: ForeignKey -> ForeignKey -> ForeignKey # min :: ForeignKey -> ForeignKey -> ForeignKey #
Show ForeignKey # |
Methods showsPrec :: Int -> ForeignKey -> ShowS # show :: ForeignKey -> String # showList :: [ForeignKey] -> ShowS #
ToJSON ForeignKey # |
Methods toJSON :: ForeignKey -> Value # toEncoding :: ForeignKey -> Encoding # toJSONList :: [ForeignKey] -> Value # toEncodingList :: [ForeignKey] -> Encoding #

data Column #

Constructors

Column |
Fields colTable :: Table colName :: Text colPosition :: Int32 colNullable :: Bool colType :: Text colUpdatable :: Bool colMaxLen :: Maybe Int32 colPrecision :: Maybe Int32 colDefault :: Maybe Text colEnum :: [Text] colFK :: Maybe ForeignKey

Instances

Eq Column # |
Methods (==) :: Column -> Column -> Bool # (/=) :: Column -> Column -> Bool #
Ord Column # |
Methods compare :: Column -> Column -> Ordering # (<) :: Column -> Column -> Bool # (<=) :: Column -> Column -> Bool # (>) :: Column -> Column -> Bool # (>=) :: Column -> Column -> Bool # max :: Column -> Column -> Column # min :: Column -> Column -> Column #
Show Column # |
Methods showsPrec :: Int -> Column -> ShowS # show :: Column -> String # showList :: [Column] -> ShowS #
ToJSON Column # |
Methods toJSON :: Column -> Value # toEncoding :: Column -> Encoding # toJSONList :: [Column] -> Value # toEncodingList :: [Column] -> Encoding #

type Synonym = (Column, Column) #

data PrimaryKey #

Constructors

PrimaryKey |
Fields pkTable :: Table pkName :: Text

Instances

Eq PrimaryKey # |
Methods (==) :: PrimaryKey -> PrimaryKey -> Bool # (/=) :: PrimaryKey -> PrimaryKey -> Bool #
Show PrimaryKey # |
Methods showsPrec :: Int -> PrimaryKey -> ShowS # show :: PrimaryKey -> String # showList :: [PrimaryKey] -> ShowS #

data OrderDirection #

Constructors

OrderAsc |
OrderDesc |

Instances

Eq OrderDirection # |
Methods (==) :: OrderDirection -> OrderDirection -> Bool # (/=) :: OrderDirection -> OrderDirection -> Bool #
Show OrderDirection # |
Methods showsPrec :: Int -> OrderDirection -> ShowS # show :: OrderDirection -> String # showList :: [OrderDirection] -> ShowS #

data OrderNulls #

Constructors

OrderNullsFirst |
OrderNullsLast |

Instances

Eq OrderNulls # |
Methods (==) :: OrderNulls -> OrderNulls -> Bool # (/=) :: OrderNulls -> OrderNulls -> Bool #
Show OrderNulls # |
Methods showsPrec :: Int -> OrderNulls -> ShowS # show :: OrderNulls -> String # showList :: [OrderNulls] -> ShowS #

data OrderTerm #

Constructors

OrderTerm |
Fields otTerm :: Field otDirection :: Maybe OrderDirection otNullOrder :: Maybe OrderNulls

Instances

Eq OrderTerm # |
Methods (==) :: OrderTerm -> OrderTerm -> Bool # (/=) :: OrderTerm -> OrderTerm -> Bool #
Show OrderTerm # |
Methods showsPrec :: Int -> OrderTerm -> ShowS # show :: OrderTerm -> String # showList :: [OrderTerm] -> ShowS #

data QualifiedIdentifier #

Constructors

QualifiedIdentifier |
Fields qiSchema :: Schema qiName :: TableName

Instances

Eq QualifiedIdentifier # |
Methods (==) :: QualifiedIdentifier -> QualifiedIdentifier -> Bool # (/=) :: QualifiedIdentifier -> QualifiedIdentifier -> Bool #
Show QualifiedIdentifier # |
Methods showsPrec :: Int -> QualifiedIdentifier -> ShowS # show :: QualifiedIdentifier -> String # showList :: [QualifiedIdentifier] -> ShowS #

data RelationType #

Constructors

Child |
Parent |
Many |
Root |

Instances

Eq RelationType # |
Methods (==) :: RelationType -> RelationType -> Bool # (/=) :: RelationType -> RelationType -> Bool #
Show RelationType # |
Methods showsPrec :: Int -> RelationType -> ShowS # show :: RelationType -> String # showList :: [RelationType] -> ShowS #

data Relation #

Constructors

Relation |
Fields relTable :: Table relColumns :: [Column] relFTable :: Table relFColumns :: [Column] relType :: RelationType relLTable :: Maybe Table relLCols1 :: Maybe [Column] relLCols2 :: Maybe [Column]

Instances

Eq Relation # |
Methods (==) :: Relation -> Relation -> Bool # (/=) :: Relation -> Relation -> Bool #
Show Relation # |
Methods showsPrec :: Int -> Relation -> ShowS # show :: Relation -> String # showList :: [Relation] -> ShowS #

newtype PayloadJSON #

An array of JSON objects that has been verified to have the same keys in every object

Constructors

PayloadJSON (Vector Object) |

Instances

Eq PayloadJSON # |
Methods (==) :: PayloadJSON -> PayloadJSON -> Bool # (/=) :: PayloadJSON -> PayloadJSON -> Bool #
Show PayloadJSON # |
Methods showsPrec :: Int -> PayloadJSON -> ShowS # show :: PayloadJSON -> String # showList :: [PayloadJSON] -> ShowS #

unPayloadJSON :: PayloadJSON -> Vector Object #

data Proxy #

Constructors

Proxy |
Fields proxyScheme :: Text proxyHost :: Text proxyPort :: Integer proxyPath :: Text

Instances

Eq Proxy # |
Methods (==) :: Proxy -> Proxy -> Bool # (/=) :: Proxy -> Proxy -> Bool #
Show Proxy # |
Methods showsPrec :: Int -> Proxy -> ShowS # show :: Proxy -> String # showList :: [Proxy] -> ShowS #

type Operator = Text #

operators :: HashMap Operator SqlFragment #

data Operation #

Constructors

Operation |
Fields hasNot :: Bool expr :: (Operator, Operand)

Instances

Eq Operation # |
Methods (==) :: Operation -> Operation -> Bool # (/=) :: Operation -> Operation -> Bool #
Show Operation # |
Methods showsPrec :: Int -> Operation -> ShowS # show :: Operation -> String # showList :: [Operation] -> ShowS #

data Operand #

Constructors

VText Text |
VTextL [Text] |
VForeignKey QualifiedIdentifier ForeignKey |

Instances

Eq Operand # |
Methods (==) :: Operand -> Operand -> Bool # (/=) :: Operand -> Operand -> Bool #
Show Operand # |
Methods showsPrec :: Int -> Operand -> ShowS # show :: Operand -> String # showList :: [Operand] -> ShowS #

data LogicOperator #

Constructors

And |
Or |

Instances

Eq LogicOperator # |
Methods (==) :: LogicOperator -> LogicOperator -> Bool # (/=) :: LogicOperator -> LogicOperator -> Bool #
Show LogicOperator # |
Methods showsPrec :: Int -> LogicOperator -> ShowS # show :: LogicOperator -> String # showList :: [LogicOperator] -> ShowS #

data LogicTree #

Boolean logic expression tree e.g. "and(name.eq.N,or(id.eq.1,id.eq.2))" is:

And / name.eq.N Or / id.eq.1 id.eq.2

Constructors

Expr Bool LogicOperator LogicTree LogicTree |
Stmnt Filter |

Instances

Eq LogicTree # |
Methods (==) :: LogicTree -> LogicTree -> Bool # (/=) :: LogicTree -> LogicTree -> Bool #
Show LogicTree # |
Methods showsPrec :: Int -> LogicTree -> ShowS # show :: LogicTree -> String # showList :: [LogicTree] -> ShowS #

type FieldName = Text #

type JsonPath = [Text] #

type Field = (FieldName, Maybe JsonPath) #

type Alias = Text #

type Cast = Text #

type NodeName = Text #

type SelectItem = (Field, Maybe Cast, Maybe Alias) #

type EmbedPath = [Text] #

Path of the embedded levels, e.g "clients.projects.name=eq.." gives Path ["clients", "projects"]

data Filter #

Constructors

Filter |
Fields field :: Field operation :: Operation

Instances

Eq Filter # |
Methods (==) :: Filter -> Filter -> Bool # (/=) :: Filter -> Filter -> Bool #
Show Filter # |
Methods showsPrec :: Int -> Filter -> ShowS # show :: Filter -> String # showList :: [Filter] -> ShowS #

data ReadQuery #

Constructors

Select |
Fields select :: [SelectItem] from :: [TableName] flt_ :: [Filter] logic :: [LogicTree] order :: Maybe [OrderTerm] range_ :: NonnegRange

Instances

Eq ReadQuery # |
Methods (==) :: ReadQuery -> ReadQuery -> Bool # (/=) :: ReadQuery -> ReadQuery -> Bool #
Show ReadQuery # |
Methods showsPrec :: Int -> ReadQuery -> ShowS # show :: ReadQuery -> String # showList :: [ReadQuery] -> ShowS #

data MutateQuery #

Constructors

Insert |
Fields in_ :: TableName qPayload :: PayloadJSON returning :: [FieldName]
Delete |
Fields in_ :: TableName where_ :: [Filter] logic :: [LogicTree] returning :: [FieldName]
Update |
Fields in_ :: TableName qPayload :: PayloadJSON where_ :: [Filter] logic :: [LogicTree] returning :: [FieldName]

Instances

Eq MutateQuery # |
Methods (==) :: MutateQuery -> MutateQuery -> Bool # (/=) :: MutateQuery -> MutateQuery -> Bool #
Show MutateQuery # |
Methods showsPrec :: Int -> MutateQuery -> ShowS # show :: MutateQuery -> String # showList :: [MutateQuery] -> ShowS #

type ReadNode = (ReadQuery, (NodeName, Maybe Relation, Maybe Alias)) #

type ReadRequest = Tree ReadNode #

type MutateRequest = MutateQuery #

data DbRequest #

Constructors

DbRead ReadRequest |
DbMutate MutateRequest |

toHeader :: ContentType -> Header #

Convert from ContentType to a full HTTP Header

toMime :: ContentType -> ByteString #

Convert from ContentType to a ByteString representing the mime type