Portability | portable |
---|---|
Stability | experimental |
Maintainer | Aleksey Uymanov <s9gf4ult@gmail.com> |
Safe Haskell | None |
- data PostgreConnection = PostgreConnection {}
- data PGStatementState
- = STNew
- | STExecuted {
- pgstResult :: !Result
- | STFetching {
- pgstResult :: !Result
- pgstColumns :: !Column
- pgstFormats :: ![Format]
- pgstTypes :: ![Oid]
- pgstTuples :: !Row
- pgstCurrent :: !Row
- | STFinished
- data PostgreStatement = PostgreStatement {}
- connectPostgreSQL :: Text -> IO PostgreConnection
- withPGConnection :: PostgreConnection -> (Connection -> IO a) -> IO a
- sqlValueToNative :: SqlValue -> Maybe (Oid, ByteString, Format)
- formatUTC :: UTCTime -> ByteString
- formatDay :: Day -> ByteString
- formatT :: TimeOfDay -> ByteString
- formatDT :: LocalTime -> ByteString
- formatBits :: Word64 -> ByteString
- o2b :: Oid -> BuiltinType
- nativeToSqlValue :: ByteString -> Format -> Oid -> IO SqlValue
- parseT :: ByteString -> TimeOfDay
- parseDT :: ByteString -> LocalTime
- parseD :: ByteString -> Day
- parseUTC :: ByteString -> UTCTime
- parseBit :: ByteString -> Word64
- throwErrorMessage :: Connection -> IO a
- getPGResult :: Connection -> Maybe Result -> IO Result
- throwResultError :: Result -> IO a
- pgRun :: PostgreConnection -> Query -> [SqlValue] -> IO Result
- pgRunRaw :: PostgreConnection -> Query -> IO Result
- pgRunMany :: PostgreConnection -> Query -> [[SqlValue]] -> IO ()
- pgstGetResult :: String -> PGStatementState -> Result
Types
data PostgreConnection Source
PostgreConnection | |
|
data PGStatementState Source
STNew | Newly created or reseted statement |
STExecuted | Just executed statement |
| |
STFetching | Fetching rows is in progress |
| |
STFinished | Statement is finished, can still be reseted |
data PostgreStatement Source
PostgreStatement | |
|
Connection functions
:: Text | Connection string according to the documentation |
-> IO PostgreConnection |
Establish new PostgreSQL connection
:: PostgreConnection | |
-> (Connection -> IO a) | action to execute with native LibPQ connection |
-> IO a |
If connection is opened then execute an action, else throw an error.
Data manipulating functions
sqlValueToNative :: SqlValue -> Maybe (Oid, ByteString, Format)Source
Convert SqlValue to native libPQ data representation
formatUTC :: UTCTime -> ByteStringSource
Format UTCTime as ByteString
formatDay :: Day -> ByteStringSource
Format Day as ByteString
formatT :: TimeOfDay -> ByteStringSource
format TimeOfDay to ByteString
formatDT :: LocalTime -> ByteStringSource
format LocalTime as ByteString
formatBits :: Word64 -> ByteStringSource
format Word64 as bit field (001010111)
o2b :: Oid -> BuiltinTypeSource
convert Oid
to BuiltinType
if not converted then throw an error
nativeToSqlValue :: ByteString -> Format -> Oid -> IO SqlValueSource
parseT :: ByteString -> TimeOfDaySource
parse ByteString as TimeOfDay
parseDT :: ByteString -> LocalTimeSource
parse ByteString as LocalTime
parseD :: ByteString -> DaySource
parse ByteString as Day
parseUTC :: ByteString -> UTCTimeSource
parse ByteString as UTCTime
parseBit :: ByteString -> Word64Source
parse ByteString as 64 bit field (00101110) and convert to Word64
Miscellaneous functions
throwErrorMessage :: Connection -> IO aSource
get last error code and error message from connection and throw proper
SqlError
getPGResult :: Connection -> Maybe Result -> IO ResultSource
Throws appropriate SqlError when no Result
is not given, or it is in
wrong status
throwResultError :: Result -> IO aSource
Get error message from the result and throw it as SqlError
pgstGetResult :: String -> PGStatementState -> ResultSource
get Result from PGStatementState
if can. If can not throw an error with specified message