HORIZON HASKELLDocslts/ghc-10.0.x8c2f8e82026-10-19Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8c2f8e8 · 2026-10-19

Modulebeam-core-0.11.1.0Haskell2010

Database.Beam.Backend.SQL.BeamExtensions

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.

  • 5 types
  • 14 classes
  • 11 values
classclass MonadBeam be m => MonadBeamInsertReturning be (m :: Type -> Type) | m -> be where
#

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

Instances9MonadBeamInsertReturning, …
classclass MonadBeam be m => MonadBeamUpdateReturning be (m :: Type -> Type) | m -> be where
#

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

Instances9MonadBeamUpdateReturning, …
classclass MonadBeam be m => MonadBeamDeleteReturning be (m :: Type -> Type) | m -> be where
#

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

Instances9MonadBeamDeleteReturning, …
classclass BeamSqlBackend be => BeamHasInsertOnConflict be where
#

Associated types

  • data family SqlConflictTarget be (table :: (Type -> Type) -> Type)

    Specifies the kind of constraint that must be violated for the action to occur

  • data family SqlConflictAction be (table :: (Type -> Type) -> Type)

    What to do when an INSERT statement inserts a row into the table tbl that violates a constraint.

Methods

Support for copying to external files

18 declarations

Express the copy from the result of a SELECT statement to a destination (typically a file). Use this when the source rows are produced by a query rather than read directly from a table.

To copy a table, or a subset of columns, see copyTableTo.

valuecopyTableTo
  1. :: (IsSqlCopyToSyntax (BeamSqlBackendCopyToSyntax be), ProjectibleWithPredicate AnyType () Text proj)
  2. => DatabaseEntity be db (TableEntity table)
  3. -> (table (QField s) -> proj)

    Projection from table to columns. If you want to copy the entire table, use id.

  4. -> SqlCopyToParams (BeamSqlBackendCopyToSyntax be)

    Backend-specific options. The output is also determined by this value

  5. -> SqlCopyTo be proj
#

Express the copy from a table, to a destination (typically a file).

To copy the result of a SELECT query instead, see copySelectTo.

Statement-level syntax for backends that support file-mode COPY ... FROM file.

Symmetric to IsSqlCopyToSyntax, but the data flows in the opposite direction: the params value supplies the source path and any format-specific options.

Associated types

  • type family SqlCopyFromSourceSyntax cmd

    The syntax for the destination table of the copy.

  • type family SqlCopyFromParams cmd

    All backend-specific options which determine HOW the copy is performed, including the source of the data (e.g. a filepath).

Methods

classclass IsSqlCopyToSourceSyntax syntax where
#

This class allows to express the source of a `COPY ... TO` statement. The options are either from a table (with a possible projection), or from the result of a select query.

Reused by both file-mode and streaming COPY: the source shape (a table or a SELECT) is the same regardless of where the data ends up.

Associated types

Statement-level syntax for backends that support COPY ... TO file.

Associated types

  • type family SqlCopyToSourceSyntax cmd

    The syntax for the source of the copy. For example, in Postgres, this can be either a table (and optional projection), or a select statement.

  • type family SqlCopyToParams cmd

    All backend-specific options which determine HOW the copy is performed, including the destination of the data (e.g. a filepath).

Methods

classclass MonadBeam be m => MonadBeamCopyFrom be (m :: Type -> Type) | m -> be where
#

MonadBeams that support copying data into database, from other location.

See MonadBeamCopyTo for the inverse operation.

Methods

Instances9MonadBeamCopyFrom, …
classclass MonadBeam be m => MonadBeamCopyTo be (m :: Type -> Type) | m -> be where
#

MonadBeams that support copying data out of a database, to some other location.

See MonadBeamCopyFrom for the inverse operation.

Methods

Instances9MonadBeamCopyTo, …
familytype family SqlCopyFromParams cmd
#

All backend-specific options which determine HOW the copy is performed, including the source of the data (e.g. a filepath).

familytype family SqlCopyToParams cmd
#

All backend-specific options which determine HOW the copy is performed, including the destination of the data (e.g. a filepath).

familytype family SqlCopyToSourceSyntax cmd
#

The syntax for the source of the copy. For example, in Postgres, this can be either a table (and optional projection), or a select statement.

Support for streaming copy

