postgresql-simple-0.2.4.1: Mid-Level PostgreSQL client library

Portability | portable
Stability | experimental
Maintainer | Leon P Smith <leon@melding-monads.com>
Safe Haskell | None

Database.PostgreSQL.Simple.Internal

Description

Internal bits. This interface is less stable and can change at any time. In particular this means that while the rest of the postgresql-simple package endeavors to follow the package versioning policy, this module does not. Also, at the moment there are things in here that aren't particularly internal and are exported elsewhere; these will eventually disappear from this module.

Synopsis

- data Field = Field {
  - result :: !Result
  - column :: !Column
  - typename :: !ByteString
  }
- name :: Field -> Maybe ByteString
- tableOid :: Field -> Oid
- tableColumn :: Field -> Int
- format :: Field -> Format
- typeOid :: Field -> Oid
- data Connection = Connection {
  - connectionHandle :: !(MVar Connection)
  - connectionObjects :: !(MVar (IntMap ByteString))
  }
- data SqlType
  - = Builtin BuiltinType
  - | Other Oid
- data SqlError = SqlError {
  - sqlState :: ByteString
  - sqlNativeError :: Int
  - sqlErrorMsg :: ByteString
  }
- data QueryError = QueryError {
  - qeMessage :: String
  - qeQuery :: Query
  }
- data ConnectInfo = ConnectInfo {
  - connectHost :: String
  - connectPort :: Word16
  - connectUser :: String
  - connectPassword :: String
  - connectDatabase :: String
  }
- defaultConnectInfo :: ConnectInfo
- connect :: ConnectInfo -> IO Connection
- connectPostgreSQL :: ByteString -> IO Connection
- postgreSQLConnectionString :: ConnectInfo -> ByteString
- oid2int :: Oid -> Int
- exec :: Connection -> ByteString -> IO Result
- execute_ :: Connection -> Query -> IO Int64
- finishExecute :: Connection -> Query -> Result -> IO Int64
- throwResultError :: ByteString -> Result -> ExecStatus -> IO a
- disconnectedError :: SqlError
- withConnection :: Connection -> (Connection -> IO a) -> IO a
- close :: Connection -> IO ()
- newNullConnection :: IO Connection
- data Row = Row {
  - row :: !Row
  - typenames :: !(Vector ByteString)
  - rowresult :: !Result
  }
- newtype RowParser a = RP {
  - unRP :: ReaderT Row (StateT Column Ok) a
  }
- getvalue :: Result -> Row -> Column -> Maybe ByteString
- nfields :: Result -> Column

# Documentation

data Field

A Field represents metadata about a particular field

You don't particularly want to retain these structures for a long period of time, as they will retain the entire query result, not just the field metadata

Constructors

Field |

Fields

result :: !Result
column :: !Column
typename :: !ByteString

name :: Field -> Maybe ByteString

tableOid :: Field -> Oid

tableColumn :: Field -> Int

format :: Field -> Format

typeOid :: Field -> Oid

data Connection

Constructors

Connection |

Fields

connectionHandle :: !(MVar Connection)
connectionObjects :: !(MVar (IntMap ByteString))

data SqlType

Constructors

Builtin BuiltinType |
Other Oid |

data SqlError

Constructors

SqlError |

Fields

sqlState :: ByteString
sqlNativeError :: Int
sqlErrorMsg :: ByteString

Instances

Show SqlError |
Typeable SqlError |
Exception SqlError |

data QueryError

Exception thrown if `query` is used to perform an `INSERT`-like operation, or `execute` is used to perform a `SELECT`-like operation.

Constructors

QueryError |

Fields

qeMessage :: String
qeQuery :: Query

Instances

Eq QueryError |
Show QueryError |
Typeable QueryError |
Exception QueryError |

data ConnectInfo

Constructors

ConnectInfo |

Fields

connectHost :: String
connectPort :: Word16
connectUser :: String
connectPassword :: String
connectDatabase :: String

Instances

Eq ConnectInfo |
Read ConnectInfo |
Show ConnectInfo |
Typeable ConnectInfo |

defaultConnectInfo :: ConnectInfo

Default information for setting up a connection.

Defaults are as follows:

- Server on `localhost`
- Port on `5432`
- User `postgres`
- No password
- Database `postgres`

Use as in the following example:

     connect defaultConnectInfo { connectHost = "db.example.com" }

connect :: ConnectInfo -> IO Connection

Connect with the given username to the given database. Will throw an exception if it cannot connect.

connectPostgreSQL :: ByteString -> IO Connection

Attempt to make a connection based on a libpq connection string. See http://www.postgresql.org/docs/9.1/static/libpq-connect.html for more information.

postgreSQLConnectionString :: ConnectInfo -> ByteString

Turns a `ConnectInfo` data structure into a libpq connection string.

oid2int :: Oid -> Int

exec :: Connection -> ByteString -> IO Result

execute_ :: Connection -> Query -> IO Int64

A version of `execute` that does not perform query substitution.

finishExecute :: Connection -> Query -> Result -> IO Int64

throwResultError :: ByteString -> Result -> ExecStatus -> IO a

disconnectedError :: SqlError

withConnection :: Connection -> (Connection -> IO a) -> IO a

Atomically perform an action with the database handle, if there is one.

close :: Connection -> IO ()

newNullConnection :: IO Connection

data Row

Constructors

Row |

Fields

row :: !Row
typenames :: !(Vector ByteString)
rowresult :: !Result

newtype RowParser a

Constructors

RP |

Fields

unRP :: ReaderT Row (StateT Column Ok) a

Instances

Monad RowParser |
Functor RowParser |
Applicative RowParser |
Alternative RowParser |

getvalue :: Result -> Row -> Column -> Maybe ByteString

nfields :: Result -> Column