Skip to content

Commit a065709

Browse files
committed
Revamp doctest
1 parent e596b4c commit a065709

File tree

5 files changed

+142
-52
lines changed

5 files changed

+142
-52
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ jobs:
7272
touch ~/.pgpass
7373
chmod 0600 ~/.pgpass
7474
echo "${FLORA_DB_HOST}:${FLORA_DB_PORT}:${FLORA_DB_DATABASE}:${FLORA_DB_USER}:${FLORA_DB_PASSWORD}" > .pgpass
75-
cabal freeze
7675
7776
- name: Cache
7877
uses: actions/cache@v3
@@ -85,8 +84,12 @@ jobs:
8584
run: |
8685
echo "$HOME/.local/bin" >> $GITHUB_PATH
8786
make build
87+
cabal install doctest
8888
cabal install postgresql-migration
8989
90+
- name: Doctests
91+
run: |
92+
make doctest
9093
- name: Test
9194
run: |
9295
source environment.sh

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ docs-build: ## Generate the documentation
3030
docs-serve: ## Start a web server to serve the documentation
3131
@cd docs; mdbook serve --open
3232

33+
doctest: ## Run the doctests
34+
@cabal repl --with-ghc=doctest
35+
3336
db-create: ## Create the database
3437
@createdb -h $(DB_HOST) -p $(DB_PORT) -U $(DB_USER) $(DB_DATABASE)
3538

src/Database/PostgreSQL/Entity.hs

Lines changed: 64 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,47 @@ import Database.PostgreSQL.Entity.Internal
9898
import Database.PostgreSQL.Entity.Types
9999

