| Copyright | (c) digitally induced GmbH 2025 |
|---|---|
| Safe Haskell | None |
| Language | GHC2021 |
IHP.Hasql.Encoders
Contents
Description
This module provides orphan DefaultParamEncoder instances for types that
hasql-implicits doesn't support out of the box, most importantly Int.
These instances are needed because hasql-implicits only provides instances for
fixed-width integer types (Int16, Int32, Int64), not Haskell's
platform-dependent Int. Since most IHP applications use Int for
integer columns, we provide these instances to make the transition seamless.
Synopsis
- class ToSnippetParams a where
- toSnippetParams :: a -> [Snippet]
- sqlToSnippet :: ByteString -> [Snippet] -> Snippet
Documentation
class ToSnippetParams a where Source #
Converts parameter tuples into a list of hasql Snippet values.
This mirrors postgresql-simple's ToRow typeclass, allowing sqlQuery and sqlExec
to use hasql's native parameterized queries instead of formatQuery.
Methods
toSnippetParams :: a -> [Snippet] Source #
Instances
sqlToSnippet :: ByteString -> [Snippet] -> Snippet Source #
Converts a SQL query with ? placeholders and a list of Snippet parameters
into a single Snippet with native hasql $1, $2, ... parameterization.
This mirrors postgresql-simple's ? placeholder convention.
Example:
sqlToSnippet "SELECT * FROM users WHERE id = ? AND name = ?" [Snippet.param id, Snippet.param name] -- becomes: Snippet.sql "SELECT * FROM users WHERE id = " <> Snippet.param id <> Snippet.sql " AND name = " <> Snippet.param name
Orphan instances
| DefaultParamEncoder Inet Source # | Encode |
Methods | |
| DefaultParamEncoder Interval Source # | Encode |
Methods | |
| DefaultParamEncoder Point Source # | Encode |
Methods | |
| DefaultParamEncoder Polygon Source # | Encode |
Methods | |
| DefaultParamEncoder Tsvector Source # | Encode |
Methods | |
| DefaultParamEncoder Integer Source # | Encode |
Methods | |
| DefaultParamEncoder Int Source # | Encode This treats Haskell's |
Methods | |
| PrimaryKey table ~ UUID => DefaultParamEncoder (Id' table) Source # | Encode |
Methods defaultParam :: NullableOrNot Value (Id' table) Source # | |
| DefaultParamEncoder (Binary ByteString) Source # | Encode 'Binary ByteString' as PostgreSQL bytea IHP wraps bytea columns in Binary, so we need to unwrap before encoding |
Methods defaultParam :: NullableOrNot Value (Binary ByteString) Source # | |
| DefaultParamEncoder (Vector Int) Source # | Encode 'Vector Int' as PostgreSQL int8[] (bigint array) |
Methods | |
| PrimaryKey table ~ UUID => DefaultParamEncoder (Maybe (Id' table)) Source # | Encode 'Maybe (Id' table)' for nullable foreign keys |
Methods defaultParam :: NullableOrNot Value (Maybe (Id' table)) Source # | |
| DefaultParamEncoder (Maybe (Binary ByteString)) Source # | Encode 'Maybe (Binary ByteString)' as nullable PostgreSQL bytea |
Methods defaultParam :: NullableOrNot Value (Maybe (Binary ByteString)) Source # | |
| DefaultParamEncoder (Maybe Inet) Source # | Encode 'Maybe Inet' as nullable PostgreSQL inet |
Methods | |
| DefaultParamEncoder (Maybe Interval) Source # | Encode 'Maybe Interval' as nullable PostgreSQL interval |
Methods defaultParam :: NullableOrNot Value (Maybe Interval) Source # | |
| DefaultParamEncoder (Maybe Point) Source # | Encode 'Maybe Point' as nullable PostgreSQL point |
Methods | |
| DefaultParamEncoder (Maybe Polygon) Source # | Encode 'Maybe Polygon' as nullable PostgreSQL polygon |
Methods defaultParam :: NullableOrNot Value (Maybe Polygon) Source # | |
| DefaultParamEncoder (Maybe Tsvector) Source # | Encode 'Maybe Tsvector' as nullable PostgreSQL tsvector |
Methods defaultParam :: NullableOrNot Value (Maybe Tsvector) Source # | |
| DefaultParamEncoder (Maybe Integer) Source # | Encode 'Maybe Integer' as nullable PostgreSQL int8 |
Methods defaultParam :: NullableOrNot Value (Maybe Integer) Source # | |
| DefaultParamEncoder (Maybe Int) Source # | Encode 'Maybe Int' as nullable PostgreSQL int8 |
Methods | |
| PrimaryKey table ~ UUID => DefaultParamEncoder [Id' table] Source # | Encode list of |
Methods defaultParam :: NullableOrNot Value [Id' table] Source # | |
| PrimaryKey table ~ UUID => DefaultParamEncoder [Maybe (Id' table)] Source # | Encode '[Maybe (Id' table)]' for filterWhereIn with nullable foreign keys |
Methods defaultParam :: NullableOrNot Value [Maybe (Id' table)] Source # | |
| DefaultParamEncoder [Maybe Int] Source # | Encode '[Maybe Int]' as PostgreSQL int8[] with nullable elements |
Methods | |
| (PrimaryKey a ~ UUID, PrimaryKey b ~ UUID) => DefaultParamEncoder [(Id' a, Id' b)] Source # | Encode '[(Id' a, Id' b)]' as PostgreSQL array of composite types Used by filterWhereIdIn for tables with composite primary keys of two Id columns |
Methods defaultParam :: NullableOrNot Value [(Id' a, Id' b)] Source # | |
| DefaultParamEncoder [(UUID, UUID)] Source # | Encode '[(UUID, UUID)]' as PostgreSQL array of composite types Used by filterWhereIdIn for tables with composite primary keys of two UUIDs |
Methods defaultParam :: NullableOrNot Value [(UUID, UUID)] Source # | |
| DefaultParamEncoder [Int] Source # | Encode '[Int]' as PostgreSQL int8[] (bigint array) |
Methods defaultParam :: NullableOrNot Value [Int] Source # | |
| (PrimaryKey a ~ UUID, PrimaryKey b ~ UUID) => DefaultParamEncoder (Id' a, Id' b) Source # | Encode '(Id' a, Id' b)' as PostgreSQL composite/record type Used for composite primary keys with two Id columns (where both resolve to UUID) |
Methods defaultParam :: NullableOrNot Value (Id' a, Id' b) Source # | |
| DefaultParamEncoder (UUID, UUID) Source # | Encode '(UUID, UUID)' as PostgreSQL composite/record type Used for composite primary keys with two UUID columns |
Methods defaultParam :: NullableOrNot Value (UUID, UUID) Source # | |