| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Database.Beam.Backend.SQL.BeamExtensions
Description
Some functionality is useful enough to be provided across backends, but is not standardized. For example, many RDBMS systems provide ways of fetching auto-incrementing or defaulting fields on INSERT or UPDATE.
Beam provides type classes that some backends instantiate that provide this support. This uses direct means on sufficiently advanced backends and is emulated on others.
Synopsis
- class MonadBeam be m => MonadBeamInsertReturning be (m :: Type -> Type) | m -> be where
- runInsertReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlInsert be table -> (table (QExpr be ()) -> a) -> m [QExprToIdentity a]
- runInsertReturningList :: (MonadBeamInsertReturning be m, Beamable table, Projectible be (table (QExpr be ())), FromBackendRow be (table Identity)) => SqlInsert be table -> m [table Identity]
- class MonadBeam be m => MonadBeamUpdateReturning be (m :: Type -> Type) | m -> be where
- runUpdateReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlUpdate be table -> (table (QExpr be ()) -> a) -> m [QExprToIdentity a]
- runUpdateReturningList :: (MonadBeamUpdateReturning be m, Beamable table, Projectible be (table (QExpr be ())), FromBackendRow be (table Identity)) => SqlUpdate be table -> m [table Identity]
- class MonadBeam be m => MonadBeamDeleteReturning be (m :: Type -> Type) | m -> be where
- runDeleteReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlDelete be table -> (table (QExpr be ()) -> a) -> m [QExprToIdentity a]
- runDeleteReturningList :: (MonadBeamDeleteReturning be m, Beamable table, Projectible be (table (QExpr be ())), FromBackendRow be (table Identity)) => SqlDelete be table -> m [table Identity]
- class BeamSqlBackend be => BeamHasInsertOnConflict be where
- data SqlConflictTarget be (table :: (Type -> Type) -> Type)
- data SqlConflictAction be (table :: (Type -> Type) -> Type)
- insertOnConflict :: forall table (db :: (Type -> Type) -> Type) s. Beamable table => DatabaseEntity be db (TableEntity table) -> SqlInsertValues be (table (QExpr be s)) -> SqlConflictTarget be table -> SqlConflictAction be table -> SqlInsert be table
- anyConflict :: forall (table :: (Type -> Type) -> Type). SqlConflictTarget be table
- conflictingFields :: Projectible be proj => (table (QExpr be QInternal) -> proj) -> SqlConflictTarget be table
- conflictingFieldsWhere :: Projectible be proj => (table (QExpr be QInternal) -> proj) -> (forall s. table (QExpr be s) -> QExpr be s Bool) -> SqlConflictTarget be table
- onConflictDoNothing :: forall (table :: (Type -> Type) -> Type). SqlConflictAction be table
- onConflictUpdateSet :: Beamable table => (forall s. table (QField s) -> table (QExpr be s) -> QAssignment be s) -> SqlConflictAction be table
- onConflictUpdateSetWhere :: Beamable table => (forall s. table (QField s) -> table (QExpr be s) -> QAssignment be s) -> (forall s. table (QField s) -> table (QExpr be s) -> QExpr be s Bool) -> SqlConflictAction be table
- newtype SqlSerial a = SqlSerial {
- unSerial :: a
- onConflictUpdateInstead :: (BeamHasInsertOnConflict be, Beamable table, ProjectibleWithPredicate AnyType () (InaccessibleQAssignment be) proj) => (table (Const (InaccessibleQAssignment be) :: Type -> Type) -> proj) -> SqlConflictAction be table
- onConflictUpdateAll :: forall be (table :: (Type -> Type) -> Type). (BeamHasInsertOnConflict be, Beamable table) => SqlConflictAction be table
Documentation
class MonadBeam be m => MonadBeamInsertReturning be (m :: Type -> Type) | m -> be where Source #
MonadBeams that support returning data from the newly created rows of an
INSERT statement. Useful for discovering the real value of a defaulted
field (such as a serial primary key).
Methods
runInsertReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlInsert be table -> (table (QExpr be ()) -> a) -> m [QExprToIdentity a] Source #
Execute an INSERT statement and return a list of values projected from
the inserted rows. The projection function selects which columns are
returned: pass id to return the full row, or supply a custom
projection to return a subset.
Instances
runInsertReturningList :: (MonadBeamInsertReturning be m, Beamable table, Projectible be (table (QExpr be ())), FromBackendRow be (table Identity)) => SqlInsert be table -> m [table Identity] Source #
Execute an INSERT statement and return the inserted rows in full.
A convenience around runInsertReturningListWith that uses id as the
projection.
class MonadBeam be m => MonadBeamUpdateReturning be (m :: Type -> Type) | m -> be where Source #
MonadBeams that support returning data from the updated rows of an
UPDATE statement. Useful for observing the post-update values of the
affected rows.
Methods
runUpdateReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlUpdate be table -> (table (QExpr be ()) -> a) -> m [QExprToIdentity a] Source #
Execute an UPDATE statement and return a list of values projected from
the updated rows. The projection function selects which columns are
returned: pass id to return the full row, or supply a custom
projection to return a subset.
Instances
runUpdateReturningList :: (MonadBeamUpdateReturning be m, Beamable table, Projectible be (table (QExpr be ())), FromBackendRow be (table Identity)) => SqlUpdate be table -> m [table Identity] Source #
Execute an UPDATE statement and return the updated rows in full.
A convenience around runUpdateReturningListWith that uses id as the
projection.
class MonadBeam be m => MonadBeamDeleteReturning be (m :: Type -> Type) | m -> be where Source #
MonadBeams that support returning data from rows that will be deleted by
the given DELETE statement. Useful for deallocating resources based on
the value of deleted rows.
Methods
runDeleteReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlDelete be table -> (table (QExpr be ()) -> a) -> m [QExprToIdentity a] Source #
Execute a DELETE statement and return a list of values projected from
the deleted rows. The projection function selects which columns are
returned: pass id to return the full row, or supply a custom
projection to return a subset.
Instances
runDeleteReturningList :: (MonadBeamDeleteReturning be m, Beamable table, Projectible be (table (QExpr be ())), FromBackendRow be (table Identity)) => SqlDelete be table -> m [table Identity] Source #
Execute a DELETE statement and return the deleted rows in full.
A convenience around runDeleteReturningListWith that uses id as the
projection.
class BeamSqlBackend be => BeamHasInsertOnConflict be where Source #
Associated Types
data SqlConflictTarget be (table :: (Type -> Type) -> Type) Source #
Specifies the kind of constraint that must be violated for the action to occur
data SqlConflictAction be (table :: (Type -> Type) -> Type) Source #
What to do when an INSERT statement inserts a row into the table tbl
that violates a constraint.
Methods
insertOnConflict :: forall table (db :: (Type -> Type) -> Type) s. Beamable table => DatabaseEntity be db (TableEntity table) -> SqlInsertValues be (table (QExpr be s)) -> SqlConflictTarget be table -> SqlConflictAction be table -> SqlInsert be table Source #
anyConflict :: forall (table :: (Type -> Type) -> Type). SqlConflictTarget be table Source #
conflictingFields :: Projectible be proj => (table (QExpr be QInternal) -> proj) -> SqlConflictTarget be table Source #
conflictingFieldsWhere :: Projectible be proj => (table (QExpr be QInternal) -> proj) -> (forall s. table (QExpr be s) -> QExpr be s Bool) -> SqlConflictTarget be table Source #
onConflictDoNothing :: forall (table :: (Type -> Type) -> Type). SqlConflictAction be table Source #
onConflictUpdateSet :: Beamable table => (forall s. table (QField s) -> table (QExpr be s) -> QAssignment be s) -> SqlConflictAction be table Source #
onConflictUpdateSetWhere :: Beamable table => (forall s. table (QField s) -> table (QExpr be s) -> QAssignment be s) -> (forall s. table (QField s) -> table (QExpr be s) -> QExpr be s Bool) -> SqlConflictAction be table Source #
Instances
onConflictUpdateInstead :: (BeamHasInsertOnConflict be, Beamable table, ProjectibleWithPredicate AnyType () (InaccessibleQAssignment be) proj) => (table (Const (InaccessibleQAssignment be) :: Type -> Type) -> proj) -> SqlConflictAction be table Source #
onConflictUpdateAll :: forall be (table :: (Type -> Type) -> Type). (BeamHasInsertOnConflict be, Beamable table) => SqlConflictAction be table Source #