beam-core-0.11.0.0: Type-safe, feature-complete SQL query and manipulation interface for Haskell
Safe HaskellNone
LanguageHaskell2010

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

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

Instances details
MonadBeamInsertReturning be m => MonadBeamInsertReturning be (ExceptT e m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runInsertReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlInsert be table -> (table (QExpr be ()) -> a) -> ExceptT e m [QExprToIdentity a] Source #

MonadBeamInsertReturning be m => MonadBeamInsertReturning be (ReaderT r m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runInsertReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlInsert be table -> (table (QExpr be ()) -> a) -> ReaderT r m [QExprToIdentity a] Source #

MonadBeamInsertReturning be m => MonadBeamInsertReturning be (StateT r m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runInsertReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlInsert be table -> (table (QExpr be ()) -> a) -> StateT r m [QExprToIdentity a] Source #

MonadBeamInsertReturning be m => MonadBeamInsertReturning be (StateT r m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runInsertReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlInsert be table -> (table (QExpr be ()) -> a) -> StateT r m [QExprToIdentity a] Source #

(MonadBeamInsertReturning be m, Monoid r) => MonadBeamInsertReturning be (WriterT r m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runInsertReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlInsert be table -> (table (QExpr be ()) -> a) -> WriterT r m [QExprToIdentity a] Source #

(MonadBeamInsertReturning be m, Monoid r) => MonadBeamInsertReturning be (WriterT r m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runInsertReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlInsert be table -> (table (QExpr be ()) -> a) -> WriterT r m [QExprToIdentity a] Source #

MonadBeamInsertReturning be m => MonadBeamInsertReturning be (ContT r m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runInsertReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlInsert be table -> (table (QExpr be ()) -> a) -> ContT r m [QExprToIdentity a] Source #

(MonadBeamInsertReturning be m, Monoid w) => MonadBeamInsertReturning be (RWST r w s m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runInsertReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlInsert be table -> (table (QExpr be ()) -> a) -> RWST r w s m [QExprToIdentity a] Source #

(MonadBeamInsertReturning be m, Monoid w) => MonadBeamInsertReturning be (RWST r w s m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runInsertReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlInsert be table -> (table (QExpr be ()) -> a) -> RWST r w s m [QExprToIdentity a] Source #

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

Instances details
MonadBeamUpdateReturning be m => MonadBeamUpdateReturning be (ExceptT e m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runUpdateReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlUpdate be table -> (table (QExpr be ()) -> a) -> ExceptT e m [QExprToIdentity a] Source #

MonadBeamUpdateReturning be m => MonadBeamUpdateReturning be (ReaderT r m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runUpdateReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlUpdate be table -> (table (QExpr be ()) -> a) -> ReaderT r m [QExprToIdentity a] Source #

MonadBeamUpdateReturning be m => MonadBeamUpdateReturning be (StateT r m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runUpdateReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlUpdate be table -> (table (QExpr be ()) -> a) -> StateT r m [QExprToIdentity a] Source #

MonadBeamUpdateReturning be m => MonadBeamUpdateReturning be (StateT r m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runUpdateReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlUpdate be table -> (table (QExpr be ()) -> a) -> StateT r m [QExprToIdentity a] Source #

(MonadBeamUpdateReturning be m, Monoid r) => MonadBeamUpdateReturning be (WriterT r m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runUpdateReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlUpdate be table -> (table (QExpr be ()) -> a) -> WriterT r m [QExprToIdentity a] Source #

(MonadBeamUpdateReturning be m, Monoid r) => MonadBeamUpdateReturning be (WriterT r m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runUpdateReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlUpdate be table -> (table (QExpr be ()) -> a) -> WriterT r m [QExprToIdentity a] Source #

MonadBeamUpdateReturning be m => MonadBeamUpdateReturning be (ContT r m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runUpdateReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlUpdate be table -> (table (QExpr be ()) -> a) -> ContT r m [QExprToIdentity a] Source #

(MonadBeamUpdateReturning be m, Monoid w) => MonadBeamUpdateReturning be (RWST r w s m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runUpdateReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlUpdate be table -> (table (QExpr be ()) -> a) -> RWST r w s m [QExprToIdentity a] Source #

(MonadBeamUpdateReturning be m, Monoid w) => MonadBeamUpdateReturning be (RWST r w s m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runUpdateReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlUpdate be table -> (table (QExpr be ()) -> a) -> RWST r w s m [QExprToIdentity a] Source #

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

Instances details
MonadBeamDeleteReturning be m => MonadBeamDeleteReturning be (ExceptT e m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runDeleteReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlDelete be table -> (table (QExpr be ()) -> a) -> ExceptT e m [QExprToIdentity a] Source #

MonadBeamDeleteReturning be m => MonadBeamDeleteReturning be (ReaderT r m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runDeleteReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlDelete be table -> (table (QExpr be ()) -> a) -> ReaderT r m [QExprToIdentity a] Source #

MonadBeamDeleteReturning be m => MonadBeamDeleteReturning be (StateT r m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runDeleteReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlDelete be table -> (table (QExpr be ()) -> a) -> StateT r m [QExprToIdentity a] Source #

MonadBeamDeleteReturning be m => MonadBeamDeleteReturning be (StateT r m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runDeleteReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlDelete be table -> (table (QExpr be ()) -> a) -> StateT r m [QExprToIdentity a] Source #

(MonadBeamDeleteReturning be m, Monoid r) => MonadBeamDeleteReturning be (WriterT r m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runDeleteReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlDelete be table -> (table (QExpr be ()) -> a) -> WriterT r m [QExprToIdentity a] Source #

(MonadBeamDeleteReturning be m, Monoid r) => MonadBeamDeleteReturning be (WriterT r m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runDeleteReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlDelete be table -> (table (QExpr be ()) -> a) -> WriterT r m [QExprToIdentity a] Source #

MonadBeamDeleteReturning be m => MonadBeamDeleteReturning be (ContT r m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runDeleteReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlDelete be table -> (table (QExpr be ()) -> a) -> ContT r m [QExprToIdentity a] Source #

(MonadBeamDeleteReturning be m, Monoid w) => MonadBeamDeleteReturning be (RWST r w s m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runDeleteReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlDelete be table -> (table (QExpr be ()) -> a) -> RWST r w s m [QExprToIdentity a] Source #

(MonadBeamDeleteReturning be m, Monoid w) => MonadBeamDeleteReturning be (RWST r w s m) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.BeamExtensions

Methods

runDeleteReturningListWith :: (Beamable table, Projectible be a, FromBackendRow be (QExprToIdentity a)) => SqlDelete be table -> (table (QExpr be ()) -> a) -> RWST r w s m [QExprToIdentity a] Source #

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 #

newtype SqlSerial a Source #

Constructors

SqlSerial 

Fields

Instances

Instances details
FromBackendRow be x => FromBackendRow be (SqlSerial x) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.Row

HasSqlValueSyntax syntax x => HasSqlValueSyntax syntax (SqlSerial x) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.SQL92

Methods

sqlValueSyntax :: SqlSerial x -> syntax Source #

HasSqlEqualityCheck be a => HasSqlEqualityCheck be (SqlSerial a) Source # 
Instance details

Defined in Database.Beam.Query.Ord

HasSqlQuantifiedEqualityCheck syntax a => HasSqlQuantifiedEqualityCheck syntax (SqlSerial a) Source # 
Instance details

Defined in Database.Beam.Query.Ord

FromJSON a => FromJSON (SqlSerial a) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.Types

ToJSON a => ToJSON (SqlSerial a) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.Types

Enum a => Enum (SqlSerial a) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.Types

Generic (SqlSerial a) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.Types

Associated Types

type Rep (SqlSerial a) 
Instance details

Defined in Database.Beam.Backend.SQL.Types

type Rep (SqlSerial a) = D1 ('MetaData "SqlSerial" "Database.Beam.Backend.SQL.Types" "beam-core-0.11.0.0-F7C6wbiPTQ59cykGpQipAT" 'True) (C1 ('MetaCons "SqlSerial" 'PrefixI 'True) (S1 ('MetaSel ('Just "unSerial") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))

Methods

from :: SqlSerial a -> Rep (SqlSerial a) x #

to :: Rep (SqlSerial a) x -> SqlSerial a #

Num a => Num (SqlSerial a) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.Types

Read a => Read (SqlSerial a) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.Types

Integral a => Integral (SqlSerial a) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.Types

Real a => Real (SqlSerial a) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.Types

Show a => Show (SqlSerial a) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.Types

Eq a => Eq (SqlSerial a) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.Types

Methods

(==) :: SqlSerial a -> SqlSerial a -> Bool #

(/=) :: SqlSerial a -> SqlSerial a -> Bool #

Ord a => Ord (SqlSerial a) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.Types

type Rep (SqlSerial a) Source # 
Instance details

Defined in Database.Beam.Backend.SQL.Types

type Rep (SqlSerial a) = D1 ('MetaData "SqlSerial" "Database.Beam.Backend.SQL.Types" "beam-core-0.11.0.0-F7C6wbiPTQ59cykGpQipAT" 'True) (C1 ('MetaCons "SqlSerial" 'PrefixI 'True) (S1 ('MetaSel ('Just "unSerial") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))

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 #