Safe Haskell | None |
---|---|
Language | Haskell2010 |
Inserts, updates and deletes
Please note that Opaleye currently only supports INSERT or UPDATE with constant values, not the result of SELECTs. That is, you can generate SQL of the form
INSERT INTO thetable ('John', 1);
but not
INSERT INTO thetable SELECT 'John', (SELECT num FROM thetable ORDER BY num DESC LIMIT 1) + 1;
Synopsis
- runInsert :: Connection -> Insert haskells -> IO haskells
- data Insert haskells = forall fieldsW fieldsR. Insert {
- iTable :: Table fieldsW fieldsR
- iRows :: [fieldsW]
- iReturning :: Returning fieldsR haskells
- iOnConflict :: Maybe OnConflict
- runUpdate :: Connection -> Update haskells -> IO haskells
- data Update haskells = forall fieldsW fieldsR. Update {
- uTable :: Table fieldsW fieldsR
- uUpdateWith :: fieldsR -> fieldsW
- uWhere :: fieldsR -> Field SqlBool
- uReturning :: Returning fieldsR haskells
- updateEasy :: Default Updater fieldsR fieldsW => (fieldsR -> fieldsR) -> fieldsR -> fieldsW
- runDelete :: Connection -> Delete haskells -> IO haskells
- data Delete haskells = forall fieldsW fieldsR. Delete {}
- data Returning fields haskells
- rCount :: Returning fieldsR Int64
- rReturning :: Default FromFields fields haskells => (fieldsR -> fields) -> Returning fieldsR [haskells]
- rReturningI :: Default (Inferrable FromFields) fields haskells => (fieldsR -> fields) -> Returning fieldsR [haskells]
- rReturningExplicit :: FromFields fields haskells -> (fieldsR -> fields) -> Returning fieldsR [haskells]
- data OnConflict
- doNothing :: OnConflict
- runInsert_ :: Connection -> Insert haskells -> IO haskells
- runUpdate_ :: Connection -> Update haskells -> IO haskells
- runDelete_ :: Connection -> Delete haskells -> IO haskells
- data OnConflict = DoNothing
Insert
:: Connection | |
-> Insert haskells | |
-> IO haskells | Returns a type that depends on the |
forall fieldsW fieldsR. Insert | |
|
Update
:: Connection | |
-> Update haskells | |
-> IO haskells | Returns a type that depends on the |
forall fieldsW fieldsR. Update | |
|
A convenient wrapper for writing your update function.
updateEasy
protects you from accidentally updating an
optionalTableField
with Nothing
(i.e. SQL
DEFAULT
). See uUpdateWith
.
uUpdateWith = updateEasy (\... -> ...)
Delete
:: Connection | |
-> Delete haskells | |
-> IO haskells | Returns a type that depends on the |
Returning
:: Default FromFields fields haskells | |
=> (fieldsR -> fields) | |
-> Returning fieldsR [haskells] |
Return a function of the inserted or updated rows
rReturning'
s use of the
typeclass means that the
compiler will have trouble inferring types. It is strongly
recommended that you provide full type signatures when using
Default
FromFields
rReturning
.
:: Default (Inferrable FromFields) fields haskells | |
=> (fieldsR -> fields) | |
-> Returning fieldsR [haskells] |
Like rReturning
but with better inference properties. On the
other hand the mapping from SQL fields to Haskell types is less
flexible.
:: FromFields fields haskells | |
-> (fieldsR -> fields) | |
-> Returning fieldsR [haskells] |
Return a function of the inserted or updated rows. Explicit
version. You probably just want to use rReturning
instead.
On conflict
Currently doNothing
is the
only conflict action supported by
Opaleye.
data OnConflict Source #
Deprecated
runInsert_ :: Connection -> Insert haskells -> IO haskells Source #
Use runInsert
instead. Will be deprecated in 0.10.
runUpdate_ :: Connection -> Update haskells -> IO haskells Source #
Use runUpdate
instead. Will be deprecated in 0.10.
runDelete_ :: Connection -> Delete haskells -> IO haskells Source #
Use runDelete
instead. Will be deprecated in 0.10.
DoNothing
Use doNothing
instead.
DoNothing
will be deprecated in
version 0.10.
data OnConflict Source #
DoNothing | ON CONFLICT DO NOTHING |