-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | PostgreSQL interface with compile-time SQL type checking, optional HDBC backend
--   
--   Automatically type-check SQL statements at compile time. Uses Template
--   Haskell and the raw PostgreSQL protocol to describe SQL statements at
--   compile time and provide appropriate type marshalling for both
--   parameters and results. Allows not only syntax verification of your
--   SQL but also full type safety between your SQL and Haskell. Supports
--   many built-in PostgreSQL types already, including arrays and ranges,
--   and can be easily extended in user code to support any other types.
--   
--   Also includes an optional HDBC backend that, since it uses the raw
--   PostgreSQL protocol, may be more efficient than the normal libpq
--   backend in some cases (though provides no more type safety than
--   HDBC-postgresql when used without templates).
--   
--   Originally based on Chris Forno's templatepg library.
@package postgresql-typed
@version 0.5.1


-- | Classes to support type inference, value encoding/decoding, and
--   instances to support built-in PostgreSQL types.
module Database.PostgreSQL.Typed.Types
type OID = Word32

-- | A value passed to or from PostgreSQL in raw format.
data PGValue
PGNullValue :: PGValue

-- | The standard text encoding format (also used for unknown formats)
PGTextValue :: PGTextValue -> PGValue
[pgTextValue] :: PGValue -> PGTextValue

-- | Special binary-encoded data. Not supported in all cases.
PGBinaryValue :: PGBinaryValue -> PGValue
[pgBinaryValue] :: PGValue -> PGBinaryValue

-- | A list of (nullable) data values, e.g. a single row or query
--   parameters.
type PGValues = [PGValue]

-- | A proxy type for PostgreSQL types. The type argument should be an
--   (internal) name of a database type, as per <tt>format_type(OID)</tt>
--   (usually the same as <tt>\dT+</tt>). When the type's namespace
--   (schema) is not in <tt>search_path</tt>, this will be explicitly
--   qualified, so you should be sure to have a consistent
--   <tt>search_path</tt> for all database connections. The underlying
--   <a>Symbol</a> should be considered a lifted <a>PGName</a>.
data PGTypeID (t :: Symbol)
PGTypeProxy :: PGTypeID

-- | Parameters that affect how marshalling happens. Currenly we force all
--   other relevant parameters at connect time. Nothing values represent
--   unknown.
data PGTypeEnv
PGTypeEnv :: Maybe Bool -> PGTypeEnv

-- | If <tt>integer_datetimes</tt> is <tt>on</tt>; only relevant for binary
--   encoding.
[pgIntegerDatetimes] :: PGTypeEnv -> Maybe Bool
unknownPGTypeEnv :: PGTypeEnv

-- | A PostgreSQL literal identifier, generally corresponding to the "name"
--   type (63-byte strings), but as it would be entered in a query, so may
--   include double-quoting for special characters or schema-qualification.
newtype PGName
PGName :: [Word8] -> PGName

-- | Raw bytes of the identifier (should really be a <a>ByteString</a>, but
--   we need a working <a>Data</a> instance for annotations).
[pgNameBytes] :: PGName -> [Word8]

-- | The literal identifier as used in a query.
pgNameBS :: PGName -> ByteString

-- | Reverses the <a>IsString</a> instantce.
pgNameString :: PGName -> String

-- | Generic class of composite (row or record) types.
newtype PGRecord
PGRecord :: [Maybe PGTextValue] -> PGRecord

-- | A valid PostgreSQL type, its metadata, and corresponding Haskell
--   representation. For conversion the other way (from Haskell type to
--   PostgreSQL), see <a>PGRep</a>. Unfortunately any instances of this
--   will be orphans.
class (KnownSymbol t, PGParameter t (PGVal t), PGColumn t (PGVal t)) => PGType t where type PGVal t :: * pgTypeName = fromString . symbolVal pgBinaryColumn _ _ = False where {
    type family PGVal t :: *;
}

-- | The string name of this type: specialized version of <a>symbolVal</a>.
pgTypeName :: PGType t => PGTypeID t -> PGName

-- | Does this type support binary decoding? If so, <a>pgDecodeBinary</a>
--   must be implemented for every <a>PGColumn</a> instance of this type.
pgBinaryColumn :: PGType t => PGTypeEnv -> PGTypeID t -> Bool

-- | A <tt>PGParameter t a</tt> instance describes how to encode a
--   PostgreSQL type <tt>t</tt> from <tt>a</tt>.
class PGType t => PGParameter t a where pgLiteral t = pgQuote . pgEncode t pgEncodeValue _ t = PGTextValue . pgEncode t

-- | Encode a value to a PostgreSQL text representation.
pgEncode :: PGParameter t a => PGTypeID t -> a -> PGTextValue

-- | Encode a value to a (quoted) literal value for use in SQL statements.
--   Defaults to a quoted version of <a>pgEncode</a>
pgLiteral :: PGParameter t a => PGTypeID t -> a -> ByteString

-- | Encode a value to a PostgreSQL representation. Defaults to the text
--   representation by pgEncode
pgEncodeValue :: PGParameter t a => PGTypeEnv -> PGTypeID t -> a -> PGValue

-- | A <tt>PGColumn t a</tt> instance describes how te decode a PostgreSQL
--   type <tt>t</tt> to <tt>a</tt>.
class PGType t => PGColumn t a where pgDecodeBinary _ t _ = error $ "pgDecodeBinary " ++ show (pgTypeName t) ++ ": not supported" pgDecodeValue _ t (PGTextValue v) = pgDecode t v pgDecodeValue e t (PGBinaryValue v) = pgDecodeBinary e t v pgDecodeValue _ t PGNullValue = error $ "NULL in " ++ show (pgTypeName t) ++ " column (use Maybe or COALESCE)"

-- | Decode the PostgreSQL text representation into a value.
pgDecode :: PGColumn t a => PGTypeID t -> PGTextValue -> a

-- | Decode the PostgreSQL binary representation into a value. Only needs
--   to be implemented if <a>pgBinaryColumn</a> is true.
pgDecodeBinary :: PGColumn t a => PGTypeEnv -> PGTypeID t -> PGBinaryValue -> a
pgDecodeValue :: PGColumn t a => PGTypeEnv -> PGTypeID t -> PGValue -> a
class PGType t => PGStringType t
class PGType t => PGRecordType t

-- | Final parameter encoding function used when a (nullable) parameter is
--   passed to a prepared query.
pgEncodeParameter :: PGParameter t a => PGTypeEnv -> PGTypeID t -> a -> PGValue

-- | Final parameter escaping function used when a (nullable) parameter is
--   passed to be substituted into a simple query.
pgEscapeParameter :: PGParameter t a => PGTypeEnv -> PGTypeID t -> a -> ByteString

-- | Final column decoding function used for a nullable result value.
pgDecodeColumn :: PGColumn t (Maybe a) => PGTypeEnv -> PGTypeID t -> PGValue -> Maybe a

-- | Final column decoding function used for a non-nullable result value.
pgDecodeColumnNotNull :: PGColumn t a => PGTypeEnv -> PGTypeID t -> PGValue -> a

-- | Produce a SQL string literal by wrapping (and escaping) a string with
--   single quotes.
pgQuote :: ByteString -> ByteString

-- | Double-quote a value if it's "", "null", or contains any whitespace,
--   '"', '\', or the characters given in the first argument. Checking all
--   these things may not be worth it. We could just double-quote
--   everything.
pgDQuote :: [Char] -> ByteString -> Builder

-- | Parse double-quoted values ala <a>pgDQuote</a>.
parsePGDQuote :: Bool -> [Char] -> (ByteString -> Bool) -> Parser (Maybe ByteString)

-- | Shorthand for <tt><a>toStrict</a> . <a>toLazyByteString</a></tt>
buildPGValue :: Builder -> ByteString
instance Data.Data.Data Database.PostgreSQL.Typed.Types.PGName
instance GHC.Classes.Ord Database.PostgreSQL.Typed.Types.PGName
instance GHC.Classes.Eq Database.PostgreSQL.Typed.Types.PGName
instance GHC.Show.Show Database.PostgreSQL.Typed.Types.PGTypeEnv
instance GHC.Classes.Eq Database.PostgreSQL.Typed.Types.PGValue
instance GHC.Show.Show Database.PostgreSQL.Typed.Types.PGValue
instance Data.String.IsString Database.PostgreSQL.Typed.Types.PGName
instance GHC.Show.Show Database.PostgreSQL.Typed.Types.PGName
instance Database.PostgreSQL.Typed.Types.PGParameter t a => Database.PostgreSQL.Typed.Types.PGParameter t (GHC.Base.Maybe a)
instance Database.PostgreSQL.Typed.Types.PGColumn t a => Database.PostgreSQL.Typed.Types.PGColumn t (GHC.Base.Maybe a)
instance Database.PostgreSQL.Typed.Types.PGType "any"
instance Database.PostgreSQL.Typed.Types.PGType t => Database.PostgreSQL.Typed.Types.PGColumn t Database.PostgreSQL.Typed.Types.PGValue
instance Database.PostgreSQL.Typed.Types.PGParameter "any" Database.PostgreSQL.Typed.Types.PGValue
instance Database.PostgreSQL.Typed.Types.PGType "void"
instance Database.PostgreSQL.Typed.Types.PGParameter "void" ()
instance Database.PostgreSQL.Typed.Types.PGColumn "void" ()
instance Database.PostgreSQL.Typed.Types.PGType "boolean"
instance Database.PostgreSQL.Typed.Types.PGParameter "boolean" GHC.Types.Bool
instance Database.PostgreSQL.Typed.Types.PGColumn "boolean" GHC.Types.Bool
instance Database.PostgreSQL.Typed.Types.PGType "oid"
instance Database.PostgreSQL.Typed.Types.PGParameter "oid" Database.PostgreSQL.Typed.Types.OID
instance Database.PostgreSQL.Typed.Types.PGColumn "oid" Database.PostgreSQL.Typed.Types.OID
instance Database.PostgreSQL.Typed.Types.PGType "smallint"
instance Database.PostgreSQL.Typed.Types.PGParameter "smallint" GHC.Int.Int16
instance Database.PostgreSQL.Typed.Types.PGColumn "smallint" GHC.Int.Int16
instance Database.PostgreSQL.Typed.Types.PGType "integer"
instance Database.PostgreSQL.Typed.Types.PGParameter "integer" GHC.Int.Int32
instance Database.PostgreSQL.Typed.Types.PGColumn "integer" GHC.Int.Int32
instance Database.PostgreSQL.Typed.Types.PGType "bigint"
instance Database.PostgreSQL.Typed.Types.PGParameter "bigint" GHC.Int.Int64
instance Database.PostgreSQL.Typed.Types.PGColumn "bigint" GHC.Int.Int64
instance Database.PostgreSQL.Typed.Types.PGType "real"
instance Database.PostgreSQL.Typed.Types.PGParameter "real" GHC.Types.Float
instance Database.PostgreSQL.Typed.Types.PGColumn "real" GHC.Types.Float
instance Database.PostgreSQL.Typed.Types.PGColumn "real" GHC.Types.Double
instance Database.PostgreSQL.Typed.Types.PGType "double precision"
instance Database.PostgreSQL.Typed.Types.PGParameter "double precision" GHC.Types.Double
instance Database.PostgreSQL.Typed.Types.PGParameter "double precision" GHC.Types.Float
instance Database.PostgreSQL.Typed.Types.PGColumn "double precision" GHC.Types.Double
instance Database.PostgreSQL.Typed.Types.PGType "\"char\""
instance Database.PostgreSQL.Typed.Types.PGParameter "\"char\"" GHC.Word.Word8
instance Database.PostgreSQL.Typed.Types.PGColumn "\"char\"" GHC.Word.Word8
instance Database.PostgreSQL.Typed.Types.PGParameter "\"char\"" GHC.Types.Char
instance Database.PostgreSQL.Typed.Types.PGColumn "\"char\"" GHC.Types.Char
instance Database.PostgreSQL.Typed.Types.PGStringType t => Database.PostgreSQL.Typed.Types.PGParameter t GHC.Base.String
instance Database.PostgreSQL.Typed.Types.PGStringType t => Database.PostgreSQL.Typed.Types.PGColumn t GHC.Base.String
instance Database.PostgreSQL.Typed.Types.PGStringType t => Database.PostgreSQL.Typed.Types.PGParameter t Data.ByteString.Internal.ByteString
instance Database.PostgreSQL.Typed.Types.PGStringType t => Database.PostgreSQL.Typed.Types.PGColumn t Data.ByteString.Internal.ByteString
instance Database.PostgreSQL.Typed.Types.PGStringType t => Database.PostgreSQL.Typed.Types.PGParameter t Database.PostgreSQL.Typed.Types.PGName
instance Database.PostgreSQL.Typed.Types.PGStringType t => Database.PostgreSQL.Typed.Types.PGColumn t Database.PostgreSQL.Typed.Types.PGName
instance Database.PostgreSQL.Typed.Types.PGStringType t => Database.PostgreSQL.Typed.Types.PGParameter t Data.ByteString.Lazy.Internal.ByteString
instance Database.PostgreSQL.Typed.Types.PGStringType t => Database.PostgreSQL.Typed.Types.PGColumn t Data.ByteString.Lazy.Internal.ByteString
instance Database.PostgreSQL.Typed.Types.PGStringType t => Database.PostgreSQL.Typed.Types.PGParameter t Data.Text.Internal.Text
instance Database.PostgreSQL.Typed.Types.PGStringType t => Database.PostgreSQL.Typed.Types.PGColumn t Data.Text.Internal.Text
instance Database.PostgreSQL.Typed.Types.PGStringType t => Database.PostgreSQL.Typed.Types.PGParameter t Data.Text.Internal.Lazy.Text
instance Database.PostgreSQL.Typed.Types.PGStringType t => Database.PostgreSQL.Typed.Types.PGColumn t Data.Text.Internal.Lazy.Text
instance Database.PostgreSQL.Typed.Types.PGType "text"
instance Database.PostgreSQL.Typed.Types.PGType "character varying"
instance Database.PostgreSQL.Typed.Types.PGType "name"
instance Database.PostgreSQL.Typed.Types.PGType "bpchar"
instance Database.PostgreSQL.Typed.Types.PGStringType "text"
instance Database.PostgreSQL.Typed.Types.PGStringType "character varying"
instance Database.PostgreSQL.Typed.Types.PGStringType "name"
instance Database.PostgreSQL.Typed.Types.PGStringType "bpchar"
instance Database.PostgreSQL.Typed.Types.PGType "bytea"
instance Database.PostgreSQL.Typed.Types.PGParameter "bytea" Data.ByteString.Lazy.Internal.ByteString
instance Database.PostgreSQL.Typed.Types.PGColumn "bytea" Data.ByteString.Lazy.Internal.ByteString
instance Database.PostgreSQL.Typed.Types.PGParameter "bytea" Data.ByteString.Internal.ByteString
instance Database.PostgreSQL.Typed.Types.PGColumn "bytea" Data.ByteString.Internal.ByteString
instance Database.PostgreSQL.Typed.Types.PGType "date"
instance Database.PostgreSQL.Typed.Types.PGParameter "date" Data.Time.Calendar.Days.Day
instance Database.PostgreSQL.Typed.Types.PGColumn "date" Data.Time.Calendar.Days.Day
instance Database.PostgreSQL.Typed.Types.PGType "time without time zone"
instance Database.PostgreSQL.Typed.Types.PGParameter "time without time zone" Data.Time.LocalTime.TimeOfDay.TimeOfDay
instance Database.PostgreSQL.Typed.Types.PGColumn "time without time zone" Data.Time.LocalTime.TimeOfDay.TimeOfDay
instance Database.PostgreSQL.Typed.Types.PGType "time with time zone"
instance Database.PostgreSQL.Typed.Types.PGParameter "time with time zone" (Data.Time.LocalTime.TimeOfDay.TimeOfDay, Data.Time.LocalTime.TimeZone.TimeZone)
instance Database.PostgreSQL.Typed.Types.PGColumn "time with time zone" (Data.Time.LocalTime.TimeOfDay.TimeOfDay, Data.Time.LocalTime.TimeZone.TimeZone)
instance Database.PostgreSQL.Typed.Types.PGType "timestamp without time zone"
instance Database.PostgreSQL.Typed.Types.PGParameter "timestamp without time zone" Data.Time.LocalTime.LocalTime.LocalTime
instance Database.PostgreSQL.Typed.Types.PGColumn "timestamp without time zone" Data.Time.LocalTime.LocalTime.LocalTime
instance Database.PostgreSQL.Typed.Types.PGType "timestamp with time zone"
instance Database.PostgreSQL.Typed.Types.PGParameter "timestamp with time zone" Data.Time.Clock.UTC.UTCTime
instance Database.PostgreSQL.Typed.Types.PGColumn "timestamp with time zone" Data.Time.Clock.UTC.UTCTime
instance Database.PostgreSQL.Typed.Types.PGType "interval"
instance Database.PostgreSQL.Typed.Types.PGParameter "interval" Data.Time.Clock.Scale.DiffTime
instance Database.PostgreSQL.Typed.Types.PGColumn "interval" Data.Time.Clock.Scale.DiffTime
instance Database.PostgreSQL.Typed.Types.PGType "numeric"
instance Database.PostgreSQL.Typed.Types.PGParameter "numeric" GHC.Real.Rational
instance Database.PostgreSQL.Typed.Types.PGColumn "numeric" GHC.Real.Rational
instance Database.PostgreSQL.Typed.Types.PGParameter "numeric" Data.Scientific.Scientific
instance Database.PostgreSQL.Typed.Types.PGColumn "numeric" Data.Scientific.Scientific
instance Database.PostgreSQL.Typed.Types.PGType "uuid"
instance Database.PostgreSQL.Typed.Types.PGParameter "uuid" Data.UUID.Types.Internal.UUID
instance Database.PostgreSQL.Typed.Types.PGColumn "uuid" Data.UUID.Types.Internal.UUID
instance Database.PostgreSQL.Typed.Types.PGRecordType t => Database.PostgreSQL.Typed.Types.PGParameter t Database.PostgreSQL.Typed.Types.PGRecord
instance Database.PostgreSQL.Typed.Types.PGRecordType t => Database.PostgreSQL.Typed.Types.PGColumn t Database.PostgreSQL.Typed.Types.PGRecord
instance Database.PostgreSQL.Typed.Types.PGType "record"
instance Database.PostgreSQL.Typed.Types.PGRecordType "record"
instance Database.PostgreSQL.Typed.Types.PGType "json"
instance Database.PostgreSQL.Typed.Types.PGParameter "json" Data.Aeson.Types.Internal.Value
instance Database.PostgreSQL.Typed.Types.PGColumn "json" Data.Aeson.Types.Internal.Value
instance Database.PostgreSQL.Typed.Types.PGType "jsonb"
instance Database.PostgreSQL.Typed.Types.PGParameter "jsonb" Data.Aeson.Types.Internal.Value
instance Database.PostgreSQL.Typed.Types.PGColumn "jsonb" Data.Aeson.Types.Internal.Value


