Safe Haskell | None |
---|---|
Language | Haskell2010 |
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;
- runInsertMany :: Connection -> Table columns columns' -> [columns] -> IO Int64
- runInsertManyReturning :: Default 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 PGBool) -> IO Int64
- runUpdate :: Connection -> Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column PGBool) -> IO Int64
- runUpdateReturning :: Default QueryRunner columnsReturned haskells => Connection -> Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column PGBool) -> (columnsR -> columnsReturned) -> IO [haskells]
- runDelete :: Connection -> Table a columnsR -> (columnsR -> Column PGBool) -> IO Int64
- 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]
- runUpdateReturningExplicit :: QueryRunner columnsReturned haskells -> Connection -> Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column PGBool) -> (columnsR -> columnsReturned) -> IO [haskells]
- runInsert :: Connection -> Table columns columns' -> columns -> IO Int64
- runInsertReturning :: Default QueryRunner columnsReturned haskells => Connection -> Table columnsW columnsR -> columnsW -> (columnsR -> columnsReturned) -> 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 PGBool) -> SqlUpdate
- arrangeUpdateSql :: Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column PGBool) -> String
- arrangeDelete :: Table a columnsR -> (columnsR -> Column PGBool) -> SqlDelete
- arrangeDeleteSql :: Table a columnsR -> (columnsR -> Column PGBool) -> 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 PGBool) -> (columnsR -> columnsReturned) -> Returning SqlUpdate
- arrangeUpdateReturningSql :: Unpackspec columnsReturned ignored -> Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column PGBool) -> (columnsR -> columnsReturned) -> String
- data Unpackspec columns columns'
Manipulation functions
:: 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 #
:: Default QueryRunner columnsReturned haskells | |
=> Connection | |
-> Table columnsW columnsR | Table to insert into |
-> [columnsW] | Rows to insert |
-> (columnsR -> columnsReturned) | Function |
-> IO [haskells] | Returned rows after |
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
.
:: Default Updater columnsR columnsW | |
=> Connection | |
-> Table columnsW columnsR | Table to update |
-> (columnsR -> columnsR) | Update function to apply to chosen rows |
-> (columnsR -> Column PGBool) | Predicate function |
-> IO Int64 | The number of rows updated |
Update rows in a table.
(N.B. runUpdateEasy'
s "returning" counterpart
"runUpdateEasyReturning
" hasn't been implemented. File an
issue if you want it!)
:: Connection | |
-> Table columnsW columnsR | Table to update |
-> (columnsR -> columnsW) | Update function to apply to chosen rows |
-> (columnsR -> Column PGBool) | Predicate function |
-> IO Int64 | The number of rows updated |
Update rows in a table. You'll probably find it more convenient
to use runUpdateEasy
(although runUpdate
provides more
fine-grained control if you need it).
Be careful: providing Nothing
to a column created by optional
updates the column to its default value. Many users have been
confused by this because they assume it means that the column is to
be left unchanged.
:: 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 |
-> (columnsR -> columnsReturned) | Functon |
-> IO [haskells] | Returned rows after |
Update rows in a table and return a function of the updated rows
Be careful: providing Nothing
to a column created by optional
updates the column to its default value. Many users have been
confused by this because they assume it means that the column is to
be left unchanged.
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
.
:: Connection | |
-> Table a columnsR | Table to delete rows from |
-> (columnsR -> Column PGBool) | Predicate function |
-> 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 #
Deprecated: runInsert
will be removed in version 0.7. Use runInsertMany
instead.
Returns the number of rows inserted
runInsertReturning :: Default QueryRunner columnsReturned haskells => Connection -> Table columnsW columnsR -> columnsW -> (columnsR -> columnsReturned) -> 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 PGBool) -> SqlUpdate Source #
Deprecated: You probably want runUpdate
instead. Will be removed in version 0.7.
arrangeUpdateSql :: Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Column PGBool) -> String Source #
Deprecated: You probably want runUpdate
instead. Will be removed in version 0.7.
arrangeDelete :: Table a columnsR -> (columnsR -> Column PGBool) -> SqlDelete Source #
Deprecated: You probably want runDelete
instead. Will be removed in version 0.7.
arrangeDeleteSql :: Table a columnsR -> (columnsR -> Column PGBool) -> 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 PGBool) -> (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 PGBool) -> (columnsR -> columnsReturned) -> String Source #
Deprecated: You probably want runUpdateReturning
instead. Will be removed in version 0.7.
Other
data Unpackspec columns columns' Source #