@@ -5,41 +5,14 @@ Module: module Database.Persist.Sql.Raw.QQ
55Description: QuasiQuoters for performing raw sql queries
66
77This module exports convenient QuasiQuoters to perform raw SQL queries.
8- All QuasiQuoters follow them same pattern and are analogous to the similar named
8+ All QuasiQuoters follow the same pattern and are analogous to the similar named
99functions exported from 'Database.Persist.Sql.Raw'. Neither the quoted
1010function's behaviour, nor it's return value is altered during the translation
1111and all documentation provided with it holds.
1212
1313The QuasiQuoters in this module perform a simple substitution on the query text,
1414that allows value substitutions, table name substitutions as well as column name
1515substitutions.
16-
17- Here is a small example:
18-
19- Given the following simple model:
20-
21- @
22- Category
23- rgt Int
24- lft Int
25- @
26-
27- We can now execute this raw query:
28-
29- @
30- let lft = 10 :: Int
31- rgt = 20 :: Int
32- width = rgt - lft
33- in [sqlQQ|
34- DELETE FROM ^{Category} WHERE @{CategoryLft} BETWEEN #{lft} AND #{rgt};
35- UPDATE category SET @{CategoryRgt} = @{CategoryRgt} - #{width} WHERE @{CategoryRgt} > #{rgt};
36- UPDATE category SET @{CategoryLft} = @{CategoryLft} - #{width} WHERE @{CategoryLft} > #{rgt};
37- |]
38- @
39-
40- @^{TableName}@ looks up the table's name and escapes it, @\@{ColumnName}@ looks
41- up the column's name and properly escapes it and @#{value}@ inserts the value
42- via the usual parameter substitution mechanism.
4316-}
4417
4518{-# LANGUAGE LambdaCase #-}
@@ -154,27 +127,70 @@ makeQQ x = QuasiQuoter
154127 (error " Cannot use qc as a type" )
155128 (error " Cannot use qc as a dec" )
156129
157- -- | Analoguous to 'Database.Persist.Sql.Raw.rawSql'
130+ -- | QuasiQuoter for performing raw sql queries, analoguous to
131+ -- 'Database.Persist.Sql.Raw.rawSql'
132+ --
133+ -- This and the following are convenient QuasiQuoters to perform raw SQL
134+ -- queries. They each follow the same pattern and are analogous to
135+ -- the similarly named @raw@ functions. Neither the quoted function's
136+ -- behaviour, nor it's return value is altered during the translation and
137+ -- all documentation provided with it holds.
138+ --
139+ -- These QuasiQuoters perform a simple substitution on the query text, that
140+ -- allows value substitutions, table name substitutions as well as column name
141+ -- substitutions.
142+ --
143+ -- Here is a small example:
144+ --
145+ -- Given the following simple model:
146+ --
147+ -- @
148+ -- Category
149+ -- rgt Int
150+ -- lft Int
151+ -- @
152+ --
153+ -- We can now execute this raw query:
154+ --
155+ -- @
156+ -- let lft = 10 :: Int
157+ -- rgt = 20 :: Int
158+ -- width = rgt - lft
159+ -- in [sqlQQ|
160+ -- DELETE FROM ^{Category} WHERE @{CategoryLft} BETWEEN #{lft} AND #{rgt};
161+ -- UPDATE category SET @{CategoryRgt} = @{CategoryRgt} - #{width} WHERE @{CategoryRgt} > #{rgt};
162+ -- UPDATE category SET @{CategoryLft} = @{CategoryLft} - #{width} WHERE @{CategoryLft} > #{rgt};
163+ -- |]
164+ -- @
165+ --
166+ -- @^{TableName}@ looks up the table's name and escapes it, @\@{ColumnName}@
167+ -- looks up the column's name and properly escapes it and @#{value}@ inserts
168+ -- the value via the usual parameter substitution mechanism.
169+ --
158170-- @since 2.7.2
159171sqlQQ :: QuasiQuoter
160172sqlQQ = makeQQ [| rawSql | ]
161173
162174-- | Analoguous to 'Database.Persist.Sql.Raw.rawExecute'
175+ --
163176-- @since 2.7.2
164177executeQQ :: QuasiQuoter
165178executeQQ = makeQQ [| rawExecute | ]
166179
167180-- | Analoguous to 'Database.Persist.Sql.Raw.rawExecuteCount'
181+ --
168182-- @since 2.7.2
169183executeCountQQ :: QuasiQuoter
170184executeCountQQ = makeQQ [| rawExecuteCount | ]
171185
172186-- | Analoguous to 'Database.Persist.Sql.Raw.rawQuery'
187+ --
173188-- @since 2.7.2
174189queryQQ :: QuasiQuoter
175190queryQQ = makeQQ [| rawQuery | ]
176191
177192-- | Analoguous to 'Database.Persist.Sql.Raw.rawQueryRes'
193+ --
178194-- @since 2.7.2
179195queryResQQ :: QuasiQuoter
180196queryResQQ = makeQQ [| rawQueryRes | ]
0 commit comments