mirror of
https://github.com/khibino/haskell-relational-record.git
synced 2025-01-07 05:36:30 +03:00
Fix around inconsistent Update specs.
This commit is contained in:
parent
851343c0c4
commit
0f12d49034
@ -11,18 +11,18 @@ deleteBanana :: Delete ()
|
||||
deleteBanana =
|
||||
typedDelete tableOfSetA banana
|
||||
|
||||
updateBanana :: Update (SetA, ()) SetA
|
||||
updateBanana :: Update (SetA, ())
|
||||
updateBanana =
|
||||
typedUpdateAllColumn tableOfSetA banana
|
||||
|
||||
updateBanana2 :: Update String SetA
|
||||
updateBanana2 :: Update String
|
||||
updateBanana2 =
|
||||
targetUpdate tableOfSetA $
|
||||
\ta pa -> do (ph', ()) <- placeholder ( \ph -> ta !# name' <-# ph )
|
||||
wheres $ pa ! name' .=. value "Banana"
|
||||
return ph'
|
||||
|
||||
updateBanana3 :: Update SetA SetA
|
||||
updateBanana3 :: Update SetA
|
||||
updateBanana3 =
|
||||
targetUpdate tableOfSetA $
|
||||
\ta pa -> do (ph', ()) <- placeholder ( \ph -> ta !# id' <-# ph )
|
||||
|
@ -82,24 +82,22 @@ instance Show (KeyUpdate p a) where
|
||||
show = untypeKeyUpdate
|
||||
|
||||
|
||||
-- | Update type with place-holder parameter 'p' and update record type 'a'.
|
||||
-- Columns to update are record all columns,
|
||||
-- So all place-holder correspond to type ('a', 'p') columns.
|
||||
newtype Update p a = Update { untypeUpdate :: String }
|
||||
-- | Update type with place-holder parameter 'p'.
|
||||
newtype Update p = Update { untypeUpdate :: String }
|
||||
|
||||
-- | Unsafely make typed 'Update' from SQL string.
|
||||
unsafeTypedUpdate :: String -> Update p a
|
||||
unsafeTypedUpdate :: String -> Update p
|
||||
unsafeTypedUpdate = Update
|
||||
|
||||
-- | Make typed 'Update' from 'Table' and 'Restriction'.
|
||||
typedUpdate :: Table r -> UpdateTarget p r -> Update p r
|
||||
typedUpdate :: Table r -> UpdateTarget p r -> Update p
|
||||
typedUpdate tbl ut = unsafeTypedUpdate . updateSeedSQL tbl
|
||||
. sqlFromUpdateTarget tbl ut $ ""
|
||||
|
||||
-- | Directly make typed 'Update' from 'Table' and 'Target' monad context.
|
||||
targetUpdate :: Table r
|
||||
-> UpdateTargetContext p r -- ^ 'Target' monad context
|
||||
-> Update p r
|
||||
-> Update p
|
||||
targetUpdate tbl = typedUpdate tbl . updateTarget'
|
||||
|
||||
-- | Make typed 'Update' from 'Table' and 'Restriction'.
|
||||
@ -107,7 +105,7 @@ targetUpdate tbl = typedUpdate tbl . updateTarget'
|
||||
typedUpdateAllColumn :: PersistableWidth r
|
||||
=> Table r
|
||||
-> Restriction p r
|
||||
-> Update (r, p) r
|
||||
-> Update (r, p)
|
||||
typedUpdateAllColumn tbl r = typedUpdate tbl $ liftTargetAllColumn' r
|
||||
|
||||
-- | Directly make typed 'Update' from 'Table' and 'Restrict' monad context.
|
||||
@ -115,11 +113,11 @@ typedUpdateAllColumn tbl r = typedUpdate tbl $ liftTargetAllColumn' r
|
||||
restricredUpdateAllColumn :: PersistableWidth r
|
||||
=> Table r
|
||||
-> RestrictionContext p r
|
||||
-> Update (r, p) r
|
||||
-> Update (r, p)
|
||||
restricredUpdateAllColumn tbl = typedUpdateAllColumn tbl . restriction'
|
||||
|
||||
-- | Show update SQL string
|
||||
instance Show (Update p a) where
|
||||
instance Show (Update p) where
|
||||
show = untypeUpdate
|
||||
|
||||
|
||||
|
@ -32,31 +32,29 @@ type PreparedUpdate p = PreparedStatement p ()
|
||||
-- | Typed prepare update operation.
|
||||
prepare :: IConnection conn
|
||||
=> conn
|
||||
-> Update p a
|
||||
-> IO (PreparedUpdate (a, p))
|
||||
-> Update p
|
||||
-> IO (PreparedUpdate p)
|
||||
prepare conn = unsafePrepare conn . untypeUpdate
|
||||
|
||||
-- | Same as 'prepare'.
|
||||
prepareUpdate :: IConnection conn
|
||||
=> conn
|
||||
-> Update p a
|
||||
-> IO (PreparedUpdate (a, p))
|
||||
-> Update p
|
||||
-> IO (PreparedUpdate p)
|
||||
prepareUpdate = prepare
|
||||
|
||||
-- | Bind parameters, execute statement and get execution result.
|
||||
runPreparedUpdate :: (ToSql SqlValue a, ToSql SqlValue p)
|
||||
=> a
|
||||
-> p
|
||||
-> PreparedUpdate (a, p)
|
||||
runPreparedUpdate :: ToSql SqlValue p
|
||||
=> p
|
||||
-> PreparedUpdate p
|
||||
-> IO Integer
|
||||
runPreparedUpdate = curry runPreparedNoFetch
|
||||
runPreparedUpdate = runPreparedNoFetch
|
||||
|
||||
-- | Prepare update statement, bind parameters,
|
||||
-- execute statement and get execution result.
|
||||
runUpdate :: (IConnection conn, ToSql SqlValue a, ToSql SqlValue p)
|
||||
runUpdate :: (IConnection conn, ToSql SqlValue p)
|
||||
=> conn
|
||||
-> a
|
||||
-> p
|
||||
-> Update p a
|
||||
-> Update p
|
||||
-> IO Integer
|
||||
runUpdate conn a p = (>>= runPreparedUpdate a p) . prepareUpdate conn
|
||||
runUpdate conn p = (>>= runPreparedUpdate p) . prepareUpdate conn
|
||||
|
Loading…
Reference in New Issue
Block a user