-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | PostgreSQL client -- -- This package defines a PostgreSQL client. -- -- Check out the PostgreSQL module for a documentation overview. @package psql @version 0.0.0 -- | The various common types commonly used throughout this package are -- exported here. module PostgreSQL.Types -- | Value data Value Null :: Value Value :: ByteString -> Value -- | Postgre's regtype newtype RegType RegType :: Text -> RegType [unRegType] :: RegType -> Text -- | Packed parameter newtype PackedParam PackedParam :: Maybe (Oid, ByteString, Format) -> PackedParam -- | Packed parameter for a prepared query newtype PackedParamPrepared PackedParamPrepared :: Maybe (ByteString, Format) -> PackedParamPrepared -- | Error that occurs when parsing a column data ParserError UnsupportedFormat :: Format -> ParserError UnsupportedOid :: Oid -> ParserError type ParserErrors = NonEmpty ParserError -- | Error that may occur during processing data ProcessorError ColumnParserError :: ColumnNum -> Oid -> Format -> ParserError -> ProcessorError [processorError_column] :: ProcessorError -> ColumnNum [processorError_type] :: ProcessorError -> Oid [processorError_format] :: ProcessorError -> Format [processorError_columnError] :: ProcessorError -> ParserError CellParserError :: ColumnNum -> Oid -> Format -> RowNum -> Value -> Text -> ProcessorError [processorError_column] :: ProcessorError -> ColumnNum [processorError_type] :: ProcessorError -> Oid [processorError_format] :: ProcessorError -> Format [processorError_row] :: ProcessorError -> RowNum [processorError_value] :: ProcessorError -> Value [processorError_cellError] :: ProcessorError -> Text NotEnoughColumns :: ColumnNum -> ColumnNum -> ProcessorError [processorError_wantedColumns] :: ProcessorError -> ColumnNum [processorError_haveColumns] :: ProcessorError -> ColumnNum MissingNamedColumn :: ByteString -> ProcessorError [processorError_wantedColumnName] :: ProcessorError -> ByteString type ProcessorErrors = NonEmpty ProcessorError -- | Error that occurs when validating the result data ResultError BadResultStatus :: ByteString -> ResultError [resultError_status] :: ResultError -> ByteString NoRows :: ResultError MultipleRows :: RowNum -> ResultError [resultError_numRows] :: ResultError -> RowNum FailedToParseAffectedRows :: Text -> ResultError [resultError_message] :: ResultError -> Text type ResultErrors = NonEmpty ResultError data Error -- | Occurs when processing the result table ErrorDuringProcessing :: ProcessorError -> Error -- | Occurs when validating the result object ErrorDuringValidation :: ResultError -> Error type Errors = NonEmpty Error -- | Numberic column identifier newtype ColumnNum ColumnNum :: Column -> ColumnNum [fromColumnNum] :: ColumnNum -> Column -- | Numberic row identifier newtype RowNum RowNum :: Row -> RowNum [fromRowNum] :: RowNum -> Row data Format Text :: Format Binary :: Format newtype Oid Oid :: CUInt -> Oid data Connection instance GHC.Classes.Ord PostgreSQL.Types.Value instance GHC.Classes.Eq PostgreSQL.Types.Value instance GHC.Show.Show PostgreSQL.Types.Value instance Data.String.IsString PostgreSQL.Types.RegType instance GHC.Classes.Ord PostgreSQL.Types.RegType instance GHC.Classes.Eq PostgreSQL.Types.RegType instance GHC.Read.Read PostgreSQL.Types.RegType instance GHC.Show.Show PostgreSQL.Types.RegType instance GHC.Show.Show PostgreSQL.Types.PackedParam instance GHC.Show.Show PostgreSQL.Types.PackedParamPrepared instance GHC.Classes.Ord PostgreSQL.Types.ParserError instance GHC.Classes.Eq PostgreSQL.Types.ParserError instance GHC.Show.Show PostgreSQL.Types.ParserError instance GHC.Real.Real PostgreSQL.Types.ColumnNum instance GHC.Real.Integral PostgreSQL.Types.ColumnNum instance GHC.Num.Num PostgreSQL.Types.ColumnNum instance GHC.Enum.Bounded PostgreSQL.Types.ColumnNum instance GHC.Enum.Enum PostgreSQL.Types.ColumnNum instance GHC.Classes.Ord PostgreSQL.Types.ColumnNum instance GHC.Classes.Eq PostgreSQL.Types.ColumnNum instance GHC.Read.Read PostgreSQL.Types.ColumnNum instance GHC.Show.Show PostgreSQL.Types.ColumnNum instance GHC.Real.Real PostgreSQL.Types.RowNum instance GHC.Real.Integral PostgreSQL.Types.RowNum instance GHC.Num.Num PostgreSQL.Types.RowNum instance GHC.Enum.Bounded PostgreSQL.Types.RowNum instance GHC.Enum.Enum PostgreSQL.Types.RowNum instance GHC.Classes.Ord PostgreSQL.Types.RowNum instance GHC.Classes.Eq PostgreSQL.Types.RowNum instance GHC.Read.Read PostgreSQL.Types.RowNum instance GHC.Show.Show PostgreSQL.Types.RowNum instance GHC.Classes.Ord PostgreSQL.Types.ResultError instance GHC.Classes.Eq PostgreSQL.Types.ResultError instance GHC.Show.Show PostgreSQL.Types.ResultError instance GHC.Classes.Ord PostgreSQL.Types.ProcessorError instance GHC.Classes.Eq PostgreSQL.Types.ProcessorError instance GHC.Show.Show PostgreSQL.Types.ProcessorError instance GHC.Exception.Type.Exception PostgreSQL.Types.Error instance GHC.Classes.Ord PostgreSQL.Types.Error instance GHC.Classes.Eq PostgreSQL.Types.Error instance GHC.Show.Show PostgreSQL.Types.Error instance Data.String.IsString PostgreSQL.Types.Value -- | Things in this module are dedicated to parsing Postgres values -- independent of their format or type. module PostgreSQL.Result.Cell -- | Cell value parser newtype Cell a Cell :: (Value -> Either (NonEmpty Text) a) -> Cell a [parseCell] :: Cell a -> Value -> Either (NonEmpty Text) a -- | Do not parse the cell at all. ignored :: Cell () -- | Get the raw cell value. Does not allow NULL. raw :: Cell ByteString -- | Parse as UTF-8 Text. Does not allow NULL. text :: Cell Text -- | Parse something using its Read instance via text. -- Rejects NULL values. readable :: Read a => Cell a -- | Validate the given cell parser. validate :: Cell a -> (a -> Either Text b) -> Cell b instance GHC.Base.Functor PostgreSQL.Result.Cell.Cell instance Data.Functor.Alt.Alt PostgreSQL.Result.Cell.Cell -- | Exports of this module are concerned with columns in a Postgres query -- result. This includes validation of type and format. Parsing of the -- actual cell values in a column is delegated to -- PostgreSQL.Result.Cell. module PostgreSQL.Result.Column -- | Result column parser newtype Column a Column :: (Oid -> Format -> Either ParserErrors (Cell a)) -> Column a [parseColumn] :: Column a -> Oid -> Format -> Either ParserErrors (Cell a) -- | Don't parse the column. ignored :: Column () -- | Raw value. Rejects NULL. raw :: Column ByteString -- | Parse as UTF-8 Text. See text. text :: Column Text -- | Parse something using its Read instance. Only supports textual -- format. See readable. readable :: Read a => Column a -- | Lift a cell parser. This does perform any validation on column type or -- format. unchecked :: Cell a -> Column a -- | Validate the result of a cell parser. validate :: Column a -> (a -> Either Text b) -> Column b -- | Only allow textual format. onlyTextual :: Column a -> Column a -- | Only allow binary format. onlyBinary :: Column a -> Column a -- | Default column parser for a type class AutoColumn a -- | Default column parser for a autoColumn :: AutoColumn a => Column a -- | Provides a AutoColumn instance using the Read for -- a newtype Readable a Readable :: a -> Readable a -- | The raw cell value data RawValue RawValue :: Oid -> Format -> Value -> RawValue [rawValue_type] :: RawValue -> Oid [rawValue_format] :: RawValue -> Format [rawValue_value] :: RawValue -> Value instance GHC.Base.Functor PostgreSQL.Result.Column.Column instance GHC.Classes.Ord PostgreSQL.Result.Column.RawValue instance GHC.Classes.Eq PostgreSQL.Result.Column.RawValue instance GHC.Show.Show PostgreSQL.Result.Column.RawValue instance PostgreSQL.Result.Column.AutoColumn PostgreSQL.Result.Column.RawValue instance GHC.Read.Read a => PostgreSQL.Result.Column.AutoColumn (PostgreSQL.Result.Column.Readable a) instance PostgreSQL.Result.Column.AutoColumn () instance PostgreSQL.Result.Column.AutoColumn GHC.Types.Int instance PostgreSQL.Result.Column.AutoColumn GHC.Types.Word instance PostgreSQL.Result.Column.AutoColumn GHC.Integer.Type.Integer instance PostgreSQL.Result.Column.AutoColumn GHC.Natural.Natural instance PostgreSQL.Result.Column.AutoColumn GHC.Types.Float instance PostgreSQL.Result.Column.AutoColumn GHC.Types.Double instance PostgreSQL.Result.Column.AutoColumn Database.PostgreSQL.LibPQ.Oid instance PostgreSQL.Result.Column.AutoColumn Data.Text.Internal.Text instance (PostgreSQL.Result.Column.AutoColumn a, PostgreSQL.Result.Column.AutoColumn b) => PostgreSQL.Result.Column.AutoColumn (Data.Either.Either a b) instance Data.Functor.Alt.Alt PostgreSQL.Result.Column.Column -- | Things in this module are used for processing Postgres query result -- rows. module PostgreSQL.Result.Row -- | Result row parser data Row a -- | Translate a Row expression. Validate things in m and -- parse each row in row. runRow :: (Monad m, Applicative row) => Row a -> (forall x. ColumnRequest x -> m (row x)) -> m (row a) -- | Generate a row runner for libpq's Result. runRowPq :: (MonadError ProcessorErrors m, MonadIO m) => Result -> Row a -> m (RowNum -> m a) -- | Request a column data ColumnRequest a ColumnReqest :: ColumnPosition -> Column a -> ColumnRequest a -- | Location of the column [columnRequest_position] :: ColumnRequest a -> ColumnPosition -- | Parser for the column [columnRequest_parser] :: ColumnRequest a -> Column a -- | Position of a column data ColumnPosition -- | Column is at a fixed index. FixedColumn :: ColumnNum -> ColumnPosition -- | Column has a fixed name. NamedColumn :: ByteString -> ColumnPosition -- | Floating column using the default Column for a -- -- The position of this column is depenend on other floating columns left -- of it. -- -- For example: -- --
-- foo = baz <$> column <*> column <*> column -- -- ^ A ^ B ^ C ---- -- Here, A would be at index 0, B at 1 and C -- at 2. Other non-floating columns do not impact the column indices. column :: AutoColumn a => Row a -- | Same as column but lets you specify the Column. columnWith :: Column a -> Row a -- | Fixed-position column using the default Column for a fixedColumn :: AutoColumn a => ColumnNum -> Row a -- | Same as fixedColumn but lets you specify the Column. fixedColumnWith :: ColumnNum -> Column a -> Row a -- | Named column using the default Column for a namedColumn :: AutoColumn a => ByteString -> Row a -- | Same as namedColumn but lets you specify the Column. namedColumnWith :: ByteString -> Column a -> Row a -- | Default row parser for a type class AutoRow a -- | Default row parser for a -- -- You may omit a definition for autoRow if a implements -- Generic. autoRow :: AutoRow a => Row a -- | Default row parser for a -- -- You may omit a definition for autoRow if a implements -- Generic. autoRow :: (AutoRow a, Generic a, AutoRow (Rep a Void)) => Row a -- | Generic row parser -- -- You can use this with your Generic-implementing data types. -- --
-- data Foo = Foo
-- { bar :: Integer
-- , baz :: Text
-- }
-- deriving Generic
--
-- fooRow :: Row Foo
-- fooRow = genericRow
--
genericRow :: (Generic a, AutoRow (Rep a Void)) => Row a
-- | This class is used to intercept instance heads like Fixed and
-- Named that have special additional meaning. For most cases it
-- will delegate to AutoColumn.
--
-- Use this class instead of AutoColumn when implementing
-- AutoRow instances.
class AutoColumnDelegate a
-- | Value for a column at a fixed location
newtype Fixed (index :: Nat) a
Fixed :: a -> Fixed (index :: Nat) a
[fromFixed] :: Fixed (index :: Nat) a -> a
-- | Value for a named column
newtype Named (name :: Symbol) a
Named :: a -> Named (name :: Symbol) a
[fromNamed] :: Named (name :: Symbol) a -> a
instance GHC.Classes.Ord PostgreSQL.Result.Row.ColumnPosition
instance GHC.Classes.Eq PostgreSQL.Result.Row.ColumnPosition
instance GHC.Read.Read PostgreSQL.Result.Row.ColumnPosition
instance GHC.Show.Show PostgreSQL.Result.Row.ColumnPosition
instance GHC.Base.Functor PostgreSQL.Result.Row.ColumnRequest
instance PostgreSQL.Result.Row.AutoColumnDelegate a => PostgreSQL.Result.Row.AutoRow (GHC.Generics.K1 tag a x)
instance PostgreSQL.Result.Row.AutoRow (f x) => PostgreSQL.Result.Row.AutoRow (GHC.Generics.M1 tag meta f x)
instance (PostgreSQL.Result.Row.AutoRow (lhs x), PostgreSQL.Result.Row.AutoRow (rhs x)) => PostgreSQL.Result.Row.AutoRow ((GHC.Generics.:*:) lhs rhs x)
instance PostgreSQL.Result.Row.AutoColumnDelegate a => PostgreSQL.Result.Row.AutoRow (Data.Functor.Identity.Identity a)
instance (PostgreSQL.Result.Row.AutoColumnDelegate a, PostgreSQL.Result.Row.AutoColumnDelegate b) => PostgreSQL.Result.Row.AutoRow (a, b)
instance (PostgreSQL.Result.Row.AutoColumnDelegate a, PostgreSQL.Result.Row.AutoColumnDelegate b, PostgreSQL.Result.Row.AutoColumnDelegate c) => PostgreSQL.Result.Row.AutoRow (a, b, c)
instance (PostgreSQL.Result.Row.AutoColumnDelegate a, PostgreSQL.Result.Row.AutoColumnDelegate b, PostgreSQL.Result.Row.AutoColumnDelegate c, PostgreSQL.Result.Row.AutoColumnDelegate d) => PostgreSQL.Result.Row.AutoRow (a, b, c, d)
instance (PostgreSQL.Result.Row.AutoColumnDelegate a, PostgreSQL.Result.Row.AutoColumnDelegate b, PostgreSQL.Result.Row.AutoColumnDelegate c, PostgreSQL.Result.Row.AutoColumnDelegate d, PostgreSQL.Result.Row.AutoColumnDelegate e) => PostgreSQL.Result.Row.AutoRow (a, b, c, d, e)
instance (PostgreSQL.Result.Row.AutoColumnDelegate a, PostgreSQL.Result.Row.AutoColumnDelegate b, PostgreSQL.Result.Row.AutoColumnDelegate c, PostgreSQL.Result.Row.AutoColumnDelegate d, PostgreSQL.Result.Row.AutoColumnDelegate e, PostgreSQL.Result.Row.AutoColumnDelegate f) => PostgreSQL.Result.Row.AutoRow (a, b, c, d, e, f)
instance (PostgreSQL.Result.Row.AutoColumnDelegate a, PostgreSQL.Result.Row.AutoColumnDelegate b, PostgreSQL.Result.Row.AutoColumnDelegate c, PostgreSQL.Result.Row.AutoColumnDelegate d, PostgreSQL.Result.Row.AutoColumnDelegate e, PostgreSQL.Result.Row.AutoColumnDelegate f, PostgreSQL.Result.Row.AutoColumnDelegate g) => PostgreSQL.Result.Row.AutoRow (a, b, c, d, e, f, g)
instance (GHC.TypeNats.KnownNat index, PostgreSQL.Result.Column.AutoColumn a) => PostgreSQL.Result.Row.AutoColumnDelegate (PostgreSQL.Result.Row.Fixed index a)
instance (GHC.TypeLits.KnownSymbol name, PostgreSQL.Result.Column.AutoColumn a) => PostgreSQL.Result.Row.AutoColumnDelegate (PostgreSQL.Result.Row.Named name a)
instance PostgreSQL.Result.Column.AutoColumn a => PostgreSQL.Result.Row.AutoColumnDelegate a
instance GHC.Base.Functor PostgreSQL.Result.Row.Row
instance GHC.Base.Applicative PostgreSQL.Result.Row.Row
instance Data.Functor.Bind.Class.Apply PostgreSQL.Result.Row.Row
-- | This module is dedicated to dealing with query results.
module PostgreSQL.Result
-- | Query result
data Result a
-- | Process libpq's Result.
runResultPq :: MonadIO m => Result -> Result a -> m (Either Errors a)
-- | Ignore the result set.
ignored :: Result ()
-- | Process exactly 1 row.
single :: Row a -> Result a
-- | Process only the first row. There may be more rows in the result set,
-- but they won't be touched.
first :: Row a -> Result a
-- | Process 0 or more rows.
many :: Row a -> Result (Vector a)
-- | Get the number of affected rows.
affectedRows :: Result Integer
-- | Check the result, if any, and the connection for errors.
checkForError :: (MonadIO m, MonadError ResultErrors m) => Connection -> Maybe Result -> m Result
instance GHC.Base.Functor PostgreSQL.Result.Result
-- | Here are things dealing with query parameters.
module PostgreSQL.Param
-- | Parameter type
data Type
-- | Type is inferred on the server side
InferredType :: Type
-- | Explicit static type
StaticType :: Oid -> Type
-- | Get the OID for the type.
typeOid :: Type -> Oid
-- | Static parameter information
data Info a
Info :: Type -> Maybe Text -> Format -> a -> Info a
[info_type] :: Info a -> Type
-- | This may be used as an explicit type annotation when used in a
-- Statement or Template
[info_typeName] :: Info a -> Maybe Text
[info_format] :: Info a -> Format
[info_pack] :: Info a -> a
-- | Value
data Value
Null :: Value
Value :: ByteString -> Value
data Oid
data Format
Text :: Format
Binary :: Format
-- | Packed parameter
newtype PackedParam
PackedParam :: Maybe (Oid, ByteString, Format) -> PackedParam
-- | Pack a parameter into a postgresql-libpq format.
packParam :: Info Value -> PackedParam
-- | Convert PackedParam.
toPrepared :: PackedParam -> PackedParamPrepared
-- | Packed parameter for a prepared query
newtype PackedParamPrepared
PackedParamPrepared :: Maybe (ByteString, Format) -> PackedParamPrepared
-- | Pack a parameter for a prepared query into a postgresql-libpq
-- format.
packParamPrepared :: Info Value -> PackedParamPrepared
-- | a can be used as a parameter
class Param a
-- | Parameter information
paramInfo :: Param a => Info (a -> Value)
-- | Raw textual parameter
newtype RawText
RawText :: ByteString -> RawText
[unRawText] :: RawText -> ByteString
instance GHC.Classes.Ord PostgreSQL.Param.Type
instance GHC.Classes.Eq PostgreSQL.Param.Type
instance GHC.Show.Show PostgreSQL.Param.Type
instance GHC.Generics.Generic (PostgreSQL.Param.Info a)
instance Data.Traversable.Traversable PostgreSQL.Param.Info
instance Data.Foldable.Foldable PostgreSQL.Param.Info
instance GHC.Base.Functor PostgreSQL.Param.Info
instance GHC.Classes.Ord PostgreSQL.Param.RawText
instance GHC.Classes.Eq PostgreSQL.Param.RawText
instance GHC.Show.Show PostgreSQL.Param.RawText
instance PostgreSQL.Param.Param PostgreSQL.Param.RawText
instance PostgreSQL.Param.Param GHC.Integer.Type.Integer
instance PostgreSQL.Param.Param GHC.Types.Double
instance PostgreSQL.Param.Param Data.Text.Internal.Text
instance PostgreSQL.Param.Param Database.PostgreSQL.LibPQ.Oid
instance PostgreSQL.Param.Param PostgreSQL.Types.RegType
instance PostgreSQL.Param.Param PostgreSQL.Types.Value
-- | Tools to deal with templates and statements are defined here.
module PostgreSQL.Statement
-- | SQL statement template
data Template a
-- | Create a code-only statement.
code :: Text -> Template a
-- | Create a code segment that mentions the given identifier (e.g. table
-- or column name).
identifier :: Text -> Template a
-- | Encase the given string literal in single quotes. Single quotes in the
-- literal are automatically escaped.
string :: Text -> Template a
-- | Reference a parameter.
param :: forall b a. Param b => (a -> b) -> Template a
-- | Reference a parameter.
paramWith :: Info (a -> Value) -> Template a
-- | Constant part of a query.
constant :: forall b a. Param b => b -> Template a
-- | Rendered SQL statement
data Statement a
Statement :: ByteString -> (a -> [PackedParam]) -> [Oid] -> ByteString -> Statement a
[statement_code] :: Statement a -> ByteString
[statement_mkParams] :: Statement a -> a -> [PackedParam]
[statement_types] :: Statement a -> [Oid]
[statement_name] :: Statement a -> ByteString
-- | Render the SQL statement.
renderTemplate :: Template a -> Statement a
-- | Prepared statement
data PreparedStatement a
PreparedStatement :: ByteString -> (a -> [PackedParamPrepared]) -> PreparedStatement a
[preparedStatement_name] :: PreparedStatement a -> ByteString
[preparedStatement_mkParams] :: PreparedStatement a -> a -> [PackedParamPrepared]
-- | Produces a Template expression.
--
-- Supports the same features as stmt.
tpl :: QuasiQuoter
-- | Produces a Statement expression.
--
-- -- [stmt| SELECT $param * 2 |] ---- -- Use $$ to render a single $. -- --
-- data MyParams = MyParams { foo :: Int, bar :: Text }
--
-- myStatement :: Statement MyParams
-- myStatement = [stmt| SELECT baz FROM my_table WHERE foo > ${foo} AND bar = ${bar} |]
--
stmt :: QuasiQuoter
instance GHC.Base.Monoid (PostgreSQL.Statement.Template a)
instance GHC.Base.Semigroup (PostgreSQL.Statement.Template a)
instance Data.Functor.Contravariant.Contravariant PostgreSQL.Statement.PreparedStatement
instance Data.Functor.Contravariant.Contravariant PostgreSQL.Statement.Statement
instance Data.Functor.Contravariant.Contravariant PostgreSQL.Statement.Template
instance Data.String.IsString (PostgreSQL.Statement.Template a)
instance (GHC.Records.HasField n r a, PostgreSQL.Param.Param a) => GHC.OverloadedLabels.IsLabel n (PostgreSQL.Statement.Template r)
instance Data.Functor.Contravariant.Contravariant PostgreSQL.Statement.Segment
-- | Class declarations for query execution
module PostgreSQL.Query.Class
-- | PostgreSQL query
class Monad query => Query query where {
-- | Native query result
type family NativeResult query :: Type;
}
-- | Execute a statement.
executeStatement :: Query query => Statement a -> a -> query (NativeResult query)
-- | Execute a previously prepared statement.
executePreparedStatement :: Query query => PreparedStatement a -> a -> query (NativeResult query)
-- | Prepare a statement. The prepared statement is only valid within the
-- provided continuation.
withPreparedStatement :: Query query => Statement a -> (PreparedStatement a -> query r) -> query r
-- | Process the result object.
processResult :: Query query => NativeResult query -> Result a -> query a
-- | statement is an executable statement.
class Executable statement
-- | Execute a statement.
execute :: (Executable statement, Query query) => statement param -> param -> query (NativeResult query)
instance PostgreSQL.Query.Class.Executable PostgreSQL.Statement.Statement
instance PostgreSQL.Query.Class.Executable PostgreSQL.Statement.PreparedStatement
-- | In here one will find the things to execute database queries.
module PostgreSQL.Query
-- | Execute a statement.
execute :: (Executable statement, Query query) => statement param -> param -> query (NativeResult query)
-- | Like execute but does not concern itself with the result
-- handle.
execute_ :: (Executable statement, Query query) => statement param -> param -> query ()
-- | Perform a parameterized query.
query :: (Executable statement, Query query, AutoRow row) => statement param -> param -> query (Vector row)
-- | Perform a parameterized query. This also lets you specify the result
-- processor explicitly.
queryWith :: (Executable statement, Query query) => statement param -> param -> Result row -> query row
-- | PostgreSQL query
class Monad query => Query query where {
-- | Native query result
type family NativeResult query :: Type;
}
-- | Execute a statement.
executeStatement :: Query query => Statement a -> a -> query (NativeResult query)
-- | Execute a previously prepared statement.
executePreparedStatement :: Query query => PreparedStatement a -> a -> query (NativeResult query)
-- | Prepare a statement. The prepared statement is only valid within the
-- provided continuation.
withPreparedStatement :: Query query => Statement a -> (PreparedStatement a -> query r) -> query r
-- | Process the result object.
processResult :: Query query => NativeResult query -> Result a -> query a
-- | Interpreter for Query
data QueryT m a
-- | Run an interaction with a PostgreSQL database.
runQueryT :: Connection -> QueryT m a -> m (Either Errors a)
-- | Like runQueryT but throw the first Error instead.
runQueryTThrow :: MonadThrow m => Connection -> QueryT m a -> m a
instance Control.Monad.Catch.MonadMask m => Control.Monad.Catch.MonadMask (PostgreSQL.Query.QueryT m)
instance Control.Monad.Catch.MonadCatch m => Control.Monad.Catch.MonadCatch (PostgreSQL.Query.QueryT m)
instance Control.Monad.Catch.MonadThrow m => Control.Monad.Catch.MonadThrow (PostgreSQL.Query.QueryT m)
instance GHC.Base.Monad m => Control.Monad.Error.Class.MonadError PostgreSQL.Types.Errors (PostgreSQL.Query.QueryT m)
instance Control.Monad.Writer.Class.MonadWriter s m => Control.Monad.Writer.Class.MonadWriter s (PostgreSQL.Query.QueryT m)
instance Control.Monad.State.Class.MonadState s m => Control.Monad.State.Class.MonadState s (PostgreSQL.Query.QueryT m)
instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (PostgreSQL.Query.QueryT m)
instance GHC.Base.Monad m => GHC.Base.Monad (PostgreSQL.Query.QueryT m)
instance GHC.Base.Monad m => GHC.Base.Applicative (PostgreSQL.Query.QueryT m)
instance GHC.Base.Monad m => Data.Functor.Bind.Class.Apply (PostgreSQL.Query.QueryT m)
instance GHC.Base.Functor m => GHC.Base.Functor (PostgreSQL.Query.QueryT m)
instance GHC.Base.Monad m => Data.Functor.Alt.Alt (PostgreSQL.Query.QueryT m)
instance GHC.Base.Monad m => Data.Functor.Bind.Class.Bind (PostgreSQL.Query.QueryT m)
instance Control.Monad.Trans.Class.MonadTrans PostgreSQL.Query.QueryT
instance Control.Monad.Reader.Class.MonadReader r m => Control.Monad.Reader.Class.MonadReader r (PostgreSQL.Query.QueryT m)
instance (Control.Monad.IO.Class.MonadIO m, Control.Monad.Catch.MonadMask m) => PostgreSQL.Query.Class.Query (PostgreSQL.Query.QueryT m)
-- | General class declarations
module PostgreSQL.Class
-- | PostgreSQL queries can be executed in m
class Query query => RunQuery query m | m -> query
-- | Run a query.
runQuery :: RunQuery query m => query a -> m (Either Errors a)
-- | Like runQuery but throws the first error instead.
runQueryThrow :: (MonadThrow m, RunQuery query m) => query a -> m a
instance (PostgreSQL.Class.RunQuery query m, GHC.Base.Monad m, Control.Monad.Trans.Class.MonadTrans t) => PostgreSQL.Class.RunQuery query (t m)
-- | This module defines an interpreter for RunQuery.
module PostgreSQL.ConnectionPool
-- | Interpreter for RunQuery which dispatches queries to a pool of
-- database connections
newtype ConnectionPoolT m a
ConnectionPoolT :: PoolT Connection m a -> ConnectionPoolT m a
[unConnectionPoolT] :: ConnectionPoolT m a -> PoolT Connection m a
-- | Run connection pool transformer.
runConnectionPoolT :: (MonadIO m, MonadConc m) => m Connection -> Settings -> ConnectionPoolT m a -> m a
-- | Default settings for the connection pool
defaultConnectionPoolSettings :: Settings
-- | Retrieve the connection pool metrics.
connectionPoolMetrics :: ConnectionPoolT m (Metrics Natural)
instance Control.Monad.Conc.Class.MonadConc m => Control.Monad.Conc.Class.MonadConc (PostgreSQL.ConnectionPool.ConnectionPoolT m)
instance Control.Monad.Catch.MonadMask m => Control.Monad.Catch.MonadMask (PostgreSQL.ConnectionPool.ConnectionPoolT m)
instance Control.Monad.Catch.MonadCatch m => Control.Monad.Catch.MonadCatch (PostgreSQL.ConnectionPool.ConnectionPoolT m)
instance Control.Monad.Catch.MonadThrow m => Control.Monad.Catch.MonadThrow (PostgreSQL.ConnectionPool.ConnectionPoolT m)
instance Control.Monad.Writer.Class.MonadWriter w m => Control.Monad.Writer.Class.MonadWriter w (PostgreSQL.ConnectionPool.ConnectionPoolT m)
instance Control.Monad.Error.Class.MonadError e m => Control.Monad.Error.Class.MonadError e (PostgreSQL.ConnectionPool.ConnectionPoolT m)
instance Control.Monad.State.Class.MonadState s m => Control.Monad.State.Class.MonadState s (PostgreSQL.ConnectionPool.ConnectionPoolT m)
instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (PostgreSQL.ConnectionPool.ConnectionPoolT m)
instance Control.Monad.Fail.MonadFail m => Control.Monad.Fail.MonadFail (PostgreSQL.ConnectionPool.ConnectionPoolT m)
instance GHC.Base.Monad m => GHC.Base.Monad (PostgreSQL.ConnectionPool.ConnectionPoolT m)
instance GHC.Base.Applicative m => GHC.Base.Applicative (PostgreSQL.ConnectionPool.ConnectionPoolT m)
instance GHC.Base.Functor m => GHC.Base.Functor (PostgreSQL.ConnectionPool.ConnectionPoolT m)
instance Control.Monad.Trans.Class.MonadTrans PostgreSQL.ConnectionPool.ConnectionPoolT
instance (Control.Monad.Catch.MonadMask m, Control.Monad.IO.Class.MonadIO m) => PostgreSQL.Class.RunQuery (PostgreSQL.Query.QueryT m) (PostgreSQL.ConnectionPool.ConnectionPoolT m)
-- | PostgreSQL client
--
-- Have a look at the individual sub-sections to find out more about the
-- respective concepts.
module PostgreSQL
-- | SQL statement template
data Template a
-- | Render the SQL statement.
renderTemplate :: Template a -> Statement a
-- | Produces a Template expression.
--
-- Supports the same features as stmt.
tpl :: QuasiQuoter
-- | Create a code-only statement.
code :: Text -> Template a
-- | Create a code segment that mentions the given identifier (e.g. table
-- or column name).
identifier :: Text -> Template a
-- | Encase the given string literal in single quotes. Single quotes in the
-- literal are automatically escaped.
string :: Text -> Template a
-- | Reference a parameter.
param :: forall b a. Param b => (a -> b) -> Template a
-- | Reference a parameter.
paramWith :: Info (a -> Value) -> Template a
-- | Constant part of a query.
constant :: forall b a. Param b => b -> Template a
-- | Rendered SQL statement
data Statement a
-- | Produces a Statement expression.
--
-- -- [stmt| SELECT $param * 2 |] ---- -- Use $$ to render a single $. -- --
-- data MyParams = MyParams { foo :: Int, bar :: Text }
--
-- myStatement :: Statement MyParams
-- myStatement = [stmt| SELECT baz FROM my_table WHERE foo > ${foo} AND bar = ${bar} |]
--
stmt :: QuasiQuoter
-- | Prepared statement
data PreparedStatement a
-- | Execute a statement.
execute :: (Executable statement, Query query) => statement param -> param -> query (NativeResult query)
-- | Like execute but does not concern itself with the result
-- handle.
execute_ :: (Executable statement, Query query) => statement param -> param -> query ()
-- | Perform a parameterized query.
query :: (Executable statement, Query query, AutoRow row) => statement param -> param -> query (Vector row)
-- | Perform a parameterized query. This also lets you specify the result
-- processor explicitly.
queryWith :: (Executable statement, Query query) => statement param -> param -> Result row -> query row
-- | Prepare a statement. The prepared statement is only valid within the
-- provided continuation.
withPreparedStatement :: Query query => Statement a -> (PreparedStatement a -> query r) -> query r
-- | PostgreSQL query
class Monad query => Query query
-- | PostgreSQL queries can be executed in m
class Query query => RunQuery query m | m -> query
-- | Run a query.
runQuery :: RunQuery query m => query a -> m (Either Errors a)
-- | Like runQuery but throws the first error instead.
runQueryThrow :: (MonadThrow m, RunQuery query m) => query a -> m a
-- | Interpreter for RunQuery which dispatches queries to a pool of
-- database connections
data ConnectionPoolT m a
-- | Run connection pool transformer.
runConnectionPoolT :: (MonadIO m, MonadConc m) => m Connection -> Settings -> ConnectionPoolT m a -> m a
-- | Default settings for the connection pool
defaultConnectionPoolSettings :: Settings
-- | Query result
data Result a
-- | Ignore the result set.
ignored :: Result ()
-- | Process exactly 1 row.
single :: Row a -> Result a
-- | Process only the first row. There may be more rows in the result set,
-- but they won't be touched.
first :: Row a -> Result a
-- | Process 0 or more rows.
many :: Row a -> Result (Vector a)
-- | Get the number of affected rows.
affectedRows :: Result Integer
-- | Result row parser
data Row a
-- | Floating column using the default Column for a
--
-- The position of this column is depenend on other floating columns left
-- of it.
--
-- For example:
--
-- -- foo = baz <$> column <*> column <*> column -- -- ^ A ^ B ^ C ---- -- Here, A would be at index 0, B at 1 and C -- at 2. Other non-floating columns do not impact the column indices. column :: AutoColumn a => Row a -- | Same as column but lets you specify the Column. columnWith :: Column a -> Row a -- | Fixed-position column using the default Column for a fixedColumn :: AutoColumn a => ColumnNum -> Row a -- | Same as fixedColumn but lets you specify the Column. fixedColumnWith :: ColumnNum -> Column a -> Row a -- | Named column using the default Column for a namedColumn :: AutoColumn a => ByteString -> Row a -- | Same as namedColumn but lets you specify the Column. namedColumnWith :: ByteString -> Column a -> Row a -- | Default row parser for a type class AutoRow a -- | Default row parser for a -- -- You may omit a definition for autoRow if a implements -- Generic. autoRow :: AutoRow a => Row a -- | Default row parser for a -- -- You may omit a definition for autoRow if a implements -- Generic. autoRow :: (AutoRow a, Generic a, AutoRow (Rep a Void)) => Row a -- | This class is used to intercept instance heads like Fixed and -- Named that have special additional meaning. For most cases it -- will delegate to AutoColumn. -- -- Use this class instead of AutoColumn when implementing -- AutoRow instances. class AutoColumnDelegate a -- | Generic row parser -- -- You can use this with your Generic-implementing data types. -- --
-- data Foo = Foo
-- { bar :: Integer
-- , baz :: Text
-- }
-- deriving Generic
--
-- fooRow :: Row Foo
-- fooRow = genericRow
--
genericRow :: (Generic a, AutoRow (Rep a Void)) => Row a
-- | Value for a named column
newtype Named (name :: Symbol) a
Named :: a -> Named (name :: Symbol) a
[fromNamed] :: Named (name :: Symbol) a -> a
-- | Value for a column at a fixed location
newtype Fixed (index :: Nat) a
Fixed :: a -> Fixed (index :: Nat) a
[fromFixed] :: Fixed (index :: Nat) a -> a
-- | Result column parser
data Column a
-- | Default column parser for a type
class AutoColumn a
-- | Default column parser for a
autoColumn :: AutoColumn a => Column a
-- | Provides a AutoColumn instance using the Read for
-- a
newtype Readable a
Readable :: a -> Readable a
data Error
-- | Occurs when processing the result table
ErrorDuringProcessing :: ProcessorError -> Error
-- | Occurs when validating the result object
ErrorDuringValidation :: ResultError -> Error
type Errors = NonEmpty Error
-- | Error that may occur during processing
data ProcessorError
ColumnParserError :: ColumnNum -> Oid -> Format -> ParserError -> ProcessorError
[processorError_column] :: ProcessorError -> ColumnNum
[processorError_type] :: ProcessorError -> Oid
[processorError_format] :: ProcessorError -> Format
[processorError_columnError] :: ProcessorError -> ParserError
CellParserError :: ColumnNum -> Oid -> Format -> RowNum -> Value -> Text -> ProcessorError
[processorError_column] :: ProcessorError -> ColumnNum
[processorError_type] :: ProcessorError -> Oid
[processorError_format] :: ProcessorError -> Format
[processorError_row] :: ProcessorError -> RowNum
[processorError_value] :: ProcessorError -> Value
[processorError_cellError] :: ProcessorError -> Text
NotEnoughColumns :: ColumnNum -> ColumnNum -> ProcessorError
[processorError_wantedColumns] :: ProcessorError -> ColumnNum
[processorError_haveColumns] :: ProcessorError -> ColumnNum
MissingNamedColumn :: ByteString -> ProcessorError
[processorError_wantedColumnName] :: ProcessorError -> ByteString
type ProcessorErrors = NonEmpty ProcessorError
-- | Error that occurs when validating the result
data ResultError
BadResultStatus :: ByteString -> ResultError
[resultError_status] :: ResultError -> ByteString
NoRows :: ResultError
MultipleRows :: RowNum -> ResultError
[resultError_numRows] :: ResultError -> RowNum
FailedToParseAffectedRows :: Text -> ResultError
[resultError_message] :: ResultError -> Text
type ResultErrors = NonEmpty ResultError
-- | Error that occurs when parsing a column
data ParserError
UnsupportedFormat :: Format -> ParserError
UnsupportedOid :: Oid -> ParserError
type ParserErrors = NonEmpty ParserError
data Format
Text :: Format
Binary :: Format
data Oid
-- | Numberic column identifier
data ColumnNum
-- | Numberic row identifier
data RowNum
-- | Value
data Value
Null :: Value
Value :: ByteString -> Value
-- | The raw cell value
data RawValue
RawValue :: Oid -> Format -> Value -> RawValue
[rawValue_type] :: RawValue -> Oid
[rawValue_format] :: RawValue -> Format
[rawValue_value] :: RawValue -> Value