Safe Haskell | None |
---|---|
Language | Haskell2010 |
Functions for running Postgres queries.
Synopsis
- data Connection
- connection :: Settings -> Acquire Connection
- data Settings
- decoder :: Decoder Settings
- data Query row
- data Error
- 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.
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 value
environment 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.
Instances
Show Error Source # | |
Exception Error Source # | |
Defined in Postgres.Error 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
.
Instances
class PGType t => PGParameter (t :: Symbol) a where #
A PGParameter t a
instance describes how to encode a PostgreSQL type t
from a
.
Instances
Orphan instances
PGType "jsonb" => PGArrayType "jsonb[]" Source # | |
type PGElemType "jsonb[]" :: Symbol # pgArrayElementType :: PGTypeID "jsonb[]" -> PGTypeID (PGElemType "jsonb[]") # pgArrayDelim :: PGTypeID "jsonb[]" -> Char # | |
PGType "jsonb" => PGType "jsonb[]" Source # | |