| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Postgres
Contents
Description
Functions for running Postgres queries.
Synopsis
- data Connection
- connection :: Settings -> Acquire Connection
- data Settings
- decoder :: Decoder Settings
- data Query row
- data Error
- = Timeout Float
- | UniqueViolation Text
- | Other Text [Context]
- sql :: QuasiQuoter
- doQuery :: HasCallStack => Connection -> Query row -> (Result Error [row] -> Task e a) -> Task e a
- transaction :: Connection -> (Connection -> Task e a) -> Task e a
- inTestTransaction :: Connection -> (Connection -> Task x a) -> Task x a
- class PGType t => PGColumn (t :: Symbol) a where
- class PGType t => PGParameter (t :: Symbol) a where
Documentation
data Connection Source #
A connection to Postgres. You need this for making Postgres queries.
connection :: Settings -> Acquire Connection Source #
Create a Connection.
Postgres connection details. You can use decoder to create one of these.
Instances
decoder :: Decoder Settings Source #
Create a Settings value by reading settings from environment values.
environment variable- PGHOST
default value- localhost
environment variable- PGPORT
default value- 5432
environment variable- PGDATABASE
default value- postgresql
environment variable- PGUSER
default value- postgresql
environment variable- PGPASSWORD
default valueenvironment variable- PG_POOL_SIZE
default value- 500
environment variable- PG_POOL_STRIPES
default value- 1
environment variable- PG_POOL_MAX_IDLE_TIME
default value- 3600
environment variable- PG_QUERY_TIMEOUT_SECONDS
default value- 5
A postgres query might fail with one of these errors.
Constructors
| Timeout Float | |
| UniqueViolation Text | |
| Other Text [Context] |
Instances
| Show Error Source # | |
| Exception Error Source # | |
Defined in Postgres.Error Methods toException :: Error -> SomeException # fromException :: SomeException -> Maybe Error # displayException :: Error -> String # | |
sql :: QuasiQuoter Source #
Quasi-quoter that allows you to write plain SQL in your code. The query is checked at compile-time using the 'postgresql-typed' library.
Requires the QuasiQuotes language extension to be enabled.
[sql| SELECT name, breed FROM doggos |]
doQuery :: HasCallStack => Connection -> Query row -> (Result Error [row] -> Task e a) -> Task e a Source #
Run a query against MySql. This will return a list of rows, where the row
type is a tuple containing the queried columns.
doQuery
connection
[sql| SELECT name, breed FROM doggos |]
(\result ->
case result of
Ok rows -> Task.succeed rows
Err err -> Task.fail err
)transaction :: Connection -> (Connection -> Task e a) -> Task e a Source #
Perform a database transaction.
inTestTransaction :: Connection -> (Connection -> Task x a) -> Task x a Source #
Run code in a transaction, then roll that transaction back. Useful in tests that shouldn't leave anything behind in the DB.
class PGType t => PGColumn (t :: Symbol) a where #
A PGColumn t a instance describes how te decode a PostgreSQL type t to a.
Methods
pgDecode :: PGTypeID t -> PGTextValue -> a #
Decode the PostgreSQL text representation into a value.
Instances
class PGType t => PGParameter (t :: Symbol) a where #
A PGParameter t a instance describes how to encode a PostgreSQL type t from a.
Methods
pgEncode :: PGTypeID t -> a -> PGTextValue #
Encode a value to a PostgreSQL text representation.
Instances
Orphan instances
| PGType "jsonb" => PGArrayType "jsonb[]" Source # | |
Associated Types type PGElemType "jsonb[]" :: Symbol # Methods pgArrayElementType :: PGTypeID "jsonb[]" -> PGTypeID (PGElemType "jsonb[]") # pgArrayDelim :: PGTypeID "jsonb[]" -> Char # | |
| PGType "jsonb" => PGType "jsonb[]" Source # | |