100100
{- $setup
101-
>>> :set -XQuasiQuotes
102-
>>> :set -XOverloadedStrings
103-
>>> :set -XOverloadedLists
104-
>>> :set -XTypeApplications
105-
>>> import Database.PostgreSQL.Entity
106-
>>> import Database.PostgreSQL.Entity.Types
107-
>>> import Database.PostgreSQL.Entity.Internal
108-
>>> import Database.PostgreSQL.Entity.Internal.BlogPost
109-
>>> import Database.PostgreSQL.Entity.Internal.QQ
110-
>>> import Database.PostgreSQL.Simple.Types (Query (..))
111-
>>> import Data.Vector (Vector)
112-
>>> import qualified Data.Vector as V
101+
>>> :set -XQuasiQuotes
102+
>>> :set -XOverloadedStrings
103+
>>> :set -XOverloadedLists
104+
>>> :set -XTypeApplications
105+
>>> import Database.PostgreSQL.Entity
106+
>>> import Database.PostgreSQL.Entity.Types
107+
>>> import Database.PostgreSQL.Entity.Internal
108+
>>> import Database.PostgreSQL.Entity.Internal.QQ
109+
>>> import Database.PostgreSQL.Simple.Types (Query (..))
110+
>>> import Data.Vector (Vector)
111+
>>> import qualified Data.Vector as V
112+
>>> import Data.Time (UTCTime)
113+
>>> import GHC.Generics (Generic)
114+
>>> :{
115+
>>> data Author = Author
116+
>>> { authorId :: Int
117+
>>> , name :: Text
118+
>>> , createdAt :: UTCTime
119+
>>> }
120+
>>> deriving stock (Eq, Generic, Ord, Show)
121+
>>> deriving anyclass (FromRow, ToRow)
122+
>>> deriving
123+
>>> (Entity)
124+
>>> via (GenericEntity '[PrimaryKey "author_id", TableName "authors"] Author)
125+
>>>
126+
>>> data BlogPost = BlogPost
127+
>>> { blogPostId :: Int
128+
>>> -- ^ Primary key
129+
>>> , authorId :: Int
130+
>>> -- ^ Foreign keys, for which we need an explicit type annotation
131+
>>> , intList :: Vector Int
132+
>>> , title :: Text
133+
>>> , content :: Text
134+
>>> , createdAt :: UTCTime
135+
>>> }
136+
>>> deriving stock (Eq, Generic, Ord, Show)
137+
>>> deriving anyclass (FromRow, ToRow)
138+
>>> deriving
139+
>>> (Entity)
140+
>>> via (GenericEntity '[PrimaryKey "blog_post_id", TableName "blogposts"] BlogPost)
141+
>>> :}
113142
-}
114143

115144
{- $highlevel
@@ -348,7 +377,7 @@ deleteByField fs values = void $ execute Delete (_deleteWhere @e fs) values
348377
__Examples__
349378
350379
>>> _select @BlogPost
351-
"SELECT blogposts.\"blogpost_id\", blogposts.\"author_id\", blogposts.\"uuid_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\" FROM \"blogposts\""
380+
"SELECT blogposts.\"blog_post_id\", blogposts.\"author_id\", blogposts.\"int_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\" FROM \"blogposts\""
352381
353382
@since 0.0.1.0
354383
-}
@@ -359,8 +388,8 @@ _select = textToQuery $ "SELECT " <> expandQualifiedFields @e <> " FROM " <> get
359388
360389
__Examples__
361390
362-
>>> _selectWithFields @BlogPost [ [field| blogpost_id |], [field| created_at |] ]
363-
"SELECT \"blogposts\".\"blogpost_id\", \"blogposts\".\"created_at\" FROM \"\"blogposts\"\""
391+
>>> _selectWithFields @BlogPost [ [field| blog_post_id |], [field| created_at |] ]
392+
"SELECT \"blogposts\".\"blog_post_id\", \"blogposts\".\"created_at\" FROM \"blogposts\""
364393
365394
@since 0.0.1.0
366395
-}
@@ -379,11 +408,11 @@ _selectWithFields fs = textToQuery $ "SELECT " <> expandQualifiedFields' fs tn <
379408
380409
__Examples__
381410
382-
>>> _select @BlogPost <> _where [[field| blogpost_id |]]
383-
"SELECT blogposts.\"blogpost_id\", blogposts.\"author_id\", blogposts.\"uuid_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\" FROM \"blogposts\" WHERE \"blogpost_id\" = ?"
411+
>>> _select @BlogPost <> _where [[field| blog_post_id |]]
412+
"SELECT blogposts.\"blog_post_id\", blogposts.\"author_id\", blogposts.\"int_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\" FROM \"blogposts\" WHERE \"blog_post_id\" = ?"
384413
385-
>>> _select @BlogPost <> _where [ [field| uuid_list |] ]
386-
"SELECT blogposts.\"blogpost_id\", blogposts.\"author_id\", blogposts.\"uuid_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\" FROM \"blogposts\" WHERE \"uuid_list\" = ?"
414+
>>> _select @BlogPost <> _where [ [field| int_list |] ]
415+
"SELECT blogposts.\"blog_post_id\", blogposts.\"author_id\", blogposts.\"int_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\" FROM \"blogposts\" WHERE \"int_list\" = ?"
387416
388417
@since 0.0.1.0
389418
-}
@@ -397,10 +426,10 @@ _where fs' = textToQuery $ " WHERE " <> clauseFields
397426
__Examples__
398427
399428
>>> _selectWhere @BlogPost [ [field| author_id |] ]
400-
"SELECT blogposts.\"blogpost_id\", blogposts.\"author_id\", blogposts.\"uuid_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\" FROM \"blogposts\" WHERE \"author_id\" = ?"
429+
"SELECT blogposts.\"blog_post_id\", blogposts.\"author_id\", blogposts.\"int_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\" FROM \"blogposts\" WHERE \"author_id\" = ?"
401430
402431
>>> _selectWhere @BlogPost [ [field| author_id |], [field| title |]]
403-
"SELECT blogposts.\"blogpost_id\", blogposts.\"author_id\", blogposts.\"uuid_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\" FROM \"blogposts\" WHERE \"author_id\" = ? AND \"title\" = ?"
432+
"SELECT blogposts.\"blog_post_id\", blogposts.\"author_id\", blogposts.\"int_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\" FROM \"blogposts\" WHERE \"author_id\" = ? AND \"title\" = ?"
404433
405434
@since 0.0.1.0
406435
-}
@@ -411,7 +440,7 @@ _selectWhere fs = _select @e <> _where fs
411440
r
412441
413442
>>> _selectWhereNotNull @BlogPost [ [field| author_id |] ]
414-
"SELECT blogposts.\"blogpost_id\", blogposts.\"author_id\", blogposts.\"uuid_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\" FROM \"blogposts\" WHERE \"author_id\" IS NOT NULL"
443+
"SELECT blogposts.\"blog_post_id\", blogposts.\"author_id\", blogposts.\"int_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\" FROM \"blogposts\" WHERE \"author_id\" IS NOT NULL"
415444
416445
@since 0.0.1.0
417446
-}
@@ -421,7 +450,7 @@ _selectWhereNotNull fs = _select @e <> textToQuery (" WHERE " <> isNotNull fs)
421450
{-| Produce a SELECT statement where the provided fields are checked for being null.
422451
423452
>>> _selectWhereNull @BlogPost [ [field| author_id |] ]
424-
"SELECT blogposts.\"blogpost_id\", blogposts.\"author_id\", blogposts.\"uuid_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\" FROM \"blogposts\" WHERE \"author_id\" IS NULL"
453+
"SELECT blogposts.\"blog_post_id\", blogposts.\"author_id\", blogposts.\"int_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\" FROM \"blogposts\" WHERE \"author_id\" IS NULL"
425454
426455
@since 0.0.1.0
427456
-}
@@ -431,7 +460,7 @@ _selectWhereNull fs = _select @e <> textToQuery (" WHERE " <> isNull fs)
431460
{-| Produce a SELECT statement where the given field is checked aginst the provided array of values .
432461
433462
>>> _selectWhereIn @BlogPost [field| title |] [ "Unnamed", "Mordred's Song" ]
434-
"SELECT blogposts.\"blogpost_id\", blogposts.\"author_id\", blogposts.\"uuid_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\" FROM \"blogposts\" WHERE \"title\" IN ('Unnamed', 'Mordred''s Song')"
463+
"SELECT blogposts.\"blog_post_id\", blogposts.\"author_id\", blogposts.\"int_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\" FROM \"blogposts\" WHERE \"title\" IN ('Unnamed', 'Mordred''s Song')"
435464
436465
@since 0.0.2.0
437466
-}
@@ -443,7 +472,7 @@ _selectWhereIn f values = _select @e <> textToQuery (" WHERE " <> isIn f values)
443472
__Examples__
444473
445474
>>> _joinSelect @BlogPost @Author
446-
"SELECT blogposts.\"blogpost_id\", blogposts.\"author_id\", blogposts.\"uuid_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\", authors.\"author_id\", authors.\"name\", authors.\"created_at\" FROM \"blogposts\" INNER JOIN \"authors\" USING(author_id)"
475+
"SELECT blogposts.\"blog_post_id\", blogposts.\"author_id\", blogposts.\"int_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\", authors.\"author_id\", authors.\"name\", authors.\"created_at\" FROM \"blogposts\" INNER JOIN \"authors\" USING(author_id)"
447476
448477
@since 0.0.1.0
449478
-}
@@ -510,7 +539,7 @@ _joinSelectWithFields fs1 fs2 =
510539
__Examples__
511540
512541
>>> _joinSelectOneByField @BlogPost @Author [field| author_id |] [field| name |] :: Query
513-
"SELECT blogposts.\"blogpost_id\", blogposts.\"author_id\", blogposts.\"uuid_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\" FROM \"blogposts\" INNER JOIN \"authors\" ON \"blogposts\".\"author_id\" = \"authors\".\"author_id\" WHERE authors.\"name\" = ?"
542+
"SELECT blogposts.\"blog_post_id\", blogposts.\"author_id\", blogposts.\"int_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\" FROM \"blogposts\" INNER JOIN \"authors\" ON \"blogposts\".\"author_id\" = \"authors\".\"author_id\" WHERE authors.\"name\" = ?"
514543
515544
@since 0.0.2.0
516545
-}
@@ -544,7 +573,7 @@ _joinSelectOneByField pivotField whereField =
544573
__Examples__
545574
546575
>>> _insert @BlogPost
547-
"INSERT INTO \"blogposts\" (\"blogpost_id\", \"author_id\", \"uuid_list\", \"title\", \"content\", \"created_at\") VALUES (?, ?, ?, ?, ?, ?)"
576+
"INSERT INTO \"blogposts\" (\"blog_post_id\", \"author_id\", \"int_list\", \"title\", \"content\", \"created_at\") VALUES (?, ?, ?, ?, ?, ?)"
548577
549578
@since 0.0.1.0
550579
-}
@@ -558,14 +587,14 @@ _insert = textToQuery $ "INSERT INTO " <> getTableName @e <> " " <> fs <> " VALU
558587
559588
__Examples__
560589
561-
>>> _onConflictDoUpdate [[field| blogpost_id |]] [ [field| title |], [field| content |]]
562-
" ON CONFLICT (blogpost_id) DO UPDATE SET title = EXCLUDED.title, content = EXCLUDED.content"
590+
>>> _onConflictDoUpdate [[field| blog_post_id |]] [ [field| title |], [field| content |]]
591+
" ON CONFLICT (blog_post_id) DO UPDATE SET title = EXCLUDED.title, content = EXCLUDED.content"
563592
564-
>>> _onConflictDoUpdate [[field| blogpost_id |], [field| author_id |]] [ [field| title |], [field| content |]]
565-
" ON CONFLICT (blogpost_id, author_id) DO UPDATE SET title = EXCLUDED.title, content = EXCLUDED.content"
593+
>>> _onConflictDoUpdate [[field| blog_post_id |], [field| author_id |]] [ [field| title |], [field| content |]]
594+
" ON CONFLICT (blog_post_id, author_id) DO UPDATE SET title = EXCLUDED.title, content = EXCLUDED.content"
566595
567-
>>> _insert @BlogPost <> _onConflictDoUpdate [[field| blogpost_id |]] [ [field| title |], [field| content |]]
568-
"INSERT INTO \"blogposts\" (\"blogpost_id\", \"author_id\", \"uuid_list\", \"title\", \"content\", \"created_at\") VALUES (?, ?, ?, ?, ?, ?) ON CONFLICT (blogpost_id) DO UPDATE SET title = EXCLUDED.title, content = EXCLUDED.content"
596+
>>> _insert @BlogPost <> _onConflictDoUpdate [[field| blog_post_id |]] [ [field| title |], [field| content |]]
597+
"INSERT INTO \"blogposts\" (\"blog_post_id\", \"author_id\", \"int_list\", \"title\", \"content\", \"created_at\") VALUES (?, ?, ?, ?, ?, ?) ON CONFLICT (blog_post_id) DO UPDATE SET title = EXCLUDED.title, content = EXCLUDED.content"
569598
570599
@since 0.0.2.0
571600
-}
@@ -586,7 +615,7 @@ _onConflictDoUpdate conflictTarget fieldsToReplace =
586615
"UPDATE \"authors\" SET (\"name\", \"created_at\") = ROW(?, ?) WHERE \"author_id\" = ?"
587616
588617
>>> _update @BlogPost
589-
"UPDATE \"blogposts\" SET (\"author_id\", \"uuid_list\", \"title\", \"content\", \"created_at\") = ROW(?, ?, ?, ?, ?) WHERE \"blogpost_id\" = ?"
618+
"UPDATE \"blogposts\" SET (\"author_id\", \"int_list\", \"title\", \"content\", \"created_at\") = ROW(?, ?, ?, ?, ?) WHERE \"blog_post_id\" = ?"
590619
591620
@since 0.0.1.0
592621
-}
@@ -655,7 +684,7 @@ _updateFieldsBy fs' f =
655684
__Examples__
656685
657686
>>> _delete @BlogPost
658-
"DELETE FROM \"blogposts\" WHERE \"blogpost_id\" = ?"
687+
"DELETE FROM \"blogposts\" WHERE \"blog_post_id\" = ?"
659688
660689
@since 0.0.1.0
661690
-}

