Skip to content

Commit f1104aa

Browse files
committed
Parametrize query
1 parent fb0113e commit f1104aa

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

squeal-postgresql/exe/Example.hs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,21 @@ getOrganizations = select_
123123
(#o ! #id `as` #orgId :* #o ! #name `as` #orgName)
124124
(from (table (#org ! #organizations `as` #o)))
125125

126-
getOrganizationsBy :: Query_ Schemas (Only Int32) Organization
127-
getOrganizationsBy =
126+
getOrganizationsBy ::
127+
Condition
128+
'Ungrouped
129+
'[]
130+
'[]
131+
Schemas
132+
'[ 'NotNull 'PGint4]
133+
'["o" ::: ["id" ::: NotNull PGint4, "name" ::: NotNull PGtext]] ->
134+
Query_ Schemas (Only Int32) Organization
135+
getOrganizationsBy condition =
128136
select_
129137
(#o ! #id `as` #orgId :* #o ! #name `as` #orgName)
130138
(
131139
from (table (#org ! #organizations `as` #o))
132-
& where_ (#o ! #id .== param @1)
140+
& where_ condition
133141
)
134142

135143
upsertUser :: Manipulation_ Schemas (Int32, String, VarArray [Maybe Int16]) ()
@@ -192,7 +200,8 @@ session = do
192200
organizationRows <- getRows organizationsResult
193201
liftIO $ print (organizationRows :: [Organization])
194202

195-
organizationsResult2 <- runQueryParams getOrganizationsBy (Only (1 :: Int32))
203+
organizationsResult2 <- runQueryParams
204+
(getOrganizationsBy ((#o ! #id) .== param @1)) (Only (1 :: Int32))
196205
organizationRows2 <- getRows organizationsResult2
197206
liftIO $ print (organizationRows2 :: [Organization])
198207

0 commit comments

Comments
 (0)