@@ -5,41 +5,14 @@ Module: module Database.Persist.Sql.Raw.QQ
5
5
Description: QuasiQuoters for performing raw sql queries
6
6
7
7
This 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
9
9
functions exported from 'Database.Persist.Sql.Raw'. Neither the quoted
10
10
function's behaviour, nor it's return value is altered during the translation
11
11
and all documentation provided with it holds.
12
12
13
13
The QuasiQuoters in this module perform a simple substitution on the query text,
14
14
that allows value substitutions, table name substitutions as well as column name
15
15
substitutions.
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.
43
16
-}
44
17
45
18
{-# LANGUAGE LambdaCase #-}
@@ -154,27 +127,70 @@ makeQQ x = QuasiQuoter
154
127
(error " Cannot use qc as a type" )
155
128
(error " Cannot use qc as a dec" )
156
129
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
+ --
158
170
-- @since 2.7.2
159
171
sqlQQ :: QuasiQuoter
160
172
sqlQQ = makeQQ [| rawSql | ]
161
173
162
174
-- | Analoguous to 'Database.Persist.Sql.Raw.rawExecute'
175
+ --
163
176
-- @since 2.7.2
164
177
executeQQ :: QuasiQuoter
165
178
executeQQ = makeQQ [| rawExecute | ]
166
179
167
180
-- | Analoguous to 'Database.Persist.Sql.Raw.rawExecuteCount'
181
+ --
168
182
-- @since 2.7.2
169
183
executeCountQQ :: QuasiQuoter
170
184
executeCountQQ = makeQQ [| rawExecuteCount | ]
171
185
172
186
-- | Analoguous to 'Database.Persist.Sql.Raw.rawQuery'
187
+ --
173
188
-- @since 2.7.2
174
189
queryQQ :: QuasiQuoter
175
190
queryQQ = makeQQ [| rawQuery | ]
176
191
177
192
-- | Analoguous to 'Database.Persist.Sql.Raw.rawQueryRes'
193
+ --
178
194
-- @since 2.7.2
179
195
queryResQQ :: QuasiQuoter
180
196
queryResQQ = makeQQ [| rawQueryRes | ]
0 commit comments