hdbi-postgresql-1.0.0: PostgreSQL driver for hdbi

Portabilityportable
Stabilityexperimental
MaintainerAleksey Uymanov <s9gf4ult@gmail.com>
Safe HaskellNone

Database.HDBI.PostgreSQL.Implementation

Contents

Description

 

Synopsis

Types

data PostgreConnection Source

Constructors

PostgreConnection 

Fields

postNative :: MVar (Maybe Connection)

LibPQ connection if established

postStatements :: ChildList PostgreStatement

List of weak refs to statements to finalize on disconnect

postConnString :: Text

Original connection string

data PGStatementState Source

Constructors

STNew

Newly created or reseted statement

STExecuted

Just executed statement

Fields

pgstResult :: !Result

The result to fetch data from

STFetching

Fetching rows is in progress

Fields

pgstResult :: !Result

The result to fetch data from

pgstColumns :: !Column

Columns count

pgstFormats :: ![Format]
 
pgstTypes :: ![Oid]
 
pgstTuples :: !Row

Tuples in result

pgstCurrent :: !Row

Row number waiting to fetch

STFinished

Statement is finished, can still be reseted

data PostgreStatement Source

Constructors

PostgreStatement 

Fields

stQuery :: Query

Initial query

stConnection :: PostgreConnection

Connection this statement working with

stState :: MVar PGStatementState

State of statement

Connection functions

connectPostgreSQLSource

Arguments

:: Text

Connection string according to the documentation

-> IO PostgreConnection 

Establish new PostgreSQL connection

withPGConnectionSource

Arguments

:: 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

convert native LibPQ data representation to SqlValue. Now support just Text format completely. Maybe binary protocol will be added in future versions.

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