src/Database/PostgreSQL/Entity/Internal.hs

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,63 @@ import Database.PostgreSQL.Entity.Internal.Unsafe (Field (Field))
5353
import Database.PostgreSQL.Entity.Types
5454

5555
{- $setup
56-
>>> :set -XQuasiQuotes
57-
>>> :set -XOverloadedLists
58-
>>> :set -XTypeApplications
59-
>>> import Database.PostgreSQL.Entity
60-
>>> import Database.PostgreSQL.Entity.Types
61-
>>> import Database.PostgreSQL.Entity.Internal.BlogPost
62-
>>> import Database.PostgreSQL.Entity.Internal.QQ
63-
>>> import Database.PostgreSQL.Entity.Internal.Unsafe
56+
>>> :set -XQuasiQuotes
57+
>>> :set -XOverloadedStrings
58+
>>> :set -XOverloadedLists
59+
>>> :set -XTypeApplications
60+
>>> import Database.PostgreSQL.Entity
61+
>>> import Database.PostgreSQL.Simple.FromRow (FromRow(..))
62+
>>> import Database.PostgreSQL.Simple.ToRow
63+
>>> import Database.PostgreSQL.Entity.Types
64+
>>> import Database.PostgreSQL.Entity.Internal
65+
>>> import Database.PostgreSQL.Entity.Internal.QQ
66+
>>> import Database.PostgreSQL.Simple.Types (Query (..))
67+
>>> import Data.Vector (Vector)
68+
>>> import qualified Data.Vector as V
69+
>>> import Data.Time (UTCTime)
70+
>>> import GHC.Generics (Generic)
71+
>>> :{
72+
>>> data Author = Author
73+
>>> { authorId :: Int
74+
>>> , name :: Text
75+
>>> , createdAt :: UTCTime
76+
>>> }
77+
>>> deriving stock (Eq, Generic, Ord, Show)
78+
>>> deriving anyclass (FromRow, ToRow)
79+
>>> deriving
80+
>>> (Entity)
81+
>>> via (GenericEntity '[PrimaryKey "author_id", TableName "authors"] Author)
82+
>>>
83+
>>> data BlogPost = BlogPost
84+
>>> { blogPostId :: Int
85+
>>> -- ^ Primary key
86+
>>> , authorId :: Int
87+
>>> -- ^ Foreign keys, for which we need an explicit type annotation
88+
>>> , intList :: Vector Int
89+
>>> , title :: Text
90+
>>> , content :: Text
91+
>>> , createdAt :: UTCTime
92+
>>> }
93+
>>> deriving stock (Eq, Generic, Ord, Show)
94+
>>> deriving anyclass (FromRow, ToRow)
95+
>>> deriving
96+
>>> (Entity)
97+
>>> via (GenericEntity '[PrimaryKey "blog_post_id", TableName "blogposts"] BlogPost)
98+
>>>
99+
>>> data Tags = Tags
100+
>>> { category :: Text
101+
>>> , labels :: [Text]
102+
>>> }
103+
>>>
104+
>>> instance Entity Tags where
105+
>>> tableName = "tags"
106+
>>> schema = Just "public"
107+
>>> primaryKey = [field| category |]
108+
>>> fields =
109+
>>> [ [field| category |]
110+
>>> , [field| labels |]
111+
>>> ]
112+
>>> :}
64113
-}
65114

66115
{-| Wrap the given text between parentheses
@@ -147,7 +196,7 @@ getFieldName = quoteName . fieldName
147196
__Examples__
148197
149198
>>> expandFields @BlogPost
150-
"\"blogpost_id\", \"author_id\", \"uuid_list\", \"title\", \"content\", \"created_at\""
199+
"\"blog_post_id\", \"author_id\", \"int_list\", \"title\", \"content\", \"created_at\""
151200
152201
@since 0.0.1.0
153202
-}
@@ -159,7 +208,7 @@ expandFields = V.foldl1' (\element acc -> element <> ", " <> acc) (getFieldName
159208
__Examples__
160209
161210
>>> expandQualifiedFields @BlogPost
162-
"blogposts.\"blogpost_id\", blogposts.\"author_id\", blogposts.\"uuid_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\""
211+
"blogposts.\"blog_post_id\", blogposts.\"author_id\", blogposts.\"int_list\", blogposts.\"title\", blogposts.\"content\", blogposts.\"created_at\""
163212
164213
@since 0.0.1.0
165214
-}
@@ -173,7 +222,7 @@ expandQualifiedFields = expandQualifiedFields' (fields @e) prefixName
173222
__Examples__
174223
175224
>>> expandQualifiedFields' (fields @BlogPost) "legacy"
176-
"legacy.\"blogpost_id\", legacy.\"author_id\", legacy.\"uuid_list\", legacy.\"title\", legacy.\"content\", legacy.\"created_at\""
225+
"legacy.\"blog_post_id\", legacy.\"author_id\", legacy.\"int_list\", legacy.\"title\", legacy.\"content\", legacy.\"created_at\""
177226
178227
@since 0.0.1.0
179228
-}
@@ -203,7 +252,7 @@ qualifyField f = (\(Field fName _) -> p <> "." <> quoteName fName) f
203252
__Examples__
204253
205254
>>> qualifyFields "legacy" (fields @BlogPost)
206-
[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]
255+
[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]
207256
208257
@since 0.0.1.0
209258
-}
@@ -221,7 +270,7 @@ qualifyFields p fs = fmap (\(Field f t) -> Field (p <> "." <> quoteName f) t) fs
221270
"\"ids\" = ?"
222271
223272
>>> fmap placeholder $ fields @BlogPost
224-
["\"blogpost_id\" = ?","\"author_id\" = ?","\"uuid_list\" = ?","\"title\" = ?","\"content\" = ?","\"created_at\" = ?"]
273+
["\"blog_post_id\" = ?","\"author_id\" = ?","\"int_list\" = ?","\"title\" = ?","\"content\" = ?","\"created_at\" = ?"]
225274
226275
@since 0.0.1.0
227276
-}
@@ -293,13 +342,19 @@ isNull fs' = fold $ intercalateVector " AND " (fmap process fieldNames)
293342
fieldNames = fmap fieldName fs'
294343
process f = quoteName f <> " IS NULL"
295344