-- | Parsing of SQL statements to safely identify placeholders. Supports
--   both dollar-placeholders and question marks for HDBC.
module Database.PostgreSQL.Typed.SQLToken

-- | A parsed SQL token.
data SQLToken

-- | Raw (non-markup) SQL string
SQLToken :: String -> SQLToken

-- | A "$N" parameter placeholder (this is the only non-string-preserving
--   token: "$012" becomes "$12")
SQLParam :: Int -> SQLToken

-- | A "${expr}" expression placeholder
SQLExpr :: String -> SQLToken

-- | A possibly-escaped question-mark: False for "?" or True for "\?"
SQLQMark :: Bool -> SQLToken

-- | Parse a SQL string into a series of tokens. The <a>showList</a>
--   implementation for <a>SQLToken</a> inverts this sequence back to a SQL
--   string.
sqlTokens :: String -> [SQLToken]
instance GHC.Classes.Eq Database.PostgreSQL.Typed.SQLToken.SQLToken
instance GHC.Show.Show Database.PostgreSQL.Typed.SQLToken.SQLToken
instance Data.String.IsString Database.PostgreSQL.Typed.SQLToken.SQLToken


-- | Representaion of PostgreSQL's range type. There are a number of
--   existing range data types, but PostgreSQL's is rather particular. This
--   tries to provide a one-to-one mapping.
module Database.PostgreSQL.Typed.Range

-- | A end-point for a range, which may be nothing (infinity, NULL in
--   PostgreSQL), open (inclusive), or closed (exclusive)
data Bound a

-- | Equivalent to <tt>Bounded False ±Infinity</tt>
Unbounded :: Bound a
Bounded :: Bool -> a -> Bound a

-- | <tt>True</tt> if the range includes this bound
[_boundClosed] :: Bound a -> Bool
[_bound] :: Bound a -> a
newtype LowerBound a
Lower :: Bound a -> LowerBound a
[boundLower] :: LowerBound a -> Bound a

-- | Takes into account open vs. closed (but does not understand equivalent
--   discrete bounds)

-- | The constraint is only necessary for <tt>maxBound</tt>, unfortunately
newtype UpperBound a
Upper :: Bound a -> UpperBound a
[boundUpper] :: UpperBound a -> Bound a

-- | Takes into account open vs. closed (but does not understand equivalent
--   discrete bounds)

-- | The constraint is only necessary for <tt>minBound</tt>, unfortunately
compareBounds :: Ord a => LowerBound a -> UpperBound a -> Bound Bool
data Range a
Empty :: Range a
Range :: LowerBound a -> UpperBound a -> Range a
[lower] :: Range a -> LowerBound a
[upper] :: Range a -> UpperBound a
bound :: Bound a -> Maybe a

-- | Unbounded endpoints are always open.
boundClosed :: Bound a -> Bool

-- | Construct from parts: <tt>makeBound (boundClosed b) (bound b) ==
--   b</tt>
makeBound :: Bool -> Maybe a -> Bound a

-- | Empty ranges treated as <a>Unbounded</a>
lowerBound :: Range a -> Bound a

-- | Empty ranges treated as <a>Unbounded</a>
upperBound :: Range a -> Bound a

-- | Equivalent to <tt>boundClosed . lowerBound</tt>
lowerClosed :: Range a -> Bool

-- | Equivalent to <tt>boundClosed . upperBound</tt>
upperClosed :: Range a -> Bool
empty :: Range a
isEmpty :: Ord a => Range a -> Bool
full :: Range a
isFull :: Range a -> Bool

-- | Create a point range <tt>[x,x]</tt>
point :: a -> Range a

-- | Extract a point: <tt>getPoint (point x) == Just x</tt>
getPoint :: Eq a => Range a -> Maybe a
range :: Ord a => Bound a -> Bound a -> Range a
normal :: Ord a => Maybe a -> Maybe a -> Range a
bounded :: Ord a => a -> a -> Range a
normalize :: Ord a => Range a -> Range a

-- | <a>normalize</a> for discrete (non-continuous) range types, using the
--   <a>Enum</a> instance
normalize' :: (Ord a, Enum a) => Range a -> Range a

-- | Contains range
(@>) :: Ord a => Range a -> Range a -> Bool

-- | Contains range
(<@) :: Ord a => Range a -> Range a -> Bool

-- | Contains element
(@>.) :: Ord a => Range a -> a -> Bool
overlaps :: Ord a => Range a -> Range a -> Bool
intersect :: Ord a => Range a -> Range a -> Range a

-- | Class indicating that the first PostgreSQL type is a range of the
--   second. This implies <a>PGParameter</a> and <a>PGColumn</a> instances
--   that will work for any type.
class (PGType t, PGType (PGSubType t)) => PGRangeType t where type PGSubType t :: Symbol pgRangeElementType PGTypeProxy = PGTypeProxy where {
    type family PGSubType t :: Symbol;
}
pgRangeElementType :: PGRangeType t => PGTypeID t -> PGTypeID (PGSubType t)
instance GHC.Classes.Ord a => GHC.Classes.Ord (Database.PostgreSQL.Typed.Range.Range a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Database.PostgreSQL.Typed.Range.Range a)
instance GHC.Base.Functor Database.PostgreSQL.Typed.Range.UpperBound
instance GHC.Classes.Eq a => GHC.Classes.Eq (Database.PostgreSQL.Typed.Range.UpperBound a)
instance GHC.Base.Functor Database.PostgreSQL.Typed.Range.LowerBound
instance GHC.Classes.Eq a => GHC.Classes.Eq (Database.PostgreSQL.Typed.Range.LowerBound a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Database.PostgreSQL.Typed.Range.Bound a)
instance GHC.Base.Functor Database.PostgreSQL.Typed.Range.Bound
instance GHC.Classes.Ord a => GHC.Classes.Ord (Database.PostgreSQL.Typed.Range.LowerBound a)
instance GHC.Enum.Bounded a => GHC.Enum.Bounded (Database.PostgreSQL.Typed.Range.LowerBound a)
instance GHC.Classes.Ord a => GHC.Classes.Ord (Database.PostgreSQL.Typed.Range.UpperBound a)
instance GHC.Enum.Bounded a => GHC.Enum.Bounded (Database.PostgreSQL.Typed.Range.UpperBound a)
instance GHC.Base.Functor Database.PostgreSQL.Typed.Range.Range
instance GHC.Show.Show a => GHC.Show.Show (Database.PostgreSQL.Typed.Range.Range a)
instance GHC.Classes.Ord a => GHC.Base.Monoid (Database.PostgreSQL.Typed.Range.Range a)
instance (Database.PostgreSQL.Typed.Range.PGRangeType t, Database.PostgreSQL.Typed.Types.PGParameter (Database.PostgreSQL.Typed.Range.PGSubType t) a) => Database.PostgreSQL.Typed.Types.PGParameter t (Database.PostgreSQL.Typed.Range.Range a)
instance (Database.PostgreSQL.Typed.Range.PGRangeType t, Database.PostgreSQL.Typed.Types.PGColumn (Database.PostgreSQL.Typed.Range.PGSubType t) a) => Database.PostgreSQL.Typed.Types.PGColumn t (Database.PostgreSQL.Typed.Range.Range a)
instance Database.PostgreSQL.Typed.Types.PGType "int4range"
instance Database.PostgreSQL.Typed.Range.PGRangeType "int4range"
instance Database.PostgreSQL.Typed.Types.PGType "numrange"
instance Database.PostgreSQL.Typed.Range.PGRangeType "numrange"
instance Database.PostgreSQL.Typed.Types.PGType "tsrange"
instance Database.PostgreSQL.Typed.Range.PGRangeType "tsrange"
instance Database.PostgreSQL.Typed.Types.PGType "tstzrange"
instance Database.PostgreSQL.Typed.Range.PGRangeType "tstzrange"
instance Database.PostgreSQL.Typed.Types.PGType "daterange"
instance Database.PostgreSQL.Typed.Range.PGRangeType "daterange"
instance Database.PostgreSQL.Typed.Types.PGType "int8range"
instance Database.PostgreSQL.Typed.Range.PGRangeType "int8range"


-- | Representaion of PostgreSQL's inet/cidr types using
--   <a>Network.Socket</a>. We don't (yet) supply PGColumn (parsing)
--   instances.
module Database.PostgreSQL.Typed.Inet
data PGInet
PGInet :: !HostAddress -> !Word8 -> PGInet
[pgInetAddr] :: PGInet -> !HostAddress
[pgInetMask] :: PGInet -> !Word8
PGInet6 :: !HostAddress6 -> !Word8 -> PGInet
[pgInetAddr6] :: PGInet -> !HostAddress6
[pgInetMask] :: PGInet -> !Word8
sockAddrPGInet :: SockAddr -> Maybe PGInet

-- | Convert four bytes to network byte order, using unsafe casting.
--   <a>byteSwap32</a> would be better, but I couldn't find a good way to
--   determine host byte order.
bton32 :: (Word8, Word8, Word8, Word8) -> Word32
instance GHC.Classes.Eq Database.PostgreSQL.Typed.Inet.PGInet
instance GHC.Show.Show Database.PostgreSQL.Typed.Inet.PGInet
instance GHC.Read.Read Database.PostgreSQL.Typed.Inet.PGInet
instance Database.PostgreSQL.Typed.Types.PGType "inet"
instance Database.PostgreSQL.Typed.Types.PGType "cidr"
instance Database.PostgreSQL.Typed.Types.PGParameter "inet" Database.PostgreSQL.Typed.Inet.PGInet
instance Database.PostgreSQL.Typed.Types.PGParameter "cidr" Database.PostgreSQL.Typed.Inet.PGInet
instance Database.PostgreSQL.Typed.Types.PGColumn "inet" Database.PostgreSQL.Typed.Inet.PGInet
instance Database.PostgreSQL.Typed.Types.PGColumn "cidr" Database.PostgreSQL.Typed.Inet.PGInet


-- | PostgreSQL error codes.
module Database.PostgreSQL.Typed.ErrCodes

-- | All known error code names by code.
names :: Map ByteString String

-- | <tt>SUCCESSFUL_COMPLETION</tt>: 00000 (Success)
successful_completion :: ByteString

-- | <tt>WARNING</tt>: 01000 (Warning)
warning :: ByteString

-- | <tt>WARNING_DYNAMIC_RESULT_SETS_RETURNED</tt>: 0100C (Warning)
warning_dynamic_result_sets_returned :: ByteString

-- | <tt>WARNING_IMPLICIT_ZERO_BIT_PADDING</tt>: 01008 (Warning)
warning_implicit_zero_bit_padding :: ByteString

-- | <tt>WARNING_NULL_VALUE_ELIMINATED_IN_SET_FUNCTION</tt>: 01003
--   (Warning)
warning_null_value_eliminated_in_set_function :: ByteString

-- | <tt>WARNING_PRIVILEGE_NOT_GRANTED</tt>: 01007 (Warning)
warning_privilege_not_granted :: ByteString

-- | <tt>WARNING_PRIVILEGE_NOT_REVOKED</tt>: 01006 (Warning)
warning_privilege_not_revoked :: ByteString

-- | <tt>WARNING_STRING_DATA_RIGHT_TRUNCATION</tt>: 01004 (Warning)
warning_string_data_right_truncation :: ByteString

