Moduleopaleye-0.10.8.0Haskell2010
Opaleye.Manipulation
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;
- 6 types
- 12 values
- Packageopaleye-0.10.8.0
- Exports18
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceManipulation.hs
Insert
2 declarationsConstructors
forall fieldsW fieldsR. InsertiTable :: Table fieldsW fieldsRiRows :: [fieldsW]iReturning :: Returning fieldsR haskellsiOnConflict :: Maybe OnConflictNB There is a clash of terminology between Haskell and Postgres.
iOnConflict
=Nothing means omitON CONFLICTstatementiOnConflict
=JustHSql.doNothingmeansON CONFLICT DO NOTHING
Update
3 declarationsConstructors
forall fieldsW fieldsR. UpdateuTable :: Table fieldsW fieldsRuUpdateWith :: fieldsR -> fieldsWBe careful: providing Nothing to a field created by
Opaleye.Table.optionalTableFieldupdates the field to its default value. Many users have been confused by this because they assume it means that the field is to be left unchanged. For an easier time wrap your update function in updateEasy.uWhere :: fieldsR -> Field SqlBooluReturning :: Returning fieldsR haskells
A convenient wrapper for writing your update function.
updateEasy protects you from accidentally updating an
Opaleye.Table.optionalTableField with Nothing (i.e. SQL
DEFAULT). See uUpdateWith.
uUpdateWith = updateEasy (\... -> ...)Delete
2 declarationsReturning
5 declarationsRepresents a RETURNING statement for a manipulation query.
Return the number of rows inserted or updated
rReturning :: Default FromFields fields haskells=> (fieldsR -> fields)͘
-> Returning fieldsR [haskells]
Return a function of the inserted or updated rows
rReturning's use of the Default FromFields
typeclass means that the
compiler will have trouble inferring types. It is strongly
recommended that you provide full type signatures when using
rReturning.
rReturningI :: 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.
rReturningExplicit :: 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
2 declarationsCurrently doNothing is the only conflict action supported by Opaleye.
Deprecated
3 declarationsDeprecated. Use runInsert instead. Will be removed in 0.11.
Deprecated. Use runUpdate instead. Will be removed in 0.11.
Deprecated. Use runDelete instead. Will be removed in 0.11.
DoNothing
Use doNothing instead.
DoNothing will be removed in
version 0.11.
Constructors
DoNothingON CONFLICT DO NOTHING