opaleye-0.7.3.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

Documentation

data Delete haskells Source #

Constructors

forall fieldsW fieldsR. Delete 

Fields

data Update haskells Source #

Constructors

forall fieldsW fieldsR. Update 

Fields

data Insert haskells Source #

Constructors

forall fieldsW fieldsR. Insert 

Fields

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.

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.

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.

updateEasy Source #

Arguments

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

A convenient wrapper for writing your update function

uUpdateWith = updateEasy (\... -> ...)

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.

runInsertManyOnConflictDoNothing Source #

Arguments

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

Arguments

:: Default FromFields columnsReturned haskells 
=> Connection 
-> Table columnsW columnsR

Table to insert into

-> [columnsW]

Rows to insert

-> (columnsR -> columnsReturned)

Function f to apply to the inserted rows

-> IO [haskells]

Returned rows after f has been applied

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.

runInsertMany Source #

Arguments

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

Arguments

:: Default FromFields columnsReturned haskells 
=> Connection 
-> Table columnsW columnsR

Table to insert into

-> [columnsW]

Rows to insert

-> (columnsR -> columnsReturned)

Function f to apply to the inserted rows

-> IO [haskells]

Returned rows after f has been applied

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.

runUpdateEasy Source #

Arguments

:: 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 f to choose which rows to update. runUpdate will update rows for which f returns TRUE and leave unchanged rows for which f returns FALSE.

-> IO Int64

The number of rows updated

Deprecated: Use runUpdate_ instead. Will be removed in version 0.8.

runUpdate Source #

Arguments

:: Connection 
-> Table columnsW columnsR

Table to update

-> (columnsR -> columnsW)

Update function to apply to chosen rows

-> (columnsR -> Column SqlBool)

Predicate function f to choose which rows to update. runUpdate will update rows for which f returns TRUE and leave unchanged rows for which f returns FALSE.

-> IO Int64

The number of rows updated

Deprecated: Use runUpdate_ instead. Will be removed in version 0.8.

runUpdateReturning Source #

Arguments

:: 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 f to choose which rows to update. runUpdate will update rows for which f returns TRUE and leave unchanged rows for which f returns FALSE.

-> (columnsR -> columnsReturned)

Functon g to apply to the updated rows

-> IO [haskells]

Returned rows after g has been applied

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.

runDelete Source #

Arguments

:: Connection 
-> Table a columnsR

Table to delete rows from

-> (columnsR -> Column SqlBool)

Predicate function f to choose which rows to delete. runDelete will delete rows for which f returns TRUE and leave unchanged rows for which f returns FALSE.

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

Constructors

DoNothing
ON CONFLICT DO NOTHING