-- | <tt>WARNING_DEPRECATED_FEATURE</tt>: 01P01 (Warning)
warning_deprecated_feature :: ByteString

-- | <tt>NO_DATA</tt>: 02000 (Warning)
no_data :: ByteString

-- | <tt>NO_ADDITIONAL_DYNAMIC_RESULT_SETS_RETURNED</tt>: 02001 (Warning)
no_additional_dynamic_result_sets_returned :: ByteString

-- | <tt>SQL_STATEMENT_NOT_YET_COMPLETE</tt>: 03000 (Error)
sql_statement_not_yet_complete :: ByteString

-- | <tt>CONNECTION_EXCEPTION</tt>: 08000 (Error)
connection_exception :: ByteString

-- | <tt>CONNECTION_DOES_NOT_EXIST</tt>: 08003 (Error)
connection_does_not_exist :: ByteString

-- | <tt>CONNECTION_FAILURE</tt>: 08006 (Error)
connection_failure :: ByteString

-- | <tt>SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION</tt>: 08001 (Error)
sqlclient_unable_to_establish_sqlconnection :: ByteString

-- | <tt>SQLSERVER_REJECTED_ESTABLISHMENT_OF_SQLCONNECTION</tt>: 08004
--   (Error)
sqlserver_rejected_establishment_of_sqlconnection :: ByteString

-- | <tt>TRANSACTION_RESOLUTION_UNKNOWN</tt>: 08007 (Error)
transaction_resolution_unknown :: ByteString

-- | <tt>PROTOCOL_VIOLATION</tt>: 08P01 (Error)
protocol_violation :: ByteString

-- | <tt>TRIGGERED_ACTION_EXCEPTION</tt>: 09000 (Error)
triggered_action_exception :: ByteString

-- | <tt>FEATURE_NOT_SUPPORTED</tt>: 0A000 (Error)
feature_not_supported :: ByteString

-- | <tt>INVALID_TRANSACTION_INITIATION</tt>: 0B000 (Error)
invalid_transaction_initiation :: ByteString

-- | <tt>LOCATOR_EXCEPTION</tt>: 0F000 (Error)
locator_exception :: ByteString

-- | <tt>L_E_INVALID_SPECIFICATION</tt>: 0F001 (Error)
invalid_locator_specification :: ByteString

-- | <tt>INVALID_GRANTOR</tt>: 0L000 (Error)
invalid_grantor :: ByteString

-- | <tt>INVALID_GRANT_OPERATION</tt>: 0LP01 (Error)
invalid_grant_operation :: ByteString

-- | <tt>INVALID_ROLE_SPECIFICATION</tt>: 0P000 (Error)
invalid_role_specification :: ByteString

-- | <tt>DIAGNOSTICS_EXCEPTION</tt>: 0Z000 (Error)
diagnostics_exception :: ByteString

-- | <tt>STACKED_DIAGNOSTICS_ACCESSED_WITHOUT_ACTIVE_HANDLER</tt>: 0Z002
--   (Error)
stacked_diagnostics_accessed_without_active_handler :: ByteString

-- | <tt>CASE_NOT_FOUND</tt>: 20000 (Error)
case_not_found :: ByteString

-- | <tt>CARDINALITY_VIOLATION</tt>: 21000 (Error)
cardinality_violation :: ByteString

-- | <tt>DATA_EXCEPTION</tt>: 22000 (Error)
data_exception :: ByteString

-- | <tt>ARRAY_ELEMENT_ERROR</tt>: 2202E (Error)
_ARRAY_ELEMENT_ERROR :: ByteString

-- | <tt>ARRAY_SUBSCRIPT_ERROR</tt>: 2202E (Error)
array_subscript_error :: ByteString

-- | <tt>CHARACTER_NOT_IN_REPERTOIRE</tt>: 22021 (Error)
character_not_in_repertoire :: ByteString

-- | <tt>DATETIME_FIELD_OVERFLOW</tt>: 22008 (Error)
datetime_field_overflow :: ByteString

-- | <tt>DATETIME_VALUE_OUT_OF_RANGE</tt>: 22008 (Error)
_DATETIME_VALUE_OUT_OF_RANGE :: ByteString

-- | <tt>DIVISION_BY_ZERO</tt>: 22012 (Error)
division_by_zero :: ByteString

-- | <tt>ERROR_IN_ASSIGNMENT</tt>: 22005 (Error)
error_in_assignment :: ByteString

-- | <tt>ESCAPE_CHARACTER_CONFLICT</tt>: 2200B (Error)
escape_character_conflict :: ByteString

-- | <tt>INDICATOR_OVERFLOW</tt>: 22022 (Error)
indicator_overflow :: ByteString

-- | <tt>INTERVAL_FIELD_OVERFLOW</tt>: 22015 (Error)
interval_field_overflow :: ByteString

-- | <tt>INVALID_ARGUMENT_FOR_LOG</tt>: 2201E (Error)
invalid_argument_for_logarithm :: ByteString

-- | <tt>INVALID_ARGUMENT_FOR_NTILE</tt>: 22014 (Error)
invalid_argument_for_ntile_function :: ByteString

-- | <tt>INVALID_ARGUMENT_FOR_NTH_VALUE</tt>: 22016 (Error)
invalid_argument_for_nth_value_function :: ByteString

-- | <tt>INVALID_ARGUMENT_FOR_POWER_FUNCTION</tt>: 2201F (Error)
invalid_argument_for_power_function :: ByteString

-- | <tt>INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION</tt>: 2201G (Error)
invalid_argument_for_width_bucket_function :: ByteString

-- | <tt>INVALID_CHARACTER_VALUE_FOR_CAST</tt>: 22018 (Error)
invalid_character_value_for_cast :: ByteString

-- | <tt>INVALID_DATETIME_FORMAT</tt>: 22007 (Error)
invalid_datetime_format :: ByteString

-- | <tt>INVALID_ESCAPE_CHARACTER</tt>: 22019 (Error)
invalid_escape_character :: ByteString

-- | <tt>INVALID_ESCAPE_OCTET</tt>: 2200D (Error)
invalid_escape_octet :: ByteString

-- | <tt>INVALID_ESCAPE_SEQUENCE</tt>: 22025 (Error)
invalid_escape_sequence :: ByteString

-- | <tt>NONSTANDARD_USE_OF_ESCAPE_CHARACTER</tt>: 22P06 (Error)
nonstandard_use_of_escape_character :: ByteString

-- | <tt>INVALID_INDICATOR_PARAMETER_VALUE</tt>: 22010 (Error)
invalid_indicator_parameter_value :: ByteString

-- | <tt>INVALID_PARAMETER_VALUE</tt>: 22023 (Error)
invalid_parameter_value :: ByteString

-- | <tt>INVALID_REGULAR_EXPRESSION</tt>: 2201B (Error)
invalid_regular_expression :: ByteString

-- | <tt>INVALID_ROW_COUNT_IN_LIMIT_CLAUSE</tt>: 2201W (Error)
invalid_row_count_in_limit_clause :: ByteString

-- | <tt>INVALID_ROW_COUNT_IN_RESULT_OFFSET_CLAUSE</tt>: 2201X (Error)
invalid_row_count_in_result_offset_clause :: ByteString

-- | <tt>INVALID_TABLESAMPLE_ARGUMENT</tt>: 2202H (Error)
invalid_tablesample_argument :: ByteString

-- | <tt>INVALID_TABLESAMPLE_REPEAT</tt>: 2202G (Error)
invalid_tablesample_repeat :: ByteString

-- | <tt>INVALID_TIME_ZONE_DISPLACEMENT_VALUE</tt>: 22009 (Error)
invalid_time_zone_displacement_value :: ByteString

-- | <tt>INVALID_USE_OF_ESCAPE_CHARACTER</tt>: 2200C (Error)
invalid_use_of_escape_character :: ByteString

-- | <tt>MOST_SPECIFIC_TYPE_MISMATCH</tt>: 2200G (Error)
most_specific_type_mismatch :: ByteString

-- | <tt>NULL_VALUE_NOT_ALLOWED</tt>: 22004 (Error)
null_value_not_allowed :: ByteString

-- | <tt>NULL_VALUE_NO_INDICATOR_PARAMETER</tt>: 22002 (Error)
null_value_no_indicator_parameter :: ByteString

-- | <tt>NUMERIC_VALUE_OUT_OF_RANGE</tt>: 22003 (Error)
numeric_value_out_of_range :: ByteString

-- | <tt>STRING_DATA_LENGTH_MISMATCH</tt>: 22026 (Error)
string_data_length_mismatch :: ByteString

-- | <tt>STRING_DATA_RIGHT_TRUNCATION</tt>: 22001 (Error)
string_data_right_truncation :: ByteString

-- | <tt>SUBSTRING_ERROR</tt>: 22011 (Error)
substring_error :: ByteString

-- | <tt>TRIM_ERROR</tt>: 22027 (Error)
trim_error :: ByteString

-- | <tt>UNTERMINATED_C_STRING</tt>: 22024 (Error)
unterminated_c_string :: ByteString

-- | <tt>ZERO_LENGTH_CHARACTER_STRING</tt>: 2200F (Error)
zero_length_character_string :: ByteString

-- | <tt>FLOATING_POINT_EXCEPTION</tt>: 22P01 (Error)
floating_point_exception :: ByteString

-- | <tt>INVALID_TEXT_REPRESENTATION</tt>: 22P02 (Error)
invalid_text_representation :: ByteString

-- | <tt>INVALID_BINARY_REPRESENTATION</tt>: 22P03 (Error)
invalid_binary_representation :: ByteString

-- | <tt>BAD_COPY_FILE_FORMAT</tt>: 22P04 (Error)
bad_copy_file_format :: ByteString

-- | <tt>UNTRANSLATABLE_CHARACTER</tt>: 22P05 (Error)
untranslatable_character :: ByteString

-- | <tt>NOT_AN_XML_DOCUMENT</tt>: 2200L (Error)
not_an_xml_document :: ByteString

-- | <tt>INVALID_XML_DOCUMENT</tt>: 2200M (Error)
invalid_xml_document :: ByteString

-- | <tt>INVALID_XML_CONTENT</tt>: 2200N (Error)
invalid_xml_content :: ByteString

-- | <tt>INVALID_XML_COMMENT</tt>: 2200S (Error)
invalid_xml_comment :: ByteString

-- | <tt>INVALID_XML_PROCESSING_INSTRUCTION</tt>: 2200T (Error)
invalid_xml_processing_instruction :: ByteString

-- | <tt>INTEGRITY_CONSTRAINT_VIOLATION</tt>: 23000 (Error)
integrity_constraint_violation :: ByteString

-- | <tt>RESTRICT_VIOLATION</tt>: 23001 (Error)
restrict_violation :: ByteString

-- | <tt>NOT_NULL_VIOLATION</tt>: 23502 (Error)
not_null_violation :: ByteString

-- | <tt>FOREIGN_KEY_VIOLATION</tt>: 23503 (Error)
foreign_key_violation :: ByteString

-- | <tt>UNIQUE_VIOLATION</tt>: 23505 (Error)
unique_violation :: ByteString

-- | <tt>CHECK_VIOLATION</tt>: 23514 (Error)
check_violation :: ByteString

-- | <tt>EXCLUSION_VIOLATION</tt>: 23P01 (Error)
exclusion_violation :: ByteString

-- | <tt>INVALID_CURSOR_STATE</tt>: 24000 (Error)
invalid_cursor_state :: ByteString

-- | <tt>INVALID_TRANSACTION_STATE</tt>: 25000 (Error)
invalid_transaction_state :: ByteString

-- | <tt>ACTIVE_SQL_TRANSACTION</tt>: 25001 (Error)
active_sql_transaction :: ByteString

-- | <tt>BRANCH_TRANSACTION_ALREADY_ACTIVE</tt>: 25002 (Error)
branch_transaction_already_active :: ByteString

-- | <tt>HELD_CURSOR_REQUIRES_SAME_ISOLATION_LEVEL</tt>: 25008 (Error)
held_cursor_requires_same_isolation_level :: ByteString

-- | <tt>INAPPROPRIATE_ACCESS_MODE_FOR_BRANCH_TRANSACTION</tt>: 25003
--   (Error)
inappropriate_access_mode_for_branch_transaction :: ByteString

-- | <tt>INAPPROPRIATE_ISOLATION_LEVEL_FOR_BRANCH_TRANSACTION</tt>: 25004
--   (Error)
inappropriate_isolation_level_for_branch_transaction :: ByteString

-- | <tt>NO_ACTIVE_SQL_TRANSACTION_FOR_BRANCH_TRANSACTION</tt>: 25005
--   (Error)
no_active_sql_transaction_for_branch_transaction :: ByteString

-- | <tt>READ_ONLY_SQL_TRANSACTION</tt>: 25006 (Error)
read_only_sql_transaction :: ByteString

-- | <tt>SCHEMA_AND_DATA_STATEMENT_MIXING_NOT_SUPPORTED</tt>: 25007 (Error)
schema_and_data_statement_mixing_not_supported :: ByteString

-- | <tt>NO_ACTIVE_SQL_TRANSACTION</tt>: 25P01 (Error)
no_active_sql_transaction :: ByteString

-- | <tt>IN_FAILED_SQL_TRANSACTION</tt>: 25P02 (Error)
in_failed_sql_transaction :: ByteString

-- | <tt>INVALID_SQL_STATEMENT_NAME</tt>: 26000 (Error)
invalid_sql_statement_name :: ByteString

-- | <tt>TRIGGERED_DATA_CHANGE_VIOLATION</tt>: 27000 (Error)
triggered_data_change_violation :: ByteString

-- | <tt>INVALID_AUTHORIZATION_SPECIFICATION</tt>: 28000 (Error)
invalid_authorization_specification :: ByteString

-- | <tt>INVALID_PASSWORD</tt>: 28P01 (Error)
invalid_password :: ByteString

-- | <tt>DEPENDENT_PRIVILEGE_DESCRIPTORS_STILL_EXIST</tt>: 2B000 (Error)
dependent_privilege_descriptors_still_exist :: ByteString

-- | <tt>DEPENDENT_OBJECTS_STILL_EXIST</tt>: 2BP01 (Error)
dependent_objects_still_exist :: ByteString

-- | <tt>INVALID_TRANSACTION_TERMINATION</tt>: 2D000 (Error)
invalid_transaction_termination :: ByteString

-- | <tt>SQL_ROUTINE_EXCEPTION</tt>: 2F000 (Error)
sql_routine_exception :: ByteString

-- | <tt>S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT</tt>: 2F005 (Error)
s_r_e_function_executed_no_return_statement :: ByteString

-- | <tt>S_R_E_MODIFYING_SQL_DATA_NOT_PERMITTED</tt>: 2F002 (Error)
s_r_e_modifying_sql_data_not_permitted :: ByteString

-- | <tt>S_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED</tt>: 2F003 (Error)
s_r_e_prohibited_sql_statement_attempted :: ByteString

-- | <tt>S_R_E_READING_SQL_DATA_NOT_PERMITTED</tt>: 2F004 (Error)
s_r_e_reading_sql_data_not_permitted :: ByteString

-- | <tt>INVALID_CURSOR_NAME</tt>: 34000 (Error)
invalid_cursor_name :: ByteString

