opaleye-0.9.2.0: An SQL-generating DSL targeting PostgreSQL
Safe HaskellNone
LanguageHaskell2010

Opaleye.Manipulation

Description

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

Insert

runInsert Source #

Arguments

:: Connection 
-> Insert haskells 
-> IO haskells

Returns a type that depends on the Returning that you provided when creating the Insert.

Run the Insert. To create an Insert use the Insert constructor.

data Insert haskells Source #

Constructors

forall fieldsW fieldsR. Insert 

Fields

Update

runUpdate Source #

Arguments

:: Connection 
-> Update haskells 
-> IO haskells

Returns a type that depends on the Returning that you provided when creating the Update.

Run the Update. To create an Update use the Update constructor.

data Update haskells Source #

Constructors

forall fieldsW fieldsR. Update 

Fields

updateEasy Source #

Arguments

:: Default Updater fieldsR fieldsW 
=> (fieldsR -> fieldsR) 
-> fieldsR -> fieldsW 

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

runDelete Source #

Arguments

:: Connection 
-> Delete haskells 
-> IO haskells

Returns a type that depends on the Returning that you provided when creating the Delete.

Run the Delete. To create an Delete use the Delete constructor.

data Delete haskells Source #

Constructors

forall fieldsW fieldsR. Delete 

Fields

Returning

data Returning fields haskells Source #

Represents a RETURNING statement for a manipulation query.

rCount :: Returning fieldsR Int64 Source #

Return the number of rows inserted or updated

rReturning Source #

Arguments

:: 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 Source #

Arguments

:: 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 Source #

Arguments

:: 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.

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 #

Constructors

DoNothing
ON CONFLICT DO NOTHING