18 declarations
valuecopyTableFromStream
  1. :: (IsSqlCopyFromStreamSyntax (BeamSqlBackendCopyFromStreamSyntax be), ProjectibleWithPredicate AnyType () Text proj)
  2. => DatabaseEntity be db (TableEntity table)
  3. -> (table (QField s) -> proj)

    Projection from which to copy columns. Other columns will have their default value inserted.

    To copy the stream into the entire table, use id.

  4. -> SqlCopyFromStreamParams (BeamSqlBackendCopyFromStreamSyntax be)
  5. -> SqlCopyFromStream be proj
#

Express a streaming copy into a table, the data flowing through the client connection rather than from a server-side file.

valuecopyTableToStream
  1. :: (IsSqlCopyToStreamSyntax (BeamSqlBackendCopyToStreamSyntax be), ProjectibleWithPredicate AnyType () Text proj)
  2. => DatabaseEntity be db (TableEntity table)
  3. -> (table (QField s) -> proj)

    Projection from table to columns. If you want to copy the entire table, use id.

  4. -> SqlCopyToStreamParams (BeamSqlBackendCopyToStreamSyntax be)

    Backend-specific options.

  5. -> SqlCopyToStream be proj
#

Express a streaming copy from a table, the data flowing through the client connection rather than to a server-side file.

To stream the result of a SELECT query instead, see copySelectToStream.

Statement-level syntax for backends that support streaming COPY ... FROM (data entering the database through the client connection).

Mirrors IsSqlCopyFromSyntax.

Associated types

  • type family SqlCopyFromStreamSourceSyntax cmd

    The syntax for the destination table of the streaming copy.

  • type family SqlCopyFromStreamParams cmd

    All backend-specific options which determine HOW the streaming copy is performed. Unlike the file-mode params, there is no source path — chunks flow through the connection.

Methods

Statement-level syntax for backends that support streaming COPY ... TO (data leaving the database through the client connection).

Mirrors IsSqlCopyToSyntax, but the params value carries only format options — no destination path, since chunks travel through the wire.

Associated types

  • type family SqlCopyToStreamSourceSyntax cmd

    The syntax for the source of the streaming copy. As with file-mode COPY, this can be a table (perhaps with a projection) or a SELECT query.

  • type family SqlCopyToStreamParams cmd

    All backend-specific options which determine HOW the streaming copy is performed (format, delimiter, etc.). Unlike the file-mode params, there is no destination — chunks flow through the connection.

Methods

classclass MonadBeam be m => MonadBeamCopyFromStream be (m :: Type -> Type) | m -> be where
#

MonadBeams that support streaming data into a database through the client connection (e.g. PostgreSQL's COPY ... FROM STDIN).

The supplied IO (Maybe ByteString) source is pulled repeatedly until it returns Nothing, signalling end of data. runCopyFromStream blocks until the COPY commits; on failure it raises the underlying backend's exception.

See MonadBeamCopyToStream for the inverse operation.

Methods

Instances9MonadBeamCopyFromStream, …
classclass MonadBeam be m => MonadBeamCopyToStream be (m :: Type -> Type) | m -> be where
#

MonadBeams that support streaming data out of a database through the client connection (e.g. PostgreSQL's COPY ... TO STDOUT).

The supplied ByteString -> IO () callback is invoked once per chunk received. The runCopyToStream call blocks until the COPY completes; on failure it raises the underlying backend's exception.

See MonadBeamCopyFromStream for the inverse operation.

Methods

Instances9MonadBeamCopyToStream, …
familytype family SqlCopyFromStreamParams cmd
#

All backend-specific options which determine HOW the streaming copy is performed. Unlike the file-mode params, there is no source path — chunks flow through the connection.

familytype family SqlCopyToStreamParams cmd
#

All backend-specific options which determine HOW the streaming copy is performed (format, delimiter, etc.). Unlike the file-mode params, there is no destination — chunks flow through the connection.

familytype family SqlCopyToStreamSourceSyntax cmd
#

The syntax for the source of the streaming copy. As with file-mode COPY, this can be a table (perhaps with a projection) or a SELECT query.

newtypenewtype SqlSerial a
#

Constructors

Instances16FromBackendRow, HasSqlEqualityCheck, HasSqlQuantifiedEqualityCheck, HasSqlValueSyntax, Enum, Eq, …