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 = Delete {}
- data Update haskells = Update {
- uTable :: Table fieldsW fieldsR
- uUpdateWith :: fieldsR -> fieldsW
- uWhere :: fieldsR -> Field SqlBool
- uReturning :: Returning fieldsR haskells
- data Insert haskells = 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 QueryRunner fields haskells => (fieldsR -> fields) -> Returning fieldsR [haskells]
- rReturningExplicit :: QueryRunner fields haskells -> (fieldsR -> fields) -> Returning fieldsR [haskells]
- runInsert :: Connection -> Table fields fields' -> fields -> IO Int64
- runInsertReturning :: Default QueryRunner fieldsReturned haskells => Connection -> Table fieldsW fieldsR -> fieldsW -> (fieldsR -> fieldsReturned) -> IO [haskells]
- arrangeInsert :: Table columns a -> columns -> SqlInsert
- arrangeInsertSql :: Table columns a -> columns -> String
- arrangeInsertMany :: Table columns a -> NonEmpty columns -> SqlInsert
- arrangeInsertManySql :: Table columns a -> NonEmpty columns -> String
- arrangeUpdate :: Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column SqlBool) -> SqlUpdate
- arrangeUpdateSql :: Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column SqlBool) -> String
- arrangeDelete :: Table a columnsR -> (columnsR -> Column SqlBool) -> SqlDelete
- arrangeDeleteSql :: Table a columnsR -> (columnsR -> Column SqlBool) -> String
- arrangeInsertManyReturning :: Unpackspec columnsReturned ignored -> Table columnsW columnsR -> NonEmpty columnsW -> (columnsR -> columnsReturned) -> Returning SqlInsert
- arrangeInsertManyReturningSql :: Unpackspec columnsReturned ignored -> Table columnsW columnsR -> NonEmpty columnsW -> (columnsR -> columnsReturned) -> String
- arrangeUpdateReturning :: Unpackspec columnsReturned ignored -> Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column SqlBool) -> (columnsR -> columnsReturned) -> Returning SqlUpdate
- arrangeUpdateReturningSql :: Unpackspec columnsReturned ignored -> Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column SqlBool) -> (columnsR -> columnsReturned) -> String
- runInsertManyOnConflictDoNothing :: Connection -> Table columns columns' -> [columns] -> IO Int64
- runInsertManyReturningOnConflictDoNothing :: Default QueryRunner columnsReturned haskells => Connection -> Table columnsW columnsR -> [columnsW] -> (columnsR -> columnsReturned) -> IO [haskells]
- runInsertMany :: Connection -> Table columns columns' -> [columns] -> IO Int64
- runInsertManyReturning :: Default QueryRunner columnsReturned haskells => Connection -> Table columnsW columnsR -> [columnsW] -> (columnsR -> columnsReturned) -> IO [haskells]
- runInsertReturningExplicit :: QueryRunner columnsReturned haskells -> Connection -> Table columnsW columnsR -> columnsW -> (columnsR -> columnsReturned) -> IO [haskells]
- runInsertManyReturningExplicit :: QueryRunner columnsReturned haskells -> Connection -> Table columnsW columnsR -> [columnsW] -> (columnsR -> columnsReturned) -> IO [haskells]
- runInsertManyReturningOnConflictDoNothingExplicit :: QueryRunner 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 QueryRunner columnsReturned haskells => Connection -> Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column SqlBool) -> (columnsR -> columnsReturned) -> IO [haskells]
- runUpdateReturningExplicit :: QueryRunner 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 Unpackspec columns columns'
- data OnConflict = DoNothing
Documentation
Update | |
|
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 QueryRunner fields haskells | |
=> (fieldsR -> fields) | |
-> Returning fieldsR [haskells] |
Return a function of the inserted or updated rows
rReturning'
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
rReturning
.
:: QueryRunner 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.
runInsert :: Connection -> Table fields fields' -> fields -> IO Int64 Source #
Deprecated: runInsert
will be removed in version 0.7. Use runInsertMany
instead.
Returns the number of rows inserted
runInsertReturning :: Default QueryRunner fieldsReturned haskells => Connection -> Table fieldsW fieldsR -> fieldsW -> (fieldsR -> fieldsReturned) -> IO [haskells] Source #
Deprecated: runInsertReturning
will be removed in version 0.7. Use runInsertManyReturning
instead.
runInsertReturning
'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
runInsertReturning
.
arrangeInsert :: Table columns a -> columns -> SqlInsert Source #
Deprecated: You probably want runInsertMany
instead. Will be removed in version 0.7.
arrangeInsertSql :: Table columns a -> columns -> String Source #
Deprecated: You probably want runInsertMany
instead. Will be removed in version 0.7.
arrangeInsertMany :: Table columns a -> NonEmpty columns -> SqlInsert Source #
Deprecated: You probably want runInsertMany
instead. Will be removed in version 0.7.
arrangeInsertManySql :: Table columns a -> NonEmpty columns -> String Source #
Deprecated: You probably want runInsertMany
instead. Will be removed in version 0.7.
arrangeUpdate :: Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column SqlBool) -> SqlUpdate Source #
Deprecated: You probably want runUpdate
instead. Will be removed in version 0.7.
arrangeUpdateSql :: Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column SqlBool) -> String Source #
Deprecated: You probably want runUpdate
instead. Will be removed in version 0.7.
arrangeDelete :: Table a columnsR -> (columnsR -> Column SqlBool) -> SqlDelete Source #
Deprecated: You probably want runDelete
instead. Will be removed in version 0.7.
arrangeDeleteSql :: Table a columnsR -> (columnsR -> Column SqlBool) -> String Source #
Deprecated: You probably want runDelete
instead. Will be removed in version 0.7.
arrangeInsertManyReturning :: Unpackspec columnsReturned ignored -> Table columnsW columnsR -> NonEmpty columnsW -> (columnsR -> columnsReturned) -> Returning SqlInsert Source #
Deprecated: You probably want runInsertMany
instead. Will be removed in version 0.7.
arrangeInsertManyReturningSql :: Unpackspec columnsReturned ignored -> Table columnsW columnsR -> NonEmpty columnsW -> (columnsR -> columnsReturned) -> String Source #
Deprecated: You probably want runInsertManyReturning
instead. Will be removed in version 0.7.
arrangeUpdateReturning :: Unpackspec columnsReturned ignored -> Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column SqlBool) -> (columnsR -> columnsReturned) -> Returning SqlUpdate Source #
Deprecated: You probably want runUpdateReturning
instead. Will be removed in version 0.7.
arrangeUpdateReturningSql :: Unpackspec columnsReturned ignored -> Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column SqlBool) -> (columnsR -> columnsReturned) -> String Source #
Deprecated: You probably want runUpdateReturning
instead. Will be removed in version 0.7.
runInsertManyOnConflictDoNothing Source #
:: Connection | |
-> Table columns columns' | Table to insert into |
-> [columns] | Rows to insert |
-> IO Int64 | Number of rows inserted |
Deprecated: Use runInsert_
Insert rows into a table with ON CONFLICT DO NOTHING
runInsertManyReturningOnConflictDoNothing Source #
:: Default QueryRunner 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_
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 |
Use runInsert_
instead. Will be deprecated in version 0.7.
runInsertManyReturning Source #
:: Default QueryRunner columnsReturned haskells | |
=> Connection | |
-> Table columnsW columnsR | Table to insert into |
-> [columnsW] | Rows to insert |
-> (columnsR -> columnsReturned) | Function |
-> IO [haskells] | Returned rows after |
Use runInsert_
instead. Will be deprecated in version 0.7.
runInsertReturningExplicit :: QueryRunner columnsReturned haskells -> Connection -> Table columnsW columnsR -> columnsW -> (columnsR -> columnsReturned) -> IO [haskells] Source #
Use runInsert_
instead. Will be deprecated in version 0.7.
runInsertManyReturningExplicit :: QueryRunner columnsReturned haskells -> Connection -> Table columnsW columnsR -> [columnsW] -> (columnsR -> columnsReturned) -> IO [haskells] Source #
Use runInsert_
instead. Will be deprecated in version 0.7.
runInsertManyReturningOnConflictDoNothingExplicit :: QueryRunner columnsReturned haskells -> Connection -> Table columnsW columnsR -> [columnsW] -> (columnsR -> columnsReturned) -> IO [haskells] Source #
Use runInsert_
instead. Will be deprecated in version 0.7.
:: 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 |
Use runUpdate_
instead. Will be deprecated in version 0.7.
:: 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 |
Use runUpdate_
instead. Will be deprecated in version 0.7.
:: Default QueryRunner 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 |
Use runUpdate_
instead. Will be deprecated in version 0.7.
runUpdateReturningExplicit :: QueryRunner columnsReturned haskells -> Connection -> Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column SqlBool) -> (columnsR -> columnsReturned) -> IO [haskells] Source #
Use runUpdate_
instead. Will be deprecated in version 0.7.
:: Connection | |
-> Table a columnsR | Table to delete rows from |
-> (columnsR -> Column SqlBool) | Predicate function |
-> IO Int64 | The number of rows deleted |
Use runDelete_
instead. Will be deprecated in 0.7.
Other
Do not use the export of
Unpackspec
. It will not be
exported in version 0.7.
data Unpackspec columns columns' Source #
Instances
Currently DoNothing
is the
only conflict action supported by
Opaleye.
data OnConflict Source #
DoNothing | ON CONFLICT DO NOTHING |