-- | <tt>EXTERNAL_ROUTINE_EXCEPTION</tt>: 38000 (Error)
external_routine_exception :: ByteString

-- | <tt>E_R_E_CONTAINING_SQL_NOT_PERMITTED</tt>: 38001 (Error)
e_r_e_containing_sql_not_permitted :: ByteString

-- | <tt>E_R_E_MODIFYING_SQL_DATA_NOT_PERMITTED</tt>: 38002 (Error)
e_r_e_modifying_sql_data_not_permitted :: ByteString

-- | <tt>E_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED</tt>: 38003 (Error)
e_r_e_prohibited_sql_statement_attempted :: ByteString

-- | <tt>E_R_E_READING_SQL_DATA_NOT_PERMITTED</tt>: 38004 (Error)
e_r_e_reading_sql_data_not_permitted :: ByteString

-- | <tt>EXTERNAL_ROUTINE_INVOCATION_EXCEPTION</tt>: 39000 (Error)
external_routine_invocation_exception :: ByteString

-- | <tt>E_R_I_E_INVALID_SQLSTATE_RETURNED</tt>: 39001 (Error)
e_r_i_e_invalid_sqlstate_returned :: ByteString

-- | <tt>E_R_I_E_NULL_VALUE_NOT_ALLOWED</tt>: 39004 (Error)
e_r_i_e_null_value_not_allowed :: ByteString

-- | <tt>E_R_I_E_TRIGGER_PROTOCOL_VIOLATED</tt>: 39P01 (Error)
e_r_i_e_trigger_protocol_violated :: ByteString

-- | <tt>E_R_I_E_SRF_PROTOCOL_VIOLATED</tt>: 39P02 (Error)
e_r_i_e_srf_protocol_violated :: ByteString

-- | <tt>E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED</tt>: 39P03 (Error)
e_r_i_e_event_trigger_protocol_violated :: ByteString

-- | <tt>SAVEPOINT_EXCEPTION</tt>: 3B000 (Error)
savepoint_exception :: ByteString

-- | <tt>S_E_INVALID_SPECIFICATION</tt>: 3B001 (Error)
invalid_savepoint_specification :: ByteString

-- | <tt>INVALID_CATALOG_NAME</tt>: 3D000 (Error)
invalid_catalog_name :: ByteString

-- | <tt>INVALID_SCHEMA_NAME</tt>: 3F000 (Error)
invalid_schema_name :: ByteString

-- | <tt>TRANSACTION_ROLLBACK</tt>: 40000 (Error)
transaction_rollback :: ByteString

-- | <tt>T_R_INTEGRITY_CONSTRAINT_VIOLATION</tt>: 40002 (Error)
transaction_integrity_constraint_violation :: ByteString

-- | <tt>T_R_SERIALIZATION_FAILURE</tt>: 40001 (Error)
serialization_failure :: ByteString

-- | <tt>T_R_STATEMENT_COMPLETION_UNKNOWN</tt>: 40003 (Error)
statement_completion_unknown :: ByteString

-- | <tt>T_R_DEADLOCK_DETECTED</tt>: 40P01 (Error)
deadlock_detected :: ByteString

-- | <tt>SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION</tt>: 42000 (Error)
syntax_error_or_access_rule_violation :: ByteString

-- | <tt>SYNTAX_ERROR</tt>: 42601 (Error)
syntax_error :: ByteString

-- | <tt>INSUFFICIENT_PRIVILEGE</tt>: 42501 (Error)
insufficient_privilege :: ByteString

-- | <tt>CANNOT_COERCE</tt>: 42846 (Error)
cannot_coerce :: ByteString

-- | <tt>GROUPING_ERROR</tt>: 42803 (Error)
grouping_error :: ByteString

-- | <tt>WINDOWING_ERROR</tt>: 42P20 (Error)
windowing_error :: ByteString

-- | <tt>INVALID_RECURSION</tt>: 42P19 (Error)
invalid_recursion :: ByteString

-- | <tt>INVALID_FOREIGN_KEY</tt>: 42830 (Error)
invalid_foreign_key :: ByteString

-- | <tt>INVALID_NAME</tt>: 42602 (Error)
invalid_name :: ByteString

-- | <tt>NAME_TOO_LONG</tt>: 42622 (Error)
name_too_long :: ByteString

-- | <tt>RESERVED_NAME</tt>: 42939 (Error)
reserved_name :: ByteString

-- | <tt>DATATYPE_MISMATCH</tt>: 42804 (Error)
datatype_mismatch :: ByteString

-- | <tt>INDETERMINATE_DATATYPE</tt>: 42P18 (Error)
indeterminate_datatype :: ByteString

-- | <tt>COLLATION_MISMATCH</tt>: 42P21 (Error)
collation_mismatch :: ByteString

-- | <tt>INDETERMINATE_COLLATION</tt>: 42P22 (Error)
indeterminate_collation :: ByteString

-- | <tt>WRONG_OBJECT_TYPE</tt>: 42809 (Error)
wrong_object_type :: ByteString

-- | <tt>UNDEFINED_COLUMN</tt>: 42703 (Error)
undefined_column :: ByteString

-- | <tt>UNDEFINED_CURSOR</tt>: 34000 (Error)
_UNDEFINED_CURSOR :: ByteString

-- | <tt>UNDEFINED_DATABASE</tt>: 3D000 (Error)
_UNDEFINED_DATABASE :: ByteString

-- | <tt>UNDEFINED_FUNCTION</tt>: 42883 (Error)
undefined_function :: ByteString

-- | <tt>UNDEFINED_PSTATEMENT</tt>: 26000 (Error)
_UNDEFINED_PSTATEMENT :: ByteString

-- | <tt>UNDEFINED_SCHEMA</tt>: 3F000 (Error)
_UNDEFINED_SCHEMA :: ByteString

-- | <tt>UNDEFINED_TABLE</tt>: 42P01 (Error)
undefined_table :: ByteString

-- | <tt>UNDEFINED_PARAMETER</tt>: 42P02 (Error)
undefined_parameter :: ByteString

-- | <tt>UNDEFINED_OBJECT</tt>: 42704 (Error)
undefined_object :: ByteString

-- | <tt>DUPLICATE_COLUMN</tt>: 42701 (Error)
duplicate_column :: ByteString

-- | <tt>DUPLICATE_CURSOR</tt>: 42P03 (Error)
duplicate_cursor :: ByteString

-- | <tt>DUPLICATE_DATABASE</tt>: 42P04 (Error)
duplicate_database :: ByteString

-- | <tt>DUPLICATE_FUNCTION</tt>: 42723 (Error)
duplicate_function :: ByteString

-- | <tt>DUPLICATE_PSTATEMENT</tt>: 42P05 (Error)
duplicate_prepared_statement :: ByteString

-- | <tt>DUPLICATE_SCHEMA</tt>: 42P06 (Error)
duplicate_schema :: ByteString

-- | <tt>DUPLICATE_TABLE</tt>: 42P07 (Error)
duplicate_table :: ByteString

-- | <tt>DUPLICATE_ALIAS</tt>: 42712 (Error)
duplicate_alias :: ByteString

-- | <tt>DUPLICATE_OBJECT</tt>: 42710 (Error)
duplicate_object :: ByteString

-- | <tt>AMBIGUOUS_COLUMN</tt>: 42702 (Error)
ambiguous_column :: ByteString

-- | <tt>AMBIGUOUS_FUNCTION</tt>: 42725 (Error)
ambiguous_function :: ByteString

-- | <tt>AMBIGUOUS_PARAMETER</tt>: 42P08 (Error)
ambiguous_parameter :: ByteString

-- | <tt>AMBIGUOUS_ALIAS</tt>: 42P09 (Error)
ambiguous_alias :: ByteString

-- | <tt>INVALID_COLUMN_REFERENCE</tt>: 42P10 (Error)
invalid_column_reference :: ByteString

-- | <tt>INVALID_COLUMN_DEFINITION</tt>: 42611 (Error)
invalid_column_definition :: ByteString

-- | <tt>INVALID_CURSOR_DEFINITION</tt>: 42P11 (Error)
invalid_cursor_definition :: ByteString

-- | <tt>INVALID_DATABASE_DEFINITION</tt>: 42P12 (Error)
invalid_database_definition :: ByteString

-- | <tt>INVALID_FUNCTION_DEFINITION</tt>: 42P13 (Error)
invalid_function_definition :: ByteString

-- | <tt>INVALID_PSTATEMENT_DEFINITION</tt>: 42P14 (Error)
invalid_prepared_statement_definition :: ByteString

-- | <tt>INVALID_SCHEMA_DEFINITION</tt>: 42P15 (Error)
invalid_schema_definition :: ByteString

-- | <tt>INVALID_TABLE_DEFINITION</tt>: 42P16 (Error)
invalid_table_definition :: ByteString

-- | <tt>INVALID_OBJECT_DEFINITION</tt>: 42P17 (Error)
invalid_object_definition :: ByteString

-- | <tt>WITH_CHECK_OPTION_VIOLATION</tt>: 44000 (Error)
with_check_option_violation :: ByteString

-- | <tt>INSUFFICIENT_RESOURCES</tt>: 53000 (Error)
insufficient_resources :: ByteString

-- | <tt>DISK_FULL</tt>: 53100 (Error)
disk_full :: ByteString

-- | <tt>OUT_OF_MEMORY</tt>: 53200 (Error)
out_of_memory :: ByteString

-- | <tt>TOO_MANY_CONNECTIONS</tt>: 53300 (Error)
too_many_connections :: ByteString

-- | <tt>CONFIGURATION_LIMIT_EXCEEDED</tt>: 53400 (Error)
configuration_limit_exceeded :: ByteString

-- | <tt>PROGRAM_LIMIT_EXCEEDED</tt>: 54000 (Error)
program_limit_exceeded :: ByteString

-- | <tt>STATEMENT_TOO_COMPLEX</tt>: 54001 (Error)
statement_too_complex :: ByteString

-- | <tt>TOO_MANY_COLUMNS</tt>: 54011 (Error)
too_many_columns :: ByteString

-- | <tt>TOO_MANY_ARGUMENTS</tt>: 54023 (Error)
too_many_arguments :: ByteString

-- | <tt>OBJECT_NOT_IN_PREREQUISITE_STATE</tt>: 55000 (Error)
object_not_in_prerequisite_state :: ByteString

-- | <tt>OBJECT_IN_USE</tt>: 55006 (Error)
object_in_use :: ByteString

-- | <tt>CANT_CHANGE_RUNTIME_PARAM</tt>: 55P02 (Error)
cant_change_runtime_param :: ByteString

-- | <tt>LOCK_NOT_AVAILABLE</tt>: 55P03 (Error)
lock_not_available :: ByteString

-- | <tt>OPERATOR_INTERVENTION</tt>: 57000 (Error)
operator_intervention :: ByteString

-- | <tt>QUERY_CANCELED</tt>: 57014 (Error)
query_canceled :: ByteString

-- | <tt>ADMIN_SHUTDOWN</tt>: 57P01 (Error)
admin_shutdown :: ByteString

-- | <tt>CRASH_SHUTDOWN</tt>: 57P02 (Error)
crash_shutdown :: ByteString

-- | <tt>CANNOT_CONNECT_NOW</tt>: 57P03 (Error)
cannot_connect_now :: ByteString

-- | <tt>DATABASE_DROPPED</tt>: 57P04 (Error)
database_dropped :: ByteString

-- | <tt>SYSTEM_ERROR</tt>: 58000 (Error)
system_error :: ByteString

-- | <tt>IO_ERROR</tt>: 58030 (Error)
io_error :: ByteString

-- | <tt>UNDEFINED_FILE</tt>: 58P01 (Error)
undefined_file :: ByteString

-- | <tt>DUPLICATE_FILE</tt>: 58P02 (Error)
duplicate_file :: ByteString

-- | <tt>CONFIG_FILE_ERROR</tt>: F0000 (Error)
config_file_error :: ByteString

-- | <tt>LOCK_FILE_EXISTS</tt>: F0001 (Error)
lock_file_exists :: ByteString

-- | <tt>FDW_ERROR</tt>: HV000 (Error)
fdw_error :: ByteString

-- | <tt>FDW_COLUMN_NAME_NOT_FOUND</tt>: HV005 (Error)
fdw_column_name_not_found :: ByteString

-- | <tt>FDW_DYNAMIC_PARAMETER_VALUE_NEEDED</tt>: HV002 (Error)
fdw_dynamic_parameter_value_needed :: ByteString

-- | <tt>FDW_FUNCTION_SEQUENCE_ERROR</tt>: HV010 (Error)
fdw_function_sequence_error :: ByteString

-- | <tt>FDW_INCONSISTENT_DESCRIPTOR_INFORMATION</tt>: HV021 (Error)
fdw_inconsistent_descriptor_information :: ByteString

-- | <tt>FDW_INVALID_ATTRIBUTE_VALUE</tt>: HV024 (Error)
fdw_invalid_attribute_value :: ByteString

-- | <tt>FDW_INVALID_COLUMN_NAME</tt>: HV007 (Error)
fdw_invalid_column_name :: ByteString

-- | <tt>FDW_INVALID_COLUMN_NUMBER</tt>: HV008 (Error)
fdw_invalid_column_number :: ByteString

-- | <tt>FDW_INVALID_DATA_TYPE</tt>: HV004 (Error)
fdw_invalid_data_type :: ByteString

-- | <tt>FDW_INVALID_DATA_TYPE_DESCRIPTORS</tt>: HV006 (Error)
fdw_invalid_data_type_descriptors :: ByteString

-- | <tt>FDW_INVALID_DESCRIPTOR_FIELD_IDENTIFIER</tt>: HV091 (Error)
fdw_invalid_descriptor_field_identifier :: ByteString

-- | <tt>FDW_INVALID_HANDLE</tt>: HV00B (Error)
fdw_invalid_handle :: ByteString

-- | <tt>FDW_INVALID_OPTION_INDEX</tt>: HV00C (Error)
fdw_invalid_option_index :: ByteString

-- | <tt>FDW_INVALID_OPTION_NAME</tt>: HV00D (Error)
fdw_invalid_option_name :: ByteString

-- | <tt>FDW_INVALID_STRING_LENGTH_OR_BUFFER_LENGTH</tt>: HV090 (Error)
fdw_invalid_string_length_or_buffer_length :: ByteString

-- | <tt>FDW_INVALID_STRING_FORMAT</tt>: HV00A (Error)
fdw_invalid_string_format :: ByteString

-- | <tt>FDW_INVALID_USE_OF_NULL_POINTER</tt>: HV009 (Error)
fdw_invalid_use_of_null_pointer :: ByteString

-- | <tt>FDW_TOO_MANY_HANDLES</tt>: HV014 (Error)
fdw_too_many_handles :: ByteString

-- | <tt>FDW_OUT_OF_MEMORY</tt>: HV001 (Error)
fdw_out_of_memory :: ByteString

-- | <tt>FDW_NO_SCHEMAS</tt>: HV00P (Error)
fdw_no_schemas :: ByteString

-- | <tt>FDW_OPTION_NAME_NOT_FOUND</tt>: HV00J (Error)
fdw_option_name_not_found :: ByteString

