mirror of
https://github.com/khibino/haskell-relational-record.git
synced 2024-12-01 13:52:12 +03:00
Apply bracketed prepare to KeyUpdate type.
This commit is contained in:
parent
3905b1a5f8
commit
8858b20158
@ -14,13 +14,14 @@
|
||||
module Database.HDBC.Record.KeyUpdate (
|
||||
PreparedKeyUpdate,
|
||||
|
||||
prepare, prepareKeyUpdate,
|
||||
prepare, prepareKeyUpdate, withPrepareKeyUpdate,
|
||||
|
||||
bindKeyUpdate,
|
||||
|
||||
runPreparedKeyUpdate, runKeyUpdate
|
||||
) where
|
||||
|
||||
import Control.Exception (bracket)
|
||||
import Database.HDBC (IConnection, SqlValue, Statement)
|
||||
import qualified Database.HDBC as HDBC
|
||||
|
||||
@ -59,6 +60,19 @@ prepareKeyUpdate :: IConnection conn
|
||||
-> IO (PreparedKeyUpdate p a)
|
||||
prepareKeyUpdate = prepare
|
||||
|
||||
-- | Bracketed prepare operation.
|
||||
withPrepareKeyUpdate :: IConnection conn
|
||||
=> conn
|
||||
-> KeyUpdate p a
|
||||
-> (PreparedKeyUpdate p a -> IO b)
|
||||
-> IO b
|
||||
withPrepareKeyUpdate conn ku body =
|
||||
bracket (HDBC.prepare conn sql) HDBC.finish
|
||||
$ body . PreparedKeyUpdate key
|
||||
where
|
||||
sql = untypeKeyUpdate ku
|
||||
key = Query.updateKey ku
|
||||
|
||||
-- | Typed operation to bind parameters for 'PreparedKeyUpdate' type.
|
||||
bindKeyUpdate :: ToSql SqlValue a
|
||||
=> PreparedKeyUpdate p a
|
||||
@ -82,4 +96,4 @@ runKeyUpdate :: (IConnection conn, ToSql SqlValue a)
|
||||
-> KeyUpdate p a
|
||||
-> a
|
||||
-> IO Integer
|
||||
runKeyUpdate conn q a = prepareKeyUpdate conn q >>= (`runPreparedKeyUpdate` a)
|
||||
runKeyUpdate conn q a = withPrepareKeyUpdate conn q (`runPreparedKeyUpdate` a)
|
||||
|
Loading…
Reference in New Issue
Block a user