opaleye-0.5.2.2: An SQL-generating DSL targeting PostgreSQL

Safe HaskellNone
LanguageHaskell2010

Opaleye.Manipulation

Contents

Description

Inserts, updates and deletes

Please note that you currently you can only 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

Manipulation functions

runInsertMany Source #

Arguments

:: Connection 
-> Table columns columns'

Table to insert into

-> [columns]

Rows to insert

-> IO Int64

Number of rows inserted

Insert rows into a table

runInsertManyReturning Source #

Arguments

:: Default QueryRunner 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

Insert rows into a table and return a function of the inserted rows

runInsertManyReturning'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 runInsertManyReturning.

runUpdate Source #

Arguments

:: Connection 
-> Table columnsW columnsR

Table to update

-> (columnsR -> columnsW)

Update function to apply to chosen rows

-> (columnsR -> Column PGBool)

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

Update rows in a table

runUpdateReturning Source #

Arguments

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

Table to update

-> (columnsR -> columnsW)

Update function to apply to chosen rows

-> (columnsR -> Column PGBool)

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

Update rows in a table and return a function of the updated rows

runUpdateReturning'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.

runDelete Source #

Arguments

:: Connection 
-> Table a columnsR

Table to delete rows from

-> (columnsR -> Column PGBool)

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

Delete rows from a table

Explicit versions

runInsertReturningExplicit :: QueryRunner columnsReturned haskells -> Connection -> Table columnsW columnsR -> columnsW -> (columnsR -> columnsReturned) -> IO [haskells] Source #

You probably don't need this, but can just use runInsertReturning instead. You only need it if you want to run an INSERT RETURNING statement but need to be explicit about the QueryRunner.

runInsertManyReturningExplicit :: QueryRunner columnsReturned haskells -> Connection -> Table columnsW columnsR -> [columnsW] -> (columnsR -> columnsReturned) -> IO [haskells] Source #

You probably don't need this, but can just use runInsertManyReturning instead. You only need it if you want to run an UPDATE RETURNING statement but need to be explicit about the QueryRunner.

runUpdateReturningExplicit :: QueryRunner columnsReturned haskells -> Connection -> Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column PGBool) -> (columnsR -> columnsReturned) -> IO [haskells] Source #

You probably don't need this, but can just use runUpdateReturning instead. You only need it if you want to run an UPDATE RETURNING statement but need to be explicit about the QueryRunner.

Deprecated versions

runInsert :: Connection -> Table columns columns' -> columns -> IO Int64 Source #

Returns the number of rows inserted

This will be deprecated in version 0.6. Use runInsertMany instead.

runInsertReturning :: Default QueryRunner columnsReturned haskells => Connection -> Table columnsW columnsR -> columnsW -> (columnsR -> columnsReturned) -> IO [haskells] Source #

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.

This will be deprecated in version 0.6. Use runInsertManyReturning instead.

arrangeInsert :: Table columns a -> columns -> SqlInsert Source #

For internal use only. Do not use. Will be deprecated in version 0.6.

arrangeInsertSql :: Table columns a -> columns -> String Source #

For internal use only. Do not use. Will be deprecated in version 0.6.

arrangeInsertMany :: Table columns a -> NonEmpty columns -> SqlInsert Source #

For internal use only. Do not use. Will be deprecated in version 0.6.

arrangeInsertManySql :: Table columns a -> NonEmpty columns -> String Source #

For internal use only. Do not use. Will be deprecated in version 0.6.

arrangeUpdate :: Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column PGBool) -> SqlUpdate Source #

For internal use only. Do not use. Will be deprecated in version 0.6.

arrangeUpdateSql :: Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column PGBool) -> String Source #

For internal use only. Do not use. Will be deprecated in version 0.6.

arrangeDelete :: Table a columnsR -> (columnsR -> Column PGBool) -> SqlDelete Source #

For internal use only. Do not use. Will be deprecated in version 0.6.

arrangeDeleteSql :: Table a columnsR -> (columnsR -> Column PGBool) -> String Source #

For internal use only. Do not use. Will be deprecated in version 0.6.

arrangeInsertManyReturning :: Unpackspec columnsReturned ignored -> Table columnsW columnsR -> NonEmpty columnsW -> (columnsR -> columnsReturned) -> Returning SqlInsert Source #

For internal use only. Do not use. Will be deprecated in version 0.6.

arrangeInsertManyReturningSql :: Unpackspec columnsReturned ignored -> Table columnsW columnsR -> NonEmpty columnsW -> (columnsR -> columnsReturned) -> String Source #

For internal use only. Do not use. Will be deprecated in version 0.6.

arrangeUpdateReturning :: Unpackspec columnsReturned ignored -> Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column PGBool) -> (columnsR -> columnsReturned) -> Returning SqlUpdate Source #

For internal use only. Do not use. Will be deprecated in version 0.6.

arrangeUpdateReturningSql :: Unpackspec columnsReturned ignored -> Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column PGBool) -> (columnsR -> columnsReturned) -> String Source #

For internal use only. Do not use. Will be deprecated in version 0.6.

Other

data Unpackspec columns columns' Source #

Instances

SumProfunctor Unpackspec Source # 

Methods

(+++!) :: Unpackspec a b -> Unpackspec a' b' -> Unpackspec (Either a a') (Either b b') #

ProductProfunctor Unpackspec Source # 

Methods

empty :: Unpackspec () () #

(***!) :: Unpackspec a b -> Unpackspec a' b' -> Unpackspec (a, a') (b, b') #

Profunctor Unpackspec Source # 

Methods

dimap :: (a -> b) -> (c -> d) -> Unpackspec b c -> Unpackspec a d #

lmap :: (a -> b) -> Unpackspec b c -> Unpackspec a c #

rmap :: (b -> c) -> Unpackspec a b -> Unpackspec a c #

(#.) :: Coercible * c b => (b -> c) -> Unpackspec a b -> Unpackspec a c #

(.#) :: Coercible * b a => Unpackspec b c -> (a -> b) -> Unpackspec a c #

Default Unpackspec (Column a) (Column a) Source # 

Methods

def :: Unpackspec (Column a) (Column a) #

Functor (Unpackspec a) Source # 

Methods

fmap :: (a -> b) -> Unpackspec a a -> Unpackspec a b #

(<$) :: a -> Unpackspec a b -> Unpackspec a a #

Applicative (Unpackspec a) Source # 

Methods

pure :: a -> Unpackspec a a #

(<*>) :: Unpackspec a (a -> b) -> Unpackspec a a -> Unpackspec a b #

(*>) :: Unpackspec a a -> Unpackspec a b -> Unpackspec a b #

(<*) :: Unpackspec a a -> Unpackspec a b -> Unpackspec a a #