| Copyright | © Clément Delafargue 2018 Théophile Choutri 2021 |
|---|---|
| License | MIT |
| Maintainer | [email protected] |
| Stability | stable |
| Safe Haskell | None |
| Language | Haskell2010 |
Database.PostgreSQL.Entity.Internal
Contents
Description
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.
Synopsis
- isNotNull :: Vector Field -> Text
- isNull :: Vector Field -> Text
- isIn :: Field -> Vector Text -> Text
- inParens :: Text -> Text
- quoteName :: Text -> Text
- literal :: Text -> Text
- getTableName :: Entity e => Text
- getFieldName :: Field -> Text
- getPrimaryKey :: Entity e => Text
- prefix :: Maybe Text -> Text
- expandFields :: Entity e => Text
- expandQualifiedFields :: Entity e => Text
- expandQualifiedFields' :: Vector Field -> Text -> Text
- qualifyField :: Entity e => Field -> Text
- qualifyFields :: Text -> Vector Field -> Vector Field
- placeholder :: Field -> Text
- placeholder' :: Entity e => Field -> Text
- generatePlaceholders :: Vector Field -> Text
- textToQuery :: Text -> Query
- queryToText :: Query -> Text
- intercalateVector :: Text -> Vector Text -> Vector Text
- renderSortExpression :: (Field, SortKeyword) -> Text
Helpers
isNotNull :: Vector Field -> Text Source #
Produce an IS NOT NULL statement given a vector of fields
>>>isNotNull [ [field| possibly_empty |] ]"\"possibly_empty\" IS NOT NULL"
>>>isNotNull [[field| possibly_empty |], [field| that_one_too |]]"\"possibly_empty\" IS NOT NULL AND \"that_one_too\" IS NOT NULL"
Since: 0.0.1.0
isNull :: Vector Field -> Text Source #
Produce an IS NULL statement given a vector of fields
>>>isNull [ [field| possibly_empty |] ]"\"possibly_empty\" IS NULL"
>>>isNull [[field| possibly_empty |], [field| that_one_too |]]"\"possibly_empty\" IS NULL AND \"that_one_too\" IS NULL"
Since: 0.0.1.0
inParens :: Text -> Text Source #
Wrap the given text between parentheses
Examples
>>>inParens "wrap me!""(wrap me!)"
Since: 0.0.1.0
quoteName :: Text -> Text Source #
Wrap the given text between double quotes
Examples
>>>quoteName "meow.""\"meow.\""
Since: 0.0.1.0
literal :: Text -> Text Source #
Wrap the given text between single quotes, for literal text in an SQL query.
Examples
>>>literal "meow.""'meow.'"
Since: 0.0.2.0
getTableName :: Entity e => Text Source #
Safe getter that quotes a table name
Examples
>>>getTableName @Author"\"authors\"">>>getTableName @Tags"public.\"tags\""
Since: 0.0.1.0
getFieldName :: Field -> Text Source #
Accessor to the name of a field, with quotation.
>>>getFieldName ([field| author_id |])"\"author_id\""
Since: 0.0.2.0
getPrimaryKey :: Entity e => Text Source #
Safe getter that quotes a table's primary key
Examples
>>>getPrimaryKey @Author"\"author_id\"">>>getPrimaryKey @Tags"\"category\""
Since: 0.0.2.0
expandFields :: Entity e => Text Source #
Produce a comma-separated list of an entity's fields.
Examples
>>>expandFields @BlogPost"\"blog_post_id\", \"author_id\", \"int_list\", \"title\", \"content\", \"created_at\""
Since: 0.0.1.0
expandQualifiedFields :: Entity e => Text Source #
Produce a comma-separated list of an entity's fields, qualified with the table name
Examples
>>>expandQualifiedFields @BlogPost"blogposts.\"blog_post_id\", blogposts.\"author_id\", blogposts.\"int_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\""
Since: 0.0.1.0
expandQualifiedFields' :: Vector Field -> Text -> Text Source #
Produce a comma-separated list of an entity's fields, qualified with an arbitrary prefix
Examples
>>>expandQualifiedFields' (fields @BlogPost) "legacy""legacy.\"blog_post_id\", legacy.\"author_id\", legacy.\"int_list\", legacy.\"title\", legacy.\"content\", legacy.\"created_at\""
Since: 0.0.1.0
qualifyField :: Entity e => Field -> Text Source #
Take a prefix and a vector of fields, and qualifies each field with the prefix
Examples
>>>qualifyField @Author [field| name |]"authors.\"name\""
Since: 0.0.2.0
qualifyFields :: Text -> Vector Field -> Vector Field Source #
Take a prefix and a vector of fields, and qualifies each field with the prefix
Examples
>>>qualifyFields "legacy" (fields @BlogPost)[Field "legacy.\"blog_post_id\"" Nothing,Field "legacy.\"author_id\"" Nothing,Field "legacy.\"int_list\"" Nothing,Field "legacy.\"title\"" Nothing,Field "legacy.\"content\"" Nothing,Field "legacy.\"created_at\"" Nothing]
Since: 0.0.1.0
placeholder :: Field -> Text Source #
Produce a placeholder of the form "field" = ? with an optional type annotation.
Examples
>>>placeholder [field| id |]"\"id\" = ?"
>>>placeholder $ [field| ids |]"\"ids\" = ?"
>>>fmap placeholder $ fields @BlogPost["\"blog_post_id\" = ?","\"author_id\" = ?","\"int_list\" = ?","\"title\" = ?","\"content\" = ?","\"created_at\" = ?"]
Since: 0.0.1.0
placeholder' :: Entity e => Field -> Text Source #
Produce a placeholder of the form table."field" = ? with an optional type annotation.
Examples
>>>placeholder' @BlogPost [field| id |]"blogposts.\"id\" = ?"
>>>placeholder' @BlogPost $ [field| ids |]"blogposts.\"ids\" = ?"
Since: 0.0.2.0
generatePlaceholders :: Vector Field -> Text Source #
Generate an appropriate number of “?” placeholders given a vector of fields.
Used to generate INSERT queries.
Examples
>>>generatePlaceholders $ fields @BlogPost"?, ?, ?, ?, ?, ?"
Since: 0.0.1.0
textToQuery :: Text -> Query Source #
queryToText :: Query -> Text Source #
intercalateVector :: Text -> Vector Text -> Vector Text Source #
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
>>>intercalateVector "~" [][]
>>>intercalateVector "~" ["nyan"]["nyan"]
>>>intercalateVector "~" ["nyan", "nyan", "nyan"]["nyan","~","nyan","~","nyan"]
Since: 0.0.1.0
renderSortExpression :: (Field, SortKeyword) -> Text Source #
Examples
>>>renderSortExpression ([field| title |], ASC)"\"title\" ASC"
Since: 0.0.2.0