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
- data Delete haskells = forall fieldsW fieldsR. Delete {}
- data Update haskells = forall fieldsW fieldsR. Update {
- uTable :: Table fieldsW fieldsR
- uUpdateWith :: fieldsR -> fieldsW
- uWhere :: fieldsR -> Field SqlBool
- uReturning :: Returning fieldsR haskells
- data Insert haskells = forall fieldsW fieldsR. Insert {
- iTable :: Table fieldsW fieldsR
- iRows :: [fieldsW]
- iReturning :: Returning fieldsR haskells
- iOnConflict :: Maybe OnConflict
- runInsert_ :: Connection -> Insert haskells -> IO haskells
- runUpdate_ :: Connection -> Update haskells -> IO haskells
- runDelete_ :: Connection -> Delete haskells -> IO haskells
- updateEasy :: Default Updater fieldsR fieldsW => (fieldsR -> fieldsR) -> fieldsR -> fieldsW
- 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]
- runInsertManyOnConflictDoNothing :: Connection -> Table columns columns' -> [columns] -> IO Int64
- runInsertManyReturningOnConflictDoNothing :: Default FromFields columnsReturned haskells => Connection -> Table columnsW columnsR -> [columnsW] -> (columnsR -> columnsReturned) -> IO [haskells]
- runInsertMany :: Connection -> Table columns columns' -> [columns] -> IO Int64
- runInsertManyReturning :: Default FromFields columnsReturned haskells => Connection -> Table columnsW columnsR -> [columnsW] -> (columnsR -> columnsReturned) -> IO [haskells]
- runInsertReturningExplicit :: FromFields columnsReturned haskells -> Connection -> Table columnsW columnsR -> columnsW -> (columnsR -> columnsReturned) -> IO [haskells]
- runInsertManyReturningExplicit :: FromFields columnsReturned haskells -> Connection -> Table columnsW columnsR -> [columnsW] -> (columnsR -> columnsReturned) -> IO [haskells]
- runInsertManyReturningOnConflictDoNothingExplicit :: FromFields columnsReturned haskells -> Connection -> Table columnsW columnsR -> [columnsW] -> (columnsR -> columnsReturned) -> IO [haskells]
- runUpdateEasy :: Default Updater columnsR columnsW => Connection -> Table columnsW columnsR -> (columnsR -> columnsR) -> (columnsR -> Column SqlBool) -> IO Int64
- runUpdate :: Connection -> Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column SqlBool) -> IO Int64
- runUpdateReturning :: Default FromFields columnsReturned haskells => Connection -> Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column SqlBool) -> (columnsR -> columnsReturned) -> IO [haskells]
- runUpdateReturningExplicit :: FromFields columnsReturned haskells -> Connection -> Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column SqlBool) -> (columnsR -> columnsReturned) -> IO [haskells]
- runDelete :: Connection -> Table a columnsR -> (columnsR -> Column SqlBool) -> IO Int64
- data OnConflict = DoNothing
Documentation
forall fieldsW fieldsR. Update | |
|
forall fieldsW fieldsR. Insert | |
|
:: Connection | |
-> Insert haskells | |
-> IO haskells | Returns a type that depends on the |
:: Connection | |
-> Update haskells | |
-> IO haskells | Returns a type that depends on the |
:: Connection | |
-> Delete haskells | |
-> IO haskells | Returns a type that depends on the |
A convenient wrapper for writing your update function
uUpdateWith = updateEasy (\... -> ...)
:: 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.
runInsertManyOnConflictDoNothing Source #
:: Connection | |
-> Table columns columns' | Table to insert into |
-> [columns] | Rows to insert |
-> IO Int64 | Number of rows inserted |
Deprecated: Use runInsert_
. Will be removed in version 0.8.
Insert rows into a table with ON CONFLICT DO NOTHING
runInsertManyReturningOnConflictDoNothing Source #
:: Default FromFields columnsReturned haskells | |
=> Connection | |
-> Table columnsW columnsR | Table to insert into |
-> [columnsW] | Rows to insert |
-> (columnsR -> columnsReturned) | Function |
-> IO [haskells] | Returned rows after |
Deprecated: Use runInsert_
. Will be removed in version 0.8.
Insert rows into a table with ON CONFLICT DO NOTHING
and
return a function of the inserted rows
runInsertManyReturningOnConflictDoNothing
's use of the
Default
typeclass means that the compiler will have trouble
inferring types. It is strongly recommended that you provide full
type signatures when using it.
:: Connection | |
-> Table columns columns' | Table to insert into |
-> [columns] | Rows to insert |
-> IO Int64 | Number of rows inserted |
Deprecated: Use runInsert_
instead. Will be removed in version 0.8.
runInsertManyReturning Source #
:: Default FromFields columnsReturned haskells | |
=> Connection | |
-> Table columnsW columnsR | Table to insert into |
-> [columnsW] | Rows to insert |
-> (columnsR -> columnsReturned) | Function |
-> IO [haskells] | Returned rows after |
Deprecated: Use runInsert_
instead. Will be removed in version 0.8.
runInsertReturningExplicit :: FromFields columnsReturned haskells -> Connection -> Table columnsW columnsR -> columnsW -> (columnsR -> columnsReturned) -> IO [haskells] Source #
Deprecated: Use runInsert_
instead. Will be removed in version 0.8.
runInsertManyReturningExplicit :: FromFields columnsReturned haskells -> Connection -> Table columnsW columnsR -> [columnsW] -> (columnsR -> columnsReturned) -> IO [haskells] Source #
Deprecated: Use runInsert_
instead. Will be removed in version 0.8.
runInsertManyReturningOnConflictDoNothingExplicit :: FromFields columnsReturned haskells -> Connection -> Table columnsW columnsR -> [columnsW] -> (columnsR -> columnsReturned) -> IO [haskells] Source #
Deprecated: Use runInsert_
instead. Will be removed in version 0.8.
:: Default Updater columnsR columnsW | |
=> Connection | |
-> Table columnsW columnsR | Table to update |
-> (columnsR -> columnsR) | Update function to apply to chosen rows |
-> (columnsR -> Column SqlBool) | Predicate function |
-> IO Int64 | The number of rows updated |
Deprecated: Use runUpdate_
instead. Will be removed in version 0.8.
:: Connection | |
-> Table columnsW columnsR | Table to update |
-> (columnsR -> columnsW) | Update function to apply to chosen rows |
-> (columnsR -> Column SqlBool) | Predicate function |
-> IO Int64 | The number of rows updated |
Deprecated: Use runUpdate_
instead. Will be removed in version 0.8.
:: Default FromFields columnsReturned haskells | |
=> Connection | |
-> Table columnsW columnsR | Table to update |
-> (columnsR -> columnsW) | Update function to apply to chosen rows |
-> (columnsR -> Column SqlBool) | Predicate function |
-> (columnsR -> columnsReturned) | Functon |
-> IO [haskells] | Returned rows after |
Deprecated: Use runUpdate_
instead. Will be removed in version 0.8.
runUpdateReturningExplicit :: FromFields columnsReturned haskells -> Connection -> Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column SqlBool) -> (columnsR -> columnsReturned) -> IO [haskells] Source #
Deprecated: Use runUpdate_
instead. Will be removed in version 0.8.
:: Connection | |
-> Table a columnsR | Table to delete rows from |
-> (columnsR -> Column SqlBool) | Predicate function |
-> IO Int64 | The number of rows deleted |
Deprecated: Use runDelete_
instead. Will be removed in version 0.8.
Currently DoNothing
is the
only conflict action supported by
Opaleye.
data OnConflict Source #
DoNothing | ON CONFLICT DO NOTHING |