-- | <tt>FDW_REPLY_HANDLE</tt>: HV00K (Error)
fdw_reply_handle :: ByteString

-- | <tt>FDW_SCHEMA_NOT_FOUND</tt>: HV00Q (Error)
fdw_schema_not_found :: ByteString

-- | <tt>FDW_TABLE_NOT_FOUND</tt>: HV00R (Error)
fdw_table_not_found :: ByteString

-- | <tt>FDW_UNABLE_TO_CREATE_EXECUTION</tt>: HV00L (Error)
fdw_unable_to_create_execution :: ByteString

-- | <tt>FDW_UNABLE_TO_CREATE_REPLY</tt>: HV00M (Error)
fdw_unable_to_create_reply :: ByteString

-- | <tt>FDW_UNABLE_TO_ESTABLISH_CONNECTION</tt>: HV00N (Error)
fdw_unable_to_establish_connection :: ByteString

-- | <tt>PLPGSQL_ERROR</tt>: P0000 (Error)
plpgsql_error :: ByteString

-- | <tt>RAISE_EXCEPTION</tt>: P0001 (Error)
raise_exception :: ByteString

-- | <tt>NO_DATA_FOUND</tt>: P0002 (Error)
no_data_found :: ByteString

-- | <tt>TOO_MANY_ROWS</tt>: P0003 (Error)
too_many_rows :: ByteString

-- | <tt>ASSERT_FAILURE</tt>: P0004 (Error)
assert_failure :: ByteString

-- | <tt>INTERNAL_ERROR</tt>: XX000 (Error)
internal_error :: ByteString

-- | <tt>DATA_CORRUPTED</tt>: XX001 (Error)
data_corrupted :: ByteString

-- | <tt>INDEX_CORRUPTED</tt>: XX002 (Error)
index_corrupted :: ByteString


-- | Automatic (dynamic) marshalling of PostgreSQL values based on Haskell
--   types (not SQL statements). This is intended for direct construction
--   of queries and query data, bypassing the normal SQL type inference.
module Database.PostgreSQL.Typed.Dynamic

-- | Represents canonical/default PostgreSQL representation for various
--   Haskell types, allowing convenient type-driven marshalling.
class (PGParameter (PGRepType a) a, PGColumn (PGRepType a) a) => PGRep a where type PGRepType a :: Symbol where {
    type family PGRepType a :: Symbol;
}
pgTypeOf :: a -> PGTypeID (PGRepType a)
pgTypeOfProxy :: Proxy a -> PGTypeID (PGRepType a)

-- | Encode a value using <a>pgEncodeValue</a>.
pgEncodeRep :: PGRep a => a -> PGValue

-- | Decode a value using <a>pgDecodeValue</a>.
pgDecodeRep :: forall a. PGRep a => PGValue -> a

-- | Produce a literal value for interpolation in a SQL statement using
--   <a>pgLiteral</a>. Using <a>pgSafeLiteral</a> is usually safer as it
--   includes type cast.
pgLiteralRep :: PGRep a => a -> ByteString

-- | Produce a raw SQL literal from a value. Using <a>pgSafeLiteral</a> is
--   usually safer when interpolating in a SQL statement.
pgLiteralString :: PGRep a => a -> String

-- | Produce a safely type-cast literal value for interpolation in a SQL
--   statement, e.g., "'123'::integer".
pgSafeLiteral :: PGRep a => a -> ByteString

-- | Identical to <tt><a>unpack</a> . <a>pgSafeLiteral</a></tt> but more
--   efficient.
pgSafeLiteralString :: PGRep a => a -> String

-- | Create an expression that literally substitutes each instance of
--   <tt>${expr}</tt> for the result of <tt>pgSafeLiteral expr</tt>,
--   producing a lazy <a>ByteString</a>. This lets you do safe, type-driven
--   literal substitution into SQL fragments without needing a full query,
--   bypassing placeholder inference and any prepared queries, for example
--   when using <a>pgSimpleQuery</a> or <a>pgSimpleQueries_</a>. Unlike
--   most other TH functions, this does not require any database
--   connection.
pgSubstituteLiterals :: String -> ExpQ
instance Database.PostgreSQL.Typed.Dynamic.PGRep a => Database.PostgreSQL.Typed.Dynamic.PGRep (GHC.Base.Maybe a)
instance Database.PostgreSQL.Typed.Dynamic.PGRep ()
instance Database.PostgreSQL.Typed.Dynamic.PGRep GHC.Types.Bool
instance Database.PostgreSQL.Typed.Dynamic.PGRep Database.PostgreSQL.Typed.Types.OID
instance Database.PostgreSQL.Typed.Dynamic.PGRep GHC.Int.Int16
instance Database.PostgreSQL.Typed.Dynamic.PGRep GHC.Int.Int32
instance Database.PostgreSQL.Typed.Dynamic.PGRep GHC.Int.Int64
instance Database.PostgreSQL.Typed.Dynamic.PGRep GHC.Types.Float
instance Database.PostgreSQL.Typed.Dynamic.PGRep GHC.Types.Double
instance Database.PostgreSQL.Typed.Dynamic.PGRep GHC.Types.Char
instance Database.PostgreSQL.Typed.Dynamic.PGRep GHC.Base.String
instance Database.PostgreSQL.Typed.Dynamic.PGRep Data.ByteString.Internal.ByteString
instance Database.PostgreSQL.Typed.Dynamic.PGRep Database.PostgreSQL.Typed.Types.PGName
instance Database.PostgreSQL.Typed.Dynamic.PGRep Data.Text.Internal.Text
instance Database.PostgreSQL.Typed.Dynamic.PGRep Data.Time.Calendar.Days.Day
instance Database.PostgreSQL.Typed.Dynamic.PGRep Data.Time.LocalTime.TimeOfDay.TimeOfDay
instance Database.PostgreSQL.Typed.Dynamic.PGRep (Data.Time.LocalTime.TimeOfDay.TimeOfDay, Data.Time.LocalTime.TimeZone.TimeZone)
instance Database.PostgreSQL.Typed.Dynamic.PGRep Data.Time.LocalTime.LocalTime.LocalTime
instance Database.PostgreSQL.Typed.Dynamic.PGRep Data.Time.Clock.UTC.UTCTime
instance Database.PostgreSQL.Typed.Dynamic.PGRep Data.Time.Clock.Scale.DiffTime
instance Database.PostgreSQL.Typed.Dynamic.PGRep GHC.Real.Rational
instance Database.PostgreSQL.Typed.Dynamic.PGRep Data.Scientific.Scientific
instance Database.PostgreSQL.Typed.Dynamic.PGRep Data.UUID.Types.Internal.UUID
instance Database.PostgreSQL.Typed.Dynamic.PGRep Data.Aeson.Types.Internal.Value


-- | The Protocol module allows for direct, low-level communication with a
--   PostgreSQL server over TCP/IP. You probably don't want to use this
--   module directly.
module Database.PostgreSQL.Typed.Protocol

-- | Information for how to connect to a database, to be passed to
--   <a>pgConnect</a>.
data PGDatabase
PGDatabase :: HostName -> PortID -> ByteString -> ByteString -> [(ByteString, ByteString)] -> Bool -> (MessageFields -> IO ()) -> PGDatabase

-- | The hostname (ignored if <a>pgDBPort</a> is <a>UnixSocket</a>)
[pgDBHost] :: PGDatabase -> HostName

-- | The port, likely either <tt>PortNumber 5432</tt> or <tt>UnixSocket
--   "/tmp/.s.PGSQL.5432"</tt>
[pgDBPort] :: PGDatabase -> PortID

-- | The name of the database
[pgDBName] :: PGDatabase -> ByteString
[pgDBUser, pgDBPass] :: PGDatabase -> ByteString

-- | Extra parameters to set for the connection (e.g., (<a>TimeZone</a>,
--   <a>UTC</a>))
[pgDBParams] :: PGDatabase -> [(ByteString, ByteString)]

-- | Log all low-level server messages
[pgDBDebug] :: PGDatabase -> Bool

-- | How to log server notice messages (e.g., <tt>print . PGError</tt>)
[pgDBLogMessage] :: PGDatabase -> MessageFields -> IO ()

-- | A database connection with sane defaults: localhost:5432:postgres
defaultPGDatabase :: PGDatabase

-- | An established connection to the PostgreSQL server. These objects are
--   not thread-safe and must only be used for a single request at a time.
data PGConnection

-- | PGException is thrown upon encountering an <a>ErrorResponse</a> with
--   severity of ERROR, FATAL, or PANIC. It holds the message of the error.
data PGError
PGError :: MessageFields -> PGError
[pgErrorFields] :: PGError -> MessageFields

-- | Message SQLState code. See
--   <a>http://www.postgresql.org/docs/current/static/errcodes-appendix.html</a>.
pgErrorCode :: PGError -> ByteString

-- | The database information for this connection.
pgConnectionDatabase :: PGConnection -> PGDatabase

-- | The type environment for this connection.
pgTypeEnv :: PGConnection -> PGTypeEnv

-- | Retrieve the "server_version" parameter from the connection, if any.
pgServerVersion :: PGConnection -> Maybe ByteString

-- | Connect to a PostgreSQL server.
pgConnect :: PGDatabase -> IO PGConnection

-- | Disconnect cleanly from the PostgreSQL server.
pgDisconnect :: PGConnection -> IO ()

-- | Possibly re-open a connection to a different database, either reusing
--   the connection if the given database is already connected or closing
--   it and opening a new one. Regardless, the input connection must not be
--   used afterwards.
pgReconnect :: PGConnection -> PGDatabase -> IO PGConnection

-- | Describe a SQL statement/query. A statement description consists of 0
--   or more parameter descriptions (a PostgreSQL type) and zero or more
--   result field descriptions (for queries) (consist of the name of the
--   field, the type of the field, and a nullability indicator).
pgDescribe :: PGConnection -> ByteString -> [OID] -> Bool -> IO ([OID], [(ByteString, OID, Bool)])

-- | A simple query is one which requires sending only a single
--   <a>SimpleQuery</a> message to the PostgreSQL server. The query is sent
--   as a single string; you cannot bind parameters. Note that queries can
--   return 0 results (an empty list).
pgSimpleQuery :: PGConnection -> ByteString -> IO (Int, [PGValues])

-- | A simple query which may contain multiple queries (separated by
--   semi-colons) whose results are all ignored. This function can also be
--   used for "SET" parameter queries if necessary, but it's safer better
--   to use <a>pgDBParams</a>.
pgSimpleQueries_ :: PGConnection -> ByteString -> IO ()

-- | Prepare a statement, bind it, and execute it. If the given statement
--   has already been prepared (and not yet closed) on this connection, it
--   will be re-used.
pgPreparedQuery :: PGConnection -> ByteString -> [OID] -> PGValues -> [Bool] -> IO (Int, [PGValues])

-- | Like <a>pgPreparedQuery</a> but requests results lazily in chunks of
--   the given size. Does not use a named portal, so other requests may not
--   intervene.
pgPreparedLazyQuery :: PGConnection -> ByteString -> [OID] -> PGValues -> [Bool] -> Word32 -> IO [PGValues]

-- | Close a previously prepared query (if necessary).
pgCloseStatement :: PGConnection -> ByteString -> [OID] -> IO ()

-- | Begin a new transaction. If there is already a transaction in progress
--   (created with <a>pgBegin</a> or <a>pgTransaction</a>) instead creates
--   a savepoint.
pgBegin :: PGConnection -> IO ()

-- | Commit the most recent <a>pgBegin</a>.
pgCommit :: PGConnection -> IO ()

-- | Rollback to the most recent <a>pgBegin</a>.
pgRollback :: PGConnection -> IO ()

-- | Commit all active <a>pgBegin</a>s.
pgCommitAll :: PGConnection -> IO ()

-- | Rollback all active <a>pgBegin</a>s.
pgRollbackAll :: PGConnection -> IO ()

-- | Wrap a computation in a <a>pgBegin</a>, <a>pgCommit</a> block, or
--   <a>pgRollback</a> on exception.
pgTransaction :: PGConnection -> IO a -> IO a

-- | Disconnect cleanly from the PostgreSQL server, but only if it's still
--   connected.
pgDisconnectOnce :: PGConnection -> IO ()

-- | Prepare, bind, execute, and close a single (unnamed) query, and return
--   the number of rows affected, or Nothing if there are (ignored) result
--   rows.
pgRun :: PGConnection -> ByteString -> [OID] -> PGValues -> IO (Maybe Integer)
data PGPreparedStatement

-- | Prepare a single query and return its handle.
pgPrepare :: PGConnection -> ByteString -> [OID] -> IO PGPreparedStatement

-- | Close a previously prepared query.
pgClose :: PGConnection -> PGPreparedStatement -> IO ()
data PGColDescription
PGColDescription :: ByteString -> !OID -> !Int16 -> !OID -> !Int16 -> !Int32 -> !Bool -> PGColDescription
[colName] :: PGColDescription -> ByteString
[colTable] :: PGColDescription -> !OID
[colNumber] :: PGColDescription -> !Int16
[colType] :: PGColDescription -> !OID
[colSize] :: PGColDescription -> !Int16
[colModifier] :: PGColDescription -> !Int32
[colBinary] :: PGColDescription -> !Bool
type PGRowDescription = [PGColDescription]

-- | Bind a prepared statement, and return the row description. After
--   <a>pgBind</a>, you must either call <a>pgFetch</a> until it completes
--   (returns <tt>(_, <a>Just</a> _)</tt>) or <tt>pgFinish</tt> before
--   calling <a>pgBind</a> again on the same prepared statement.
pgBind :: PGConnection -> PGPreparedStatement -> PGValues -> IO PGRowDescription

-- | Fetch a single row from an executed prepared statement, returning the
--   next N result rows (if any) and number of affected rows when complete.
pgFetch :: PGConnection -> PGPreparedStatement -> Word32 -> IO ([PGValues], Maybe Integer)
instance GHC.Show.Show Database.PostgreSQL.Typed.Protocol.PGBackendMessage
instance GHC.Show.Show Database.PostgreSQL.Typed.Protocol.PGFrontendMessage
instance GHC.Show.Show Database.PostgreSQL.Typed.Protocol.PGColDescription
instance GHC.Show.Show Database.PostgreSQL.Typed.Protocol.PGPreparedStatement
instance GHC.Classes.Eq Database.PostgreSQL.Typed.Protocol.PGPreparedStatement
instance GHC.Classes.Eq Database.PostgreSQL.Typed.Protocol.PGState
instance GHC.Show.Show Database.PostgreSQL.Typed.Protocol.PGState
instance GHC.Classes.Eq Database.PostgreSQL.Typed.Protocol.PGDatabase
instance GHC.Show.Show Database.PostgreSQL.Typed.Protocol.PGError
instance GHC.Exception.Exception Database.PostgreSQL.Typed.Protocol.PGError


-- | Use postgresql-typed as a backend for HDBC.
module Database.PostgreSQL.Typed.HDBC