345+
-- | Produce an "IS (<value1>, <value2>, …, <valueN>)" clause
346+
--
347+
-- >>> isIn [field| colour |] [ "yellow", "blue", "magenta" ]
348+
-- "\"colour\" IN ('yellow', 'blue', 'magenta')"
349+
--
350+
-- @since 0.0.2.0
296351
isIn :: Field -> Vector Text -> Text
297352
isIn f values = process f <> " IN (" <> fold (intercalateVector ", " vals) <> ")"
298353
where
299354
vals = fmap literal values
300355
process f' = quoteName $ fieldName f'
301356

302-
{-| Since the 'Query' type has an 'IsString' instance, the process of converting from 'Text' to 'String' to 'Query' is
357+
{-| Since the 'Query' type has an 'Data.String.IsString' instance, the process of converting from 'Text' to 'String' to 'Query' is
303358
factored into this function
304359
305360
⚠ This may be dangerous and an unregulated usage of this function may expose to you SQL injection attacks

src/Database/PostgreSQL/Entity/Internal/QQ.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import Text.Parsec (Parsec, anyChar, manyTill, parse, space, spaces, string, try
2727
2828
> instance Entity BlogPost where
2929
> tableName = "blogposts"
30-
> primaryKey = [field| blogpost_id |]
31-
> fields = [ [field| blogpost_id |]
30+
> primaryKey = [field| blog_post_id |]
31+
> fields = [ [field| blog_post_id |]
3232
> , [field| author_id |]
3333
> , [field| uuid_list :: uuid[] |] -- ← This is where we specify an optional PostgreSQL type annotation
3434
> , [field| title |]

0 commit comments

Comments
 (0)