HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulepg-entity-0.0.4.4Haskell2010

Database.PostgreSQL.Entity.Internal

Internal helpers used to implement the high-level API and SQL combinators.

You can re-use those building blocks freely to create your own wrappers.

  • 22 values

Helpers

22 declarations
valueisNotNull :: Vector Field -> Text
#

Produce an IS NOT NULL statement given a vector of fields

Example1 expression
isNotNull [ [field| possibly_empty |] ]"\"possibly_empty\" IS NOT NULL"
Example1 expression
isNotNull [[field| possibly_empty |], [field| that_one_too |]]"\"possibly_empty\" IS NOT NULL AND \"that_one_too\" IS NOT NULL"
valueisNull :: Vector Field -> Text
#

Produce an IS NULL statement given a vector of fields

Example1 expression
isNull [ [field| possibly_empty |] ]"\"possibly_empty\" IS NULL"
Example1 expression
isNull [[field| possibly_empty |], [field| that_one_too |]]"\"possibly_empty\" IS NULL AND \"that_one_too\" IS NULL"
valueinParens :: Text -> Text
#

Wrap the given text between parentheses

Examples

Example1 expression
inParens "wrap me!""(wrap me!)"
valuequoteName :: Text -> Text
#

Wrap the given text between double quotes

Examples

Example1 expression
quoteName "meow.""\"meow.\""
valueliteral :: Text -> Text
#

Wrap the given text between single quotes, for literal text in an SQL query.

Examples

Example1 expression
literal "meow.""'meow.'"
valuegetTableName :: Entity e => Text
#

Safe getter that quotes a table name

Examples

Example2 expressions
getTableName @Author"\"authors\""getTableName @Tags"public.\"tags\""
valuegetFieldName :: Field -> Text
#

Accessor to the name of a field, with quotation.

Example1 expression
getFieldName ([field| author_id |])"\"author_id\""
valuegetPrimaryKey :: Entity e => Text
#

Safe getter that quotes a table's primary key

Examples

Example2 expressions
getPrimaryKey @Author"\"author_id\""getPrimaryKey @Tags"\"category\""
valueexpandFields :: Entity e => Text
#

Produce a comma-separated list of an entity's fields.

Examples

Example1 expression
expandFields @BlogPost"\"blogpost_id\", \"author_id\", \"uuid_list\", \"title\", \"content\", \"created_at\""

Produce a comma-separated list of an entity's fields, qualified with the table name

Examples

Example1 expression
expandQualifiedFields @BlogPost"blogposts.\"blogpost_id\", blogposts.\"author_id\", blogposts.\"uuid_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\""

Produce a comma-separated list of an entity's fields, qualified with an arbitrary prefix

Examples

Example1 expression
expandQualifiedFields' (fields @BlogPost) "legacy""legacy.\"blogpost_id\", legacy.\"author_id\", legacy.\"uuid_list\", legacy.\"title\", legacy.\"content\", legacy.\"created_at\""
valuequalifyField :: Entity e => Field -> Text
#

Take a prefix and a vector of fields, and qualifies each field with the prefix

Examples

Example1 expression
qualifyField @Author [field| name |]"authors.\"name\""

Take a prefix and a vector of fields, and qualifies each field with the prefix

Examples

Example1 expression
qualifyFields "legacy" (fields @BlogPost)[Field "legacy.\"blogpost_id\"" Nothing,Field "legacy.\"author_id\"" Nothing,Field "legacy.\"uuid_list\"" Nothing,Field "legacy.\"title\"" Nothing,Field "legacy.\"content\"" Nothing,Field "legacy.\"created_at\"" Nothing]
valueplaceholder :: Field -> Text
#

Produce a placeholder of the form "field" = ? with an optional type annotation.

Examples

Example1 expression
placeholder [field| id |]"\"id\" = ?"
Example1 expression
placeholder $ [field| ids |]"\"ids\" = ?"
Example1 expression
fmap placeholder $ fields @BlogPost["\"blogpost_id\" = ?","\"author_id\" = ?","\"uuid_list\" = ?","\"title\" = ?","\"content\" = ?","\"created_at\" = ?"]
valueplaceholder' :: Entity e => Field -> Text
#

Produce a placeholder of the form table."field" = ? with an optional type annotation.

Examples

Example1 expression
placeholder' @BlogPost [field| id |]"blogposts.\"id\" = ?"
Example1 expression
placeholder' @BlogPost $ [field| ids |]"blogposts.\"ids\" = ?"

Generate an appropriate number of “?” placeholders given a vector of fields.

Used to generate INSERT queries.

Examples

Example1 expression
generatePlaceholders $ fields @BlogPost"?, ?, ?, ?, ?, ?"
valuetextToQuery :: Text -> Query
#

Since the Query type has an IsString instance, the process of converting from Text to String to Query is factored into this function

⚠ This may be dangerous and an unregulated usage of this function may expose to you SQL injection attacks @since 0.0.1.0

valuequeryToText :: Query -> Text
#

For cases where combinator composition is tricky, we can safely get back to a Text string from a Query

⚠ This may be dangerous and an unregulated usage of this function may expose to you SQL injection attacks @since 0.0.1.0

The intercalateVector function takes a Text and a Vector Text and concatenates the vector after interspersing the first argument between each element of the list.

Examples

Example1 expression
intercalateVector "~" [][]
Example1 expression
intercalateVector "~" ["nyan"]["nyan"]
Example1 expression
intercalateVector "~" ["nyan", "nyan", "nyan"]["nyan","~","nyan","~","nyan"]