-- | A wrapped <a>PGConnection</a>. This differs from a bare
--   <a>PGConnection</a> in a few ways:
--   
--   <ol>
--   <li>It always has exactly one active transaction (with
--   <a>pgBegin</a>)</li>
--   <li>It automatically disconnects on GC</li>
--   <li>It provides a mutex around the underlying <a>PGConnection</a> for
--   thread-safety</li>
--   </ol>
data Connection

-- | Connect to a database for HDBC use (equivalent to <a>pgConnect</a> and
--   <a>pgBegin</a>).
connect :: PGDatabase -> IO Connection

-- | Convert an existing <a>PGConnection</a> to an HDBC-compatible
--   <a>Connection</a>. The caveats under <a>connectionPG</a> apply if you
--   plan to continue using the original <a>PGConnection</a>.
fromPGConnection :: PGConnection -> IO Connection

-- | Use the underlying <a>PGConnection</a> directly. You must be careful
--   to ensure that the first invariant is preserved: you should not call
--   <a>pgBegin</a>, <a>pgCommit</a>, or <a>pgRollback</a> on it. All other
--   operations should be safe.
withPGConnection :: Connection -> (PGConnection -> IO a) -> IO a

-- | Reload the table of all types from the database. This may be needed if
--   you make structural changes to the database.
reloadTypes :: Connection -> IO Connection

-- | Number of rows to fetch (and cache) with <a>execute</a> and each time
--   <a>fetchRow</a> requires more rows. A higher value will result in
--   fewer round-trips to the database but potentially more wasted data.
--   Defaults to 1. 0 means fetch all rows.
connectionFetchSize :: Connection -> Word32

-- | Change the <a>connectionFetchSize</a> for new <a>Statement</a>s
--   created with <a>prepare</a>. Ideally this could be set with each call
--   to <a>execute</a> and <a>fetchRow</a>, but the HDBC interface provides
--   no way to do this.
setFetchSize :: Word32 -> Connection -> Connection
instance Database.HDBC.Types.IConnection Database.PostgreSQL.Typed.HDBC.Connection


-- | Support functions for compile-time PostgreSQL connection and state
--   management. You can use these to build your own Template Haskell
--   functions using the PostgreSQL connection.
module Database.PostgreSQL.Typed.TH

-- | Generate a <a>PGDatabase</a> based on the environment variables:
--   <tt>TPG_HOST</tt> (localhost); <tt>TPG_SOCK</tt> or <tt>TPG_PORT</tt>
--   (5432); <tt>TPG_DB</tt> or user; <tt>TPG_USER</tt> or <tt>USER</tt>
--   (postgres); <tt>TPG_PASS</tt> ()
getTPGDatabase :: IO PGDatabase

-- | Run an action using the Template Haskell state.
withTPGTypeConnection :: (PGTypeConnection -> IO a) -> IO a

-- | Run an action using the Template Haskell PostgreSQL connection.
withTPGConnection :: (PGConnection -> IO a) -> IO a

-- | Specify an alternative database to use during compilation. This lets
--   you override the default connection parameters that are based on TPG
--   environment variables. This should be called as a top-level
--   declaration and produces no code. It uses <a>pgReconnect</a> so is
--   safe to call multiple times with the same database.
useTPGDatabase :: PGDatabase -> DecsQ

-- | Force reloading of all types from the database. This may be needed if
--   you make structural changes to the database during compile-time.
reloadTPGTypes :: DecsQ
data TPGValueInfo
TPGValueInfo :: ByteString -> !OID -> PGName -> Bool -> TPGValueInfo
[tpgValueName] :: TPGValueInfo -> ByteString
[tpgValueTypeOID] :: TPGValueInfo -> !OID
[tpgValueType] :: TPGValueInfo -> PGName
[tpgValueNullable] :: TPGValueInfo -> Bool

-- | A type-aware wrapper to <a>pgDescribe</a>
tpgDescribe :: ByteString -> [String] -> Bool -> IO ([TPGValueInfo], [TPGValueInfo])

-- | TH expression to encode a <a>PGParameter</a> value to a <a>Maybe</a>
--   <a>ByteString</a>.
tpgTypeEncoder :: Bool -> TPGValueInfo -> Name -> Exp

-- | TH expression to decode a <a>Maybe</a> <a>ByteString</a> to a
--   (<a>Maybe</a>) <a>PGColumn</a> value.
tpgTypeDecoder :: Bool -> TPGValueInfo -> Name -> Exp

-- | TH expression calling <a>pgBinaryColumn</a>.
tpgTypeBinary :: TPGValueInfo -> Name -> Exp


-- | Support for PostgreSQL enums.
module Database.PostgreSQL.Typed.Enum

-- | A type based on a PostgreSQL enum. Automatically instantiated by
--   <a>dataPGEnum</a>.
class (Eq a, Ord a, Enum a, Bounded a, PGRep a) => PGEnum a where pgEnumName a = fromJust $ lookup a pgEnumValues pgEnumValue n = lookup n $ map swap pgEnumValues pgEnumValues = map (id &&& pgEnumName) $ enumFromTo minBound maxBound

-- | The database name of a value.
pgEnumName :: PGEnum a => a -> PGName

-- | Lookup a value matching the given database name.
pgEnumValue :: PGEnum a => PGName -> Maybe a

-- | List of all the values in the enum along with their database names.
pgEnumValues :: PGEnum a => [(a, PGName)]

-- | Create a new enum type corresponding to the given PostgreSQL enum
--   type. For example, if you have <tt>CREATE TYPE foo AS ENUM ('abc',
--   'DEF')</tt>, then <tt>dataPGEnum "Foo" "foo" ("Foo_"++)</tt> will be
--   equivalent to:
--   
--   <pre>
--   data Foo = Foo_abc | Foo_DEF deriving (Eq, Ord, Enum, Bounded, Typeable)
--   instance PGType "foo" where PGVal "foo" = Foo
--   instance PGParameter "foo" Foo where ...
--   instance PGColumn "foo" Foo where ...
--   instance PGRep Foo where PGRepType = "foo"
--   instance PGEnum Foo where pgEnumValues = [(Foo_abc, "abc"), (Foo_DEF, "DEF")]
--   </pre>
--   
--   Requires language extensions: TemplateHaskell, FlexibleInstances,
--   MultiParamTypeClasses, DeriveDataTypeable, DataKinds, TypeFamilies
dataPGEnum :: String -> PGName -> (String -> String) -> DecsQ

module Database.PostgreSQL.Typed.Query
class PGQuery q a | q -> a

-- | Execute a query and return the number of rows affected (or -1 if not
--   known) and a list of results.
pgRunQuery :: PGQuery q a => PGConnection -> q -> IO (Int, [a])

-- | Change the raw SQL query stored within this query. This is unsafe
--   because the query has already been type-checked, so any change must
--   not change the number or type of results or placeholders (so adding
--   additional static WHERE or ORDER BY clauses is generally safe). This
--   is useful in cases where you need to construct some part of the query
--   dynamically, but still want to infer the result types. If you want to
--   add dynamic values to the query, it's best to use
--   <a>pgSafeLiteral</a>. For example:
--   
--   <pre>
--   [pgSQL|SELECT a FROM t|] `unsafeModifyQuery` (&lt;&gt; (" WHERE a = " &lt;&gt; pgSafeLiteral x))
--   </pre>
unsafeModifyQuery :: PGQuery q a => q -> (ByteString -> ByteString) -> q

-- | A simple one-shot query that simply substitutes literal
--   representations of parameters for placeholders.
type PGSimpleQuery = QueryParser SimpleQuery

-- | A prepared query that automatically is prepared in the database the
--   first time it is run and bound with new parameters each subsequent
--   time.
type PGPreparedQuery = QueryParser PreparedQuery

-- | Make a simple query directly from a query string, with no type
--   inference
rawPGSimpleQuery :: ByteString -> PGSimpleQuery PGValues

-- | Make a prepared query directly from a query string and bind
--   parameters, with no type inference
rawPGPreparedQuery :: ByteString -> PGValues -> PGPreparedQuery PGValues

-- | Flags affecting how and what type of query to build with
--   <a>makePGQuery</a>.
data QueryFlags
QueryFlags :: Bool -> Maybe Bool -> Maybe [String] -> QueryFlags

-- | Create a query -- otherwise just call <a>pgSubstituteLiterals</a> to
--   create a string (SQL fragment).
[flagQuery] :: QueryFlags -> Bool

-- | Disable nullability inference, treating all values as nullable (if
--   <a>True</a>) or not (if <a>False</a>).
[flagNullable] :: QueryFlags -> Maybe Bool

-- | Prepare and re-use query, binding parameters of the given types
--   (inferring the rest, like PREPARE).
[flagPrepare] :: QueryFlags -> Maybe [String]

-- | <a>QueryFlags</a> for a default (simple) query.
simpleQueryFlags :: QueryFlags

-- | Parse flags off the beginning of a query string, returning the flags
--   and the remaining string.
parseQueryFlags :: String -> (QueryFlags, String)

-- | Construct a <a>PGQuery</a> from a SQL string. This is the underlying
--   template function for <a>pgSQL</a> which you can use in largely the
--   same way when you want to construct query strings from other
--   variables. For example:
--   
--   <pre>
--   selectQuery = "SELECT * FROM"
--   selectFoo = $(makePGQuery simpleQueryFlags (selectQuery ++ " foo"))
--   </pre>
--   
--   The only caveat is that variables or functions like
--   <tt>selectQuery</tt> need to be defined in a different module (due to
--   TH stage restrictions).
makePGQuery :: QueryFlags -> String -> ExpQ

-- | A quasi-quoter for PGSQL queries.
--   
--   Used in expression context, it may contain any SQL statement
--   <tt>[pgSQL|SELECT ...|]</tt>. The statement may contain
--   PostgreSQL-style placeholders (<tt>$1</tt>, <tt>$2</tt>, ...) or
--   in-line placeholders (<tt>${1+1}</tt>) containing any valid Haskell
--   expression (except <tt>{}</tt>). It will be replaced by a
--   <a>PGQuery</a> object that can be used to perform the SQL statement.
--   If there are more <tt>$N</tt> placeholders than expressions, it will
--   instead be a function accepting the additional parameters and
--   returning a <a>PGQuery</a>.
--   
--   Ideally, this mimics postgres' SQL parsing, so that placeholders and
--   expressions will only be expanded when they are in valid positions
--   (i.e., not inside quoted strings). Since <tt>${</tt> is not valid SQL
--   otherwise, there should be no need to escape it.
--   
--   The statement may start with one of more special flags affecting the
--   interpretation:
--   
--   <ul>
--   <li><i><tt>?</tt></i> To disable nullability inference, treating all
--   result values as nullable, thus returning <a>Maybe</a> values
--   regardless of inferred nullability. This makes unexpected NULL errors
--   impossible.</li>
--   <li><i><tt>!</tt></i> To disable nullability inference, treating all
--   result values as <i>not</i> nullable, thus only returning <a>Maybe</a>
--   where requested. This is makes unexpected NULL errors more
--   likely.</li>
--   <li><i><tt>$</tt></i> To create a <a>PGPreparedQuery</a> (using
--   placeholder parameters) rather than the default <a>PGSimpleQuery</a>
--   (using literal substitution).</li>
--   <li><i><tt>$(type,...)</tt></i> To specify specific types for a
--   prepared query (see
--   <a>http://www.postgresql.org/docs/current/static/sql-prepare.html</a>
--   for details), rather than inferring parameter types by default.</li>
--   <li><i><tt>#</tt></i> Only do literal <tt>${}</tt> substitution using
--   <a>pgSubstituteLiterals</a> and return a string, not a query.</li>
--   </ul>
--   
--   <a>pgSQL</a> can also be used at the top-level to execute SQL
--   statements at compile-time (without any parameters and ignoring
--   results). Here the query can only be prefixed with <tt>!</tt> to make
--   errors non-fatal.
--   
--   If you want to construct queries out of string variables rather than
--   quasi-quoted strings, you can use the lower-level <a>makePGQuery</a>
--   instead.
pgSQL :: QuasiQuoter

-- | Execute a query that does not return results. Return the number of
--   rows affected (or -1 if not known).
pgExecute :: PGQuery q () => PGConnection -> q -> IO Int

-- | Run a query and return a list of row results.
pgQuery :: PGQuery q a => PGConnection -> q -> IO [a]

-- | Run a prepared query in lazy mode, where only chunk size rows are
--   requested at a time. If you eventually retrieve all the rows this way,
--   it will be far less efficient than using <tt>pgQuery</tt>, since every
--   chunk requires an additional round-trip. Although you may safely stop
--   consuming rows early, currently you may not interleave any other
--   database operation while reading rows. (This limitation could
--   theoretically be lifted if required.)
pgLazyQuery :: PGConnection -> PGPreparedQuery a -> Word32 -> IO [a]
instance GHC.Show.Show Database.PostgreSQL.Typed.Query.PreparedQuery
instance GHC.Show.Show Database.PostgreSQL.Typed.Query.SimpleQuery
instance Database.PostgreSQL.Typed.Query.PGQuery Data.ByteString.Internal.ByteString Database.PostgreSQL.Typed.Types.PGValues
instance Database.PostgreSQL.Typed.Query.PGQuery Database.PostgreSQL.Typed.Query.SimpleQuery Database.PostgreSQL.Typed.Types.PGValues
instance Database.PostgreSQL.Typed.Query.PGRawQuery Database.PostgreSQL.Typed.Query.SimpleQuery
instance Database.PostgreSQL.Typed.Query.PGQuery Database.PostgreSQL.Typed.Query.PreparedQuery Database.PostgreSQL.Typed.Types.PGValues
instance Database.PostgreSQL.Typed.Query.PGRawQuery Database.PostgreSQL.Typed.Query.PreparedQuery
instance Database.PostgreSQL.Typed.Query.PGRawQuery q => Database.PostgreSQL.Typed.Query.PGQuery (Database.PostgreSQL.Typed.Query.QueryParser q a) a
instance GHC.Base.Functor (Database.PostgreSQL.Typed.Query.QueryParser q)
instance GHC.Show.Show q => GHC.Show.Show (Database.PostgreSQL.Typed.Query.QueryParser q a)
instance Data.String.IsString (Database.PostgreSQL.Typed.Query.PGSimpleQuery Database.PostgreSQL.Typed.Types.PGValues)
instance Data.String.IsString (Database.PostgreSQL.Typed.Query.PGSimpleQuery ())


-- | This module exposes the high-level Template Haskell interface for
--   querying and manipulating the PostgreSQL server.
--   
--   All SQL string arguments support expression interpolation. Just
--   enclose your expression in <tt>{}</tt> in the SQL string.
--   
--   Note that transactions are messy and untested. Attempt to use them at
--   your own risk.
module Database.PostgreSQL.Typed.TemplatePG

-- | <pre>
--   queryTuples :: String -&gt; (PGConnection -&gt; IO [(column1, column2, ...)])
--   </pre>
--   
--   Query a PostgreSQL server and return the results as a list of tuples.
--   
--   Example (where <tt>h</tt> is a handle from <a>pgConnect</a>):
--   
--   <pre>
--   $(queryTuples "SELECT usesysid, usename FROM pg_user") h :: IO [(Maybe String, Maybe Integer)]
--   </pre>
queryTuples :: String -> ExpQ

-- | <pre>
--   queryTuple :: String -&gt; (PGConnection -&gt; IO (Maybe (column1, column2, ...)))
--   </pre>
--   
--   Convenience function to query a PostgreSQL server and return the first
--   result as a tuple. If the query produces no results, return
--   <a>Nothing</a>.
--   
--   Example (where <tt>h</tt> is a handle from <a>pgConnect</a>):
--   
--   <pre>
--   let sysid = 10::Integer;
--   $(queryTuple "SELECT usesysid, usename FROM pg_user WHERE usesysid = {sysid}") h :: IO (Maybe (Maybe String, Maybe Integer))
--   </pre>
queryTuple :: String -> ExpQ

-- | <pre>
--   execute :: String -&gt; (PGConnection -&gt; IO ())
--   </pre>
--   
--   Convenience function to execute a statement on the PostgreSQL server.
--   
--   Example (where <tt>h</tt> is a handle from <a>pgConnect</a>):
execute :: String -> ExpQ

-- | Ignore duplicate key errors. This is also limited to the <a>IO</a>
--   Monad.
insertIgnore :: IO () -> IO ()

-- | Run a sequence of IO actions (presumably SQL statements) wrapped in a
--   transaction. Unfortunately you're restricted to using this in the
--   <a>IO</a> Monad for now due to the use of <tt>onException</tt>. I'm
--   debating adding a <tt>MonadPeelIO</tt> version.
withTransaction :: PGConnection -> IO a -> IO a

-- | Roll back a transaction.
rollback :: PGConnection -> IO ()
type PGException = PGError
pgConnect :: HostName -> PortID -> ByteString -> ByteString -> ByteString -> IO PGConnection

-- | Disconnect cleanly from the PostgreSQL server.
pgDisconnect :: PGConnection -> IO ()


-- | Automatically create data types based on tables and other relations.
module Database.PostgreSQL.Typed.Relation

-- | Create a new data type corresponding to the given PostgreSQL relation.
--   For example, if you have <tt>CREATE TABLE foo (abc integer NOT NULL,
--   def text)</tt>, then <tt>dataPGRelation "Foo" "foo" ("foo_"++)</tt>
--   will be equivalent to:
--   
--   <pre>
--   data Foo = Foo{ foo_abc :: PGVal "integer", foo_def :: Maybe (PGVal "text") }
--   instance PGType "foo" where PGVal "foo" = Foo
--   instance PGParameter "foo" Foo where ...
--   instance PGColumn "foo" Foo where ...
--   instance PGColumn "foo" (Maybe Foo) where ... -- to handle NULL in not null columns
--   instance PGRep Foo where PGRepType = "foo"
--   instance PGRecordType "foo"
--   instance PGRelation Foo where pgColumnNames _ = ["abc", "def"]
--   uncurryFoo :: (PGVal "integer", Maybe (PGVal "text")) -&gt; Foo
--   </pre>
--   
--   (Note that <tt>PGVal "integer" = Int32</tt> and <tt>PGVal "text" =
--   Text</tt> by default.) This provides instances for marshalling the
--   corresponding composite/record types, e.g., using <tt>SELECT
--   foo.*::foo FROM foo</tt>. If you want any derived instances, you'll
--   need to create them yourself using StandaloneDeriving.
--   
--   Requires language extensions: TemplateHaskell, FlexibleInstances,
--   MultiParamTypeClasses, DataKinds, TypeFamilies, PatternGuards
dataPGRelation :: String -> PGName -> (String -> String) -> DecsQ


-- | Representaion of PostgreSQL's array type. Currently this only supports
--   one-dimensional arrays. PostgreSQL arrays in theory can dynamically be
--   any (rectangular) shape.
module Database.PostgreSQL.Typed.Array

-- | The cannonical representation of a PostgreSQL array of any type, which
--   may always contain NULLs. Currenly only one-dimetional arrays are
--   supported, although in PostgreSQL, any array may be of any
--   dimentionality.
type PGArray a = [Maybe a]

-- | Class indicating that the first PostgreSQL type is an array of the
--   second. This implies <a>PGParameter</a> and <a>PGColumn</a> instances
--   that will work for any type using comma as a delimiter (i.e., anything
--   but <tt>box</tt>). This will only work with 1-dimensional arrays.
class (PGType t, PGType (PGElemType t)) => PGArrayType t where type PGElemType t :: Symbol pgArrayElementType PGTypeProxy = PGTypeProxy pgArrayDelim _ = ',' where {
    type family PGElemType t :: Symbol;
}
pgArrayElementType :: PGArrayType t => PGTypeID t -> PGTypeID (PGElemType t)

-- | The character used as a delimeter. The default <tt>,</tt> is correct
--   for all standard types (except <tt>box</tt>).
pgArrayDelim :: PGArrayType t => PGTypeID t -> Char

-- | Allow entirely non-null arrays as parameter inputs only. (Only
--   supported on ghc &gt;= 7.10 due to instance overlap.)
instance (Database.PostgreSQL.Typed.Array.PGArrayType t, Database.PostgreSQL.Typed.Types.PGParameter (Database.PostgreSQL.Typed.Array.PGElemType t) a) => Database.PostgreSQL.Typed.Types.PGParameter t (Database.PostgreSQL.Typed.Array.PGArray a)
instance (Database.PostgreSQL.Typed.Array.PGArrayType t, Database.PostgreSQL.Typed.Types.PGParameter (Database.PostgreSQL.Typed.Array.PGElemType t) a) => Database.PostgreSQL.Typed.Types.PGParameter t [a]
instance (Database.PostgreSQL.Typed.Array.PGArrayType t, Database.PostgreSQL.Typed.Types.PGColumn (Database.PostgreSQL.Typed.Array.PGElemType t) a) => Database.PostgreSQL.Typed.Types.PGColumn t (Database.PostgreSQL.Typed.Array.PGArray a)
instance Database.PostgreSQL.Typed.Types.PGType "boolean" => Database.PostgreSQL.Typed.Types.PGType "boolean[]"
instance Database.PostgreSQL.Typed.Types.PGType "boolean" => Database.PostgreSQL.Typed.Array.PGArrayType "boolean[]"
instance Database.PostgreSQL.Typed.Types.PGType "bytea" => Database.PostgreSQL.Typed.Types.PGType "bytea[]"
instance Database.PostgreSQL.Typed.Types.PGType "bytea" => Database.PostgreSQL.Typed.Array.PGArrayType "bytea[]"
instance Database.PostgreSQL.Typed.Types.PGType "\"char\"" => Database.PostgreSQL.Typed.Types.PGType "\"char\"[]"
instance Database.PostgreSQL.Typed.Types.PGType "\"char\"" => Database.PostgreSQL.Typed.Array.PGArrayType "\"char\"[]"
instance Database.PostgreSQL.Typed.Types.PGType "name" => Database.PostgreSQL.Typed.Types.PGType "name[]"
instance Database.PostgreSQL.Typed.Types.PGType "name" => Database.PostgreSQL.Typed.Array.PGArrayType "name[]"
instance Database.PostgreSQL.Typed.Types.PGType "bigint" => Database.PostgreSQL.Typed.Types.PGType "bigint[]"
instance Database.PostgreSQL.Typed.Types.PGType "bigint" => Database.PostgreSQL.Typed.Array.PGArrayType "bigint[]"
instance Database.PostgreSQL.Typed.Types.PGType "smallint" => Database.PostgreSQL.Typed.Types.PGType "smallint[]"
instance Database.PostgreSQL.Typed.Types.PGType "smallint" => Database.PostgreSQL.Typed.Array.PGArrayType "smallint[]"
instance Database.PostgreSQL.Typed.Types.PGType "int2vector" => Database.PostgreSQL.Typed.Types.PGType "int2vector[]"
instance Database.PostgreSQL.Typed.Types.PGType "int2vector" => Database.PostgreSQL.Typed.Array.PGArrayType "int2vector[]"
instance Database.PostgreSQL.Typed.Types.PGType "integer" => Database.PostgreSQL.Typed.Types.PGType "integer[]"
instance Database.PostgreSQL.Typed.Types.PGType "integer" => Database.PostgreSQL.Typed.Array.PGArrayType "integer[]"
instance Database.PostgreSQL.Typed.Types.PGType "regproc" => Database.PostgreSQL.Typed.Types.PGType "regproc[]"
instance Database.PostgreSQL.Typed.Types.PGType "regproc" => Database.PostgreSQL.Typed.Array.PGArrayType "regproc[]"
instance Database.PostgreSQL.Typed.Types.PGType "text" => Database.PostgreSQL.Typed.Types.PGType "text[]"
instance Database.PostgreSQL.Typed.Types.PGType "text" => Database.PostgreSQL.Typed.Array.PGArrayType "text[]"
instance Database.PostgreSQL.Typed.Types.PGType "oid" => Database.PostgreSQL.Typed.Types.PGType "oid[]"
instance Database.PostgreSQL.Typed.Types.PGType "oid" => Database.PostgreSQL.Typed.Array.PGArrayType "oid[]"
instance Database.PostgreSQL.Typed.Types.PGType "tid" => Database.PostgreSQL.Typed.Types.PGType "tid[]"
instance Database.PostgreSQL.Typed.Types.PGType "tid" => Database.PostgreSQL.Typed.Array.PGArrayType "tid[]"
instance Database.PostgreSQL.Typed.Types.PGType "xid" => Database.PostgreSQL.Typed.Types.PGType "xid[]"
instance Database.PostgreSQL.Typed.Types.PGType "xid" => Database.PostgreSQL.Typed.Array.PGArrayType "xid[]"
instance Database.PostgreSQL.Typed.Types.PGType "cid" => Database.PostgreSQL.Typed.Types.PGType "cid[]"
instance Database.PostgreSQL.Typed.Types.PGType "cid" => Database.PostgreSQL.Typed.Array.PGArrayType "cid[]"
instance Database.PostgreSQL.Typed.Types.PGType "oidvector" => Database.PostgreSQL.Typed.Types.PGType "oidvector[]"
instance Database.PostgreSQL.Typed.Types.PGType "oidvector" => Database.PostgreSQL.Typed.Array.PGArrayType "oidvector[]"
instance Database.PostgreSQL.Typed.Types.PGType "json" => Database.PostgreSQL.Typed.Types.PGType "json[]"
instance Database.PostgreSQL.Typed.Types.PGType "json" => Database.PostgreSQL.Typed.Array.PGArrayType "json[]"
instance Database.PostgreSQL.Typed.Types.PGType "xml" => Database.PostgreSQL.Typed.Types.PGType "xml[]"
instance Database.PostgreSQL.Typed.Types.PGType "xml" => Database.PostgreSQL.Typed.Array.PGArrayType "xml[]"
instance Database.PostgreSQL.Typed.Types.PGType "point" => Database.PostgreSQL.Typed.Types.PGType "point[]"
instance Database.PostgreSQL.Typed.Types.PGType "point" => Database.PostgreSQL.Typed.Array.PGArrayType "point[]"
instance Database.PostgreSQL.Typed.Types.PGType "lseg" => Database.PostgreSQL.Typed.Types.PGType "lseg[]"
instance Database.PostgreSQL.Typed.Types.PGType "lseg" => Database.PostgreSQL.Typed.Array.PGArrayType "lseg[]"
instance Database.PostgreSQL.Typed.Types.PGType "path" => Database.PostgreSQL.Typed.Types.PGType "path[]"
instance Database.PostgreSQL.Typed.Types.PGType "path" => Database.PostgreSQL.Typed.Array.PGArrayType "path[]"
instance Database.PostgreSQL.Typed.Types.PGType "box" => Database.PostgreSQL.Typed.Types.PGType "box[]"
instance Database.PostgreSQL.Typed.Types.PGType "box" => Database.PostgreSQL.Typed.Array.PGArrayType "box[]"
instance Database.PostgreSQL.Typed.Types.PGType "polygon" => Database.PostgreSQL.Typed.Types.PGType "polygon[]"
instance Database.PostgreSQL.Typed.Types.PGType "polygon" => Database.PostgreSQL.Typed.Array.PGArrayType "polygon[]"
instance Database.PostgreSQL.Typed.Types.PGType "line" => Database.PostgreSQL.Typed.Types.PGType "line[]"
instance Database.PostgreSQL.Typed.Types.PGType "line" => Database.PostgreSQL.Typed.Array.PGArrayType "line[]"
instance Database.PostgreSQL.Typed.Types.PGType "cidr" => Database.PostgreSQL.Typed.Types.PGType "cidr[]"
instance Database.PostgreSQL.Typed.Types.PGType "cidr" => Database.PostgreSQL.Typed.Array.PGArrayType "cidr[]"
instance Database.PostgreSQL.Typed.Types.PGType "real" => Database.PostgreSQL.Typed.Types.PGType "real[]"
instance Database.PostgreSQL.Typed.Types.PGType "real" => Database.PostgreSQL.Typed.Array.PGArrayType "real[]"
instance Database.PostgreSQL.Typed.Types.PGType "double precision" => Database.PostgreSQL.Typed.Types.PGType "double precision[]"
instance Database.PostgreSQL.Typed.Types.PGType "double precision" => Database.PostgreSQL.Typed.Array.PGArrayType "double precision[]"
instance Database.PostgreSQL.Typed.Types.PGType "abstime" => Database.PostgreSQL.Typed.Types.PGType "abstime[]"
instance Database.PostgreSQL.Typed.Types.PGType "abstime" => Database.PostgreSQL.Typed.Array.PGArrayType "abstime[]"
instance Database.PostgreSQL.Typed.Types.PGType "reltime" => Database.PostgreSQL.Typed.Types.PGType "reltime[]"
instance Database.PostgreSQL.Typed.Types.PGType "reltime" => Database.PostgreSQL.Typed.Array.PGArrayType "reltime[]"
instance Database.PostgreSQL.Typed.Types.PGType "tinterval" => Database.PostgreSQL.Typed.Types.PGType "tinterval[]"
instance Database.PostgreSQL.Typed.Types.PGType "tinterval" => Database.PostgreSQL.Typed.Array.PGArrayType "tinterval[]"
instance Database.PostgreSQL.Typed.Types.PGType "circle" => Database.PostgreSQL.Typed.Types.PGType "circle[]"
instance Database.PostgreSQL.Typed.Types.PGType "circle" => Database.PostgreSQL.Typed.Array.PGArrayType "circle[]"
instance Database.PostgreSQL.Typed.Types.PGType "money" => Database.PostgreSQL.Typed.Types.PGType "money[]"
instance Database.PostgreSQL.Typed.Types.PGType "money" => Database.PostgreSQL.Typed.Array.PGArrayType "money[]"
instance Database.PostgreSQL.Typed.Types.PGType "macaddr" => Database.PostgreSQL.Typed.Types.PGType "macaddr[]"
instance Database.PostgreSQL.Typed.Types.PGType "macaddr" => Database.PostgreSQL.Typed.Array.PGArrayType "macaddr[]"
instance Database.PostgreSQL.Typed.Types.PGType "inet" => Database.PostgreSQL.Typed.Types.PGType "inet[]"
instance Database.PostgreSQL.Typed.Types.PGType "inet" => Database.PostgreSQL.Typed.Array.PGArrayType "inet[]"
instance Database.PostgreSQL.Typed.Types.PGType "aclitem" => Database.PostgreSQL.Typed.Types.PGType "aclitem[]"
instance Database.PostgreSQL.Typed.Types.PGType "aclitem" => Database.PostgreSQL.Typed.Array.PGArrayType "aclitem[]"
instance Database.PostgreSQL.Typed.Types.PGType "bpchar" => Database.PostgreSQL.Typed.Types.PGType "bpchar[]"
instance Database.PostgreSQL.Typed.Types.PGType "bpchar" => Database.PostgreSQL.Typed.Array.PGArrayType "bpchar[]"
instance Database.PostgreSQL.Typed.Types.PGType "character varying" => Database.PostgreSQL.Typed.Types.PGType "character varying[]"
instance Database.PostgreSQL.Typed.Types.PGType "character varying" => Database.PostgreSQL.Typed.Array.PGArrayType "character varying[]"
instance Database.PostgreSQL.Typed.Types.PGType "date" => Database.PostgreSQL.Typed.Types.PGType "date[]"
instance Database.PostgreSQL.Typed.Types.PGType "date" => Database.PostgreSQL.Typed.Array.PGArrayType "date[]"
instance Database.PostgreSQL.Typed.Types.PGType "time without time zone" => Database.PostgreSQL.Typed.Types.PGType "time without time zone[]"
instance Database.PostgreSQL.Typed.Types.PGType "time without time zone" => Database.PostgreSQL.Typed.Array.PGArrayType "time without time zone[]"
instance Database.PostgreSQL.Typed.Types.PGType "timestamp without time zone" => Database.PostgreSQL.Typed.Types.PGType "timestamp without time zone[]"
instance Database.PostgreSQL.Typed.Types.PGType "timestamp without time zone" => Database.PostgreSQL.Typed.Array.PGArrayType "timestamp without time zone[]"
instance Database.PostgreSQL.Typed.Types.PGType "timestamp with time zone" => Database.PostgreSQL.Typed.Types.PGType "timestamp with time zone[]"
instance Database.PostgreSQL.Typed.Types.PGType "timestamp with time zone" => Database.PostgreSQL.Typed.Array.PGArrayType "timestamp with time zone[]"
instance Database.PostgreSQL.Typed.Types.PGType "interval" => Database.PostgreSQL.Typed.Types.PGType "interval[]"
instance Database.PostgreSQL.Typed.Types.PGType "interval" => Database.PostgreSQL.Typed.Array.PGArrayType "interval[]"
instance Database.PostgreSQL.Typed.Types.PGType "time with time zone" => Database.PostgreSQL.Typed.Types.PGType "time with time zone[]"
instance Database.PostgreSQL.Typed.Types.PGType "time with time zone" => Database.PostgreSQL.Typed.Array.PGArrayType "time with time zone[]"
instance Database.PostgreSQL.Typed.Types.PGType "bit" => Database.PostgreSQL.Typed.Types.PGType "bit[]"
instance Database.PostgreSQL.Typed.Types.PGType "bit" => Database.PostgreSQL.Typed.Array.PGArrayType "bit[]"
instance Database.PostgreSQL.Typed.Types.PGType "varbit" => Database.PostgreSQL.Typed.Types.PGType "varbit[]"
instance Database.PostgreSQL.Typed.Types.PGType "varbit" => Database.PostgreSQL.Typed.Array.PGArrayType "varbit[]"
instance Database.PostgreSQL.Typed.Types.PGType "numeric" => Database.PostgreSQL.Typed.Types.PGType "numeric[]"
instance Database.PostgreSQL.Typed.Types.PGType "numeric" => Database.PostgreSQL.Typed.Array.PGArrayType "numeric[]"
instance Database.PostgreSQL.Typed.Types.PGType "refcursor" => Database.PostgreSQL.Typed.Types.PGType "refcursor[]"
instance Database.PostgreSQL.Typed.Types.PGType "refcursor" => Database.PostgreSQL.Typed.Array.PGArrayType "refcursor[]"
instance Database.PostgreSQL.Typed.Types.PGType "regprocedure" => Database.PostgreSQL.Typed.Types.PGType "regprocedure[]"
instance Database.PostgreSQL.Typed.Types.PGType "regprocedure" => Database.PostgreSQL.Typed.Array.PGArrayType "regprocedure[]"
instance Database.PostgreSQL.Typed.Types.PGType "regoper" => Database.PostgreSQL.Typed.Types.PGType "regoper[]"
instance Database.PostgreSQL.Typed.Types.PGType "regoper" => Database.PostgreSQL.Typed.Array.PGArrayType "regoper[]"
instance Database.PostgreSQL.Typed.Types.PGType "regoperator" => Database.PostgreSQL.Typed.Types.PGType "regoperator[]"
instance Database.PostgreSQL.Typed.Types.PGType "regoperator" => Database.PostgreSQL.Typed.Array.PGArrayType "regoperator[]"
instance Database.PostgreSQL.Typed.Types.PGType "regclass" => Database.PostgreSQL.Typed.Types.PGType "regclass[]"
instance Database.PostgreSQL.Typed.Types.PGType "regclass" => Database.PostgreSQL.Typed.Array.PGArrayType "regclass[]"
instance Database.PostgreSQL.Typed.Types.PGType "regtype" => Database.PostgreSQL.Typed.Types.PGType "regtype[]"
instance Database.PostgreSQL.Typed.Types.PGType "regtype" => Database.PostgreSQL.Typed.Array.PGArrayType "regtype[]"
instance Database.PostgreSQL.Typed.Types.PGType "record" => Database.PostgreSQL.Typed.Types.PGType "record[]"
instance Database.PostgreSQL.Typed.Types.PGType "record" => Database.PostgreSQL.Typed.Array.PGArrayType "record[]"
instance Database.PostgreSQL.Typed.Types.PGType "cstring" => Database.PostgreSQL.Typed.Types.PGType "cstring[]"
instance Database.PostgreSQL.Typed.Types.PGType "cstring" => Database.PostgreSQL.Typed.Array.PGArrayType "cstring[]"
instance Database.PostgreSQL.Typed.Types.PGType "uuid" => Database.PostgreSQL.Typed.Types.PGType "uuid[]"
instance Database.PostgreSQL.Typed.Types.PGType "uuid" => Database.PostgreSQL.Typed.Array.PGArrayType "uuid[]"
instance Database.PostgreSQL.Typed.Types.PGType "txid_snapshot" => Database.PostgreSQL.Typed.Types.PGType "txid_snapshot[]"
instance Database.PostgreSQL.Typed.Types.PGType "txid_snapshot" => Database.PostgreSQL.Typed.Array.PGArrayType "txid_snapshot[]"
instance Database.PostgreSQL.Typed.Types.PGType "tsvector" => Database.PostgreSQL.Typed.Types.PGType "tsvector[]"
instance Database.PostgreSQL.Typed.Types.PGType "tsvector" => Database.PostgreSQL.Typed.Array.PGArrayType "tsvector[]"
instance Database.PostgreSQL.Typed.Types.PGType "tsquery" => Database.PostgreSQL.Typed.Types.PGType "tsquery[]"
instance Database.PostgreSQL.Typed.Types.PGType "tsquery" => Database.PostgreSQL.Typed.Array.PGArrayType "tsquery[]"
instance Database.PostgreSQL.Typed.Types.PGType "gtsvector" => Database.PostgreSQL.Typed.Types.PGType "gtsvector[]"
instance Database.PostgreSQL.Typed.Types.PGType "gtsvector" => Database.PostgreSQL.Typed.Array.PGArrayType "gtsvector[]"
instance Database.PostgreSQL.Typed.Types.PGType "regconfig" => Database.PostgreSQL.Typed.Types.PGType "regconfig[]"
instance Database.PostgreSQL.Typed.Types.PGType "regconfig" => Database.PostgreSQL.Typed.Array.PGArrayType "regconfig[]"
instance Database.PostgreSQL.Typed.Types.PGType "regdictionary" => Database.PostgreSQL.Typed.Types.PGType "regdictionary[]"
instance Database.PostgreSQL.Typed.Types.PGType "regdictionary" => Database.PostgreSQL.Typed.Array.PGArrayType "regdictionary[]"
instance Database.PostgreSQL.Typed.Types.PGType "int4range" => Database.PostgreSQL.Typed.Types.PGType "int4range[]"
instance Database.PostgreSQL.Typed.Types.PGType "int4range" => Database.PostgreSQL.Typed.Array.PGArrayType "int4range[]"
instance Database.PostgreSQL.Typed.Types.PGType "numrange" => Database.PostgreSQL.Typed.Types.PGType "numrange[]"
instance Database.PostgreSQL.Typed.Types.PGType "numrange" => Database.PostgreSQL.Typed.Array.PGArrayType "numrange[]"
instance Database.PostgreSQL.Typed.Types.PGType "tsrange" => Database.PostgreSQL.Typed.Types.PGType "tsrange[]"
instance Database.PostgreSQL.Typed.Types.PGType "tsrange" => Database.PostgreSQL.Typed.Array.PGArrayType "tsrange[]"
instance Database.PostgreSQL.Typed.Types.PGType "tstzrange" => Database.PostgreSQL.Typed.Types.PGType "tstzrange[]"
instance Database.PostgreSQL.Typed.Types.PGType "tstzrange" => Database.PostgreSQL.Typed.Array.PGArrayType "tstzrange[]"
instance Database.PostgreSQL.Typed.Types.PGType "daterange" => Database.PostgreSQL.Typed.Types.PGType "daterange[]"
instance Database.PostgreSQL.Typed.Types.PGType "daterange" => Database.PostgreSQL.Typed.Array.PGArrayType "daterange[]"
instance Database.PostgreSQL.Typed.Types.PGType "int8range" => Database.PostgreSQL.Typed.Types.PGType "int8range[]"
instance Database.PostgreSQL.Typed.Types.PGType "int8range" => Database.PostgreSQL.Typed.Array.PGArrayType "int8range[]"

module Database.PostgreSQL.Typed

-- | PGException is thrown upon encountering an <a>ErrorResponse</a> with
--   severity of ERROR, FATAL, or PANIC. It holds the message of the error.
data PGError
PGError :: MessageFields -> PGError
[pgErrorFields] :: PGError -> MessageFields

-- | Information for how to connect to a database, to be passed to
--   <a>pgConnect</a>.
data PGDatabase
PGDatabase :: HostName -> PortID -> ByteString -> ByteString -> [(ByteString, ByteString)] -> Bool -> (MessageFields -> IO ()) -> PGDatabase

-- | The hostname (ignored if <a>pgDBPort</a> is <a>UnixSocket</a>)
[pgDBHost] :: PGDatabase -> HostName

-- | The port, likely either <tt>PortNumber 5432</tt> or <tt>UnixSocket
--   "/tmp/.s.PGSQL.5432"</tt>
[pgDBPort] :: PGDatabase -> PortID

-- | The name of the database
[pgDBName] :: PGDatabase -> ByteString
[pgDBUser, pgDBPass] :: PGDatabase -> ByteString

-- | Extra parameters to set for the connection (e.g., (<a>TimeZone</a>,
--   <a>UTC</a>))
[pgDBParams] :: PGDatabase -> [(ByteString, ByteString)]

-- | Log all low-level server messages
[pgDBDebug] :: PGDatabase -> Bool

-- | How to log server notice messages (e.g., <tt>print . PGError</tt>)
[pgDBLogMessage] :: PGDatabase -> MessageFields -> IO ()

-- | A database connection with sane defaults: localhost:5432:postgres
defaultPGDatabase :: PGDatabase

-- | An established connection to the PostgreSQL server. These objects are
--   not thread-safe and must only be used for a single request at a time.
data PGConnection

-- | Connect to a PostgreSQL server.
pgConnect :: PGDatabase -> IO PGConnection

-- | Disconnect cleanly from the PostgreSQL server.
pgDisconnect :: PGConnection -> IO ()

-- | Specify an alternative database to use during compilation. This lets
--   you override the default connection parameters that are based on TPG
--   environment variables. This should be called as a top-level
--   declaration and produces no code. It uses <a>pgReconnect</a> so is
--   safe to call multiple times with the same database.
useTPGDatabase :: PGDatabase -> DecsQ

-- | A quasi-quoter for PGSQL queries.
--   
--   Used in expression context, it may contain any SQL statement
--   <tt>[pgSQL|SELECT ...|]</tt>. The statement may contain
--   PostgreSQL-style placeholders (<tt>$1</tt>, <tt>$2</tt>, ...) or
--   in-line placeholders (<tt>${1+1}</tt>) containing any valid Haskell
--   expression (except <tt>{}</tt>). It will be replaced by a
--   <a>PGQuery</a> object that can be used to perform the SQL statement.
--   If there are more <tt>$N</tt> placeholders than expressions, it will
--   instead be a function accepting the additional parameters and
--   returning a <a>PGQuery</a>.
--   
--   Ideally, this mimics postgres' SQL parsing, so that placeholders and
--   expressions will only be expanded when they are in valid positions
--   (i.e., not inside quoted strings). Since <tt>${</tt> is not valid SQL
--   otherwise, there should be no need to escape it.
--   
--   The statement may start with one of more special flags affecting the
--   interpretation:
--   
--   <ul>
--   <li><i><tt>?</tt></i> To disable nullability inference, treating all
--   result values as nullable, thus returning <a>Maybe</a> values
--   regardless of inferred nullability. This makes unexpected NULL errors
--   impossible.</li>
--   <li><i><tt>!</tt></i> To disable nullability inference, treating all
--   result values as <i>not</i> nullable, thus only returning <a>Maybe</a>
--   where requested. This is makes unexpected NULL errors more
--   likely.</li>
--   <li><i><tt>$</tt></i> To create a <a>PGPreparedQuery</a> (using
--   placeholder parameters) rather than the default <a>PGSimpleQuery</a>
--   (using literal substitution).</li>
--   <li><i><tt>$(type,...)</tt></i> To specify specific types for a
--   prepared query (see
--   <a>http://www.postgresql.org/docs/current/static/sql-prepare.html</a>
--   for details), rather than inferring parameter types by default.</li>
--   <li><i><tt>#</tt></i> Only do literal <tt>${}</tt> substitution using
--   <a>pgSubstituteLiterals</a> and return a string, not a query.</li>
--   </ul>
--   
--   <a>pgSQL</a> can also be used at the top-level to execute SQL
--   statements at compile-time (without any parameters and ignoring
--   results). Here the query can only be prefixed with <tt>!</tt> to make
--   errors non-fatal.
--   
--   If you want to construct queries out of string variables rather than
--   quasi-quoted strings, you can use the lower-level <a>makePGQuery</a>
--   instead.
pgSQL :: QuasiQuoter

-- | Run a query and return a list of row results.
pgQuery :: PGQuery q a => PGConnection -> q -> IO [a]

-- | Execute a query that does not return results. Return the number of
--   rows affected (or -1 if not known).
pgExecute :: PGQuery q () => PGConnection -> q -> IO Int

-- | Wrap a computation in a <a>pgBegin</a>, <a>pgCommit</a> block, or
--   <a>pgRollback</a> on exception.
pgTransaction :: PGConnection -> IO a -> IO a
