0 | module Postgres.Exec
 1 |
 2 | import Postgres.FFI.Utility
 3 | import Postgres.Data.Conn
 4 | import Postgres.Result
 5 |
 6 | %foreign libpq "PQexec"
 7 |          nLibpq "PQexec"
 8 | prim__dbExec : Ptr PGconn -> (command: String) -> PrimIO (Ptr PGresult)
 9 |
10 | data ExecSource : Type where
11 |   MkExecSource : Conn -> ExecSource
12 |
13 | ResultProducer ExecSource String where
14 |   exec (MkExecSource conn) = pgExec conn where
15 |      pgExec : Conn -> (command: String) -> IO (Ptr PGresult)
16 |      pgExec (MkConn conn) command = primIO $ prim__dbExec conn command
17 |
18 | ||| Execute the given command, apply the given function `f`,
19 | ||| and then free the memory for the result.
20 | export
21 | withExecResult : Conn -> (command : String) -> (f : Result -> IO b) -> IO b
22 | withExecResult conn command = withResult (MkExecSource conn) command
23 |
24 | export
25 | ignore : Result -> IO ()
26 | ignore _ = pure ()
27 |