[web-devel] Auto-discard notification
Michael Snoyman
michael at snoyman.com
Thu Jun 9 14:14:42 CEST 2011
> From: Hehe Nicht <zerstroyer at googlemail.com>
> To: web-devel at haskell.org
> Date: Thu, 9 Jun 2011 11:26:14 +0200
> Subject: withStmt function
> Could someone explain the withStmt function from Persist.Raw to me?
> Here is an example i was toying with:
>
>>{-# LANGUAGE QuasiQuotes, TypeFamilies, GeneralizedNewtypeDeriving, TemplateHaskell, OverloadedStrings #-}
>>import Database.Persist
>>import Database.Persist.Base
>>import Database.Persist.Sqlite
>>import Database.Persist.GenericSql.Raw
>>import Control.Monad.IO.Class (liftIO)
>>
>>main :: IO ()
>>main = withSqliteConn ":memory:" $ runSqlConn $ do
>> _ <- execute "CREATE TABLE cities (name varchar(80),location point);" ([]::[PersistValue])
>> _ <- execute "INSERT INTO cities VALUES ('SanFrancisco','(100.0,100.9)');" ([]::[PersistValue])
>> _ <- execute "INSERT INTO cities VALUES ('New York','(1.0,10.9)');" ([]::[PersistValue])
>> query <- withStmt "SELECT name, location FROM cities;" ([]::[PersistValue]) (id)
>> liftIO $ print query
>
> which prints "Just [PersistText "SanFrancisco",PersistText
> "(100.0,100.9)"])". So how do i get the rest of the rows? Do i have to
> pass a different function as the last argument to withStmt?
> Thanks in advance.
>
>
>
The function provided by withStmt returns one row at a time, until it
exhausts the input and returns a Nothing. I'll try to write a
"cookbook recipe" for the next cookbook installment describing that.
Michael
More information about the web-devel
mailing list