Safe Haskell | None |
---|---|
Language | Haskell2010 |
Database.Beam
Contents
Description
Top-level Beam module. This module re-exports all the symbols necessary for most common user operations.
The most interesting modules are Database.Beam.Schema and Database.Beam.Query.
This is mainly reference documentation. Most users will want to consult the manual.
Synopsis
- module Database.Beam.Query
- module Database.Beam.Schema
- class (BeamBackend be, Monad m) => MonadBeam be (m :: Type -> Type) | m -> be where
- runReturningMany :: FromBackendRow be x => BeamSqlBackendSyntax be -> (m (Maybe x) -> m a) -> m a
- runNoReturn :: BeamSqlBackendSyntax be -> m ()
- runReturningOne :: FromBackendRow be x => BeamSqlBackendSyntax be -> m (Maybe x)
- runReturningFirst :: FromBackendRow be x => BeamSqlBackendSyntax be -> m (Maybe x)
- runReturningList :: FromBackendRow be x => BeamSqlBackendSyntax be -> m [x]
- class BeamBackend be => FromBackendRow be a where
- fromBackendRow :: FromBackendRowM be a
- valuesNeeded :: Proxy be -> Proxy a -> Int
- class Monad m => MonadIO (m :: Type -> Type) where
- class Typeable (a :: k)
- class Generic a
- data Identity a
Documentation
module Database.Beam.Query
module Database.Beam.Schema
class (BeamBackend be, Monad m) => MonadBeam be (m :: Type -> Type) | m -> be where Source #
A class that ties together a monad with a particular backend
Provided here is a low-level interface for executing commands. The 'run*'
functions are wrapped by the appropriate functions in Query
.
This interface is very high-level and isn't meant to expose the full power
of the underlying database. Namely, it only supports simple data retrieval
strategies. More complicated strategies (for example, Postgres's COPY
)
are supported in individual backends. See the documentation of those
backends for more details.
Minimal complete definition
Methods
Arguments
:: FromBackendRow be x | |
=> BeamSqlBackendSyntax be | The query to run |
-> (m (Maybe x) -> m a) | Reader action that will be called with a function to fetch the next row |
-> m a |
Run a query determined by the given syntax, providing an action that will
be called to consume the results from the database (if any). The action
will get a reader action that can be used to fetch the next row. When
this reader action returns Nothing
, there are no rows left to consume.
When the reader action returns, the database result is freed.
runNoReturn :: BeamSqlBackendSyntax be -> m () Source #
Run the given command and don't consume any results. Useful for DML statements like INSERT, UPDATE, and DELETE, or DDL statements.
runReturningOne :: FromBackendRow be x => BeamSqlBackendSyntax be -> m (Maybe x) Source #
Run the given command and fetch the unique result. The result is
Nothing
if either no results are returned or more than one result is
returned.
runReturningFirst :: FromBackendRow be x => BeamSqlBackendSyntax be -> m (Maybe x) Source #
Run the given command and fetch the first result. The result is
Nothing
if no results are returned.
This is not guaranteed to automatically limit the query to one result.
runReturningList :: FromBackendRow be x => BeamSqlBackendSyntax be -> m [x] Source #
Run the given command, collect all the results, and return them as a
list. May be more convenient than runReturningMany
, but reads the entire
result set into memory.
Instances
class BeamBackend be => FromBackendRow be a where Source #
Minimal complete definition
Nothing
Methods
fromBackendRow :: FromBackendRowM be a Source #
Parses a beam row. This should not fail, except in the case of
an internal bug in beam deserialization code. If it does fail,
this should throw a BeamRowParseError
.
default fromBackendRow :: (Typeable a, BackendFromField be a) => FromBackendRowM be a Source #
Instances
Re-exports
class Monad m => MonadIO (m :: Type -> Type) where #
Monads in which IO
computations may be embedded.
Any monad built by applying a sequence of monad transformers to the
IO
monad will be an instance of this class.
Instances should satisfy the following laws, which state that liftIO
is a transformer of monads:
Methods
Lift a computation from the IO
monad.
This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations
(i.e. IO
is the base monad for the stack).
Example
import Control.Monad.Trans.State -- from the "transformers" library printState :: Show s => StateT s IO () printState = do state <- get liftIO $ print state
Had we omitted
, we would have ended up with this error:liftIO
• Couldn't match type ‘IO’ with ‘StateT s IO’ Expected type: StateT s IO () Actual type: IO ()
The important part here is the mismatch between StateT s IO ()
and
.IO
()
Luckily, we know of a function that takes an
and returns an IO
a(m a)
:
,
enabling us to run the program and see the expected results:liftIO
> evalStateT printState "hello" "hello" > evalStateT printState 3 3
Instances
The class Typeable
allows a concrete representation of a type to
be calculated.
Minimal complete definition
typeRep#
Representable types of kind *
.
This class is derivable in GHC with the DeriveGeneric
flag on.
A Generic
instance must satisfy the following laws:
from
.to
≡id
to
.from
≡id
Instances
Identity functor and monad. (a non-strict monad)
Examples
>>>
fmap (+1) (Identity 0)
Identity 1
>>>
Identity [1, 2, 3] <> Identity [4, 5, 6]
Identity [1,2,3,4,5,6]
>>> do x <- Identity 10 y <- Identity (x + 5) pure (x + y) Identity 25
@since base-4.8.0.0
Instances
Representable Identity | |||||
FromJSON1 Identity | |||||
Defined in Data.Aeson.Types.FromJSON | |||||
ToJSON1 Identity | |||||
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Bool) -> (a -> Value) -> ([a] -> Value) -> Identity a -> Value # liftToJSONList :: (a -> Bool) -> (a -> Value) -> ([a] -> Value) -> [Identity a] -> Value # liftToEncoding :: (a -> Bool) -> (a -> Encoding) -> ([a] -> Encoding) -> Identity a -> Encoding # liftToEncodingList :: (a -> Bool) -> (a -> Encoding) -> ([a] -> Encoding) -> [Identity a] -> Encoding # liftOmitField :: (a -> Bool) -> Identity a -> Bool # | |||||
MonadZip Identity | Since: base-4.8.0.0 | ||||
Foldable1 Identity | Since: base-4.18.0.0 | ||||
Defined in Data.Foldable1 Methods fold1 :: Semigroup m => Identity m -> m # foldMap1 :: Semigroup m => (a -> m) -> Identity a -> m # foldMap1' :: Semigroup m => (a -> m) -> Identity a -> m # toNonEmpty :: Identity a -> NonEmpty a # maximum :: Ord a => Identity a -> a # minimum :: Ord a => Identity a -> a # foldrMap1 :: (a -> b) -> (a -> b -> b) -> Identity a -> b # foldlMap1' :: (a -> b) -> (b -> a -> b) -> Identity a -> b # foldlMap1 :: (a -> b) -> (b -> a -> b) -> Identity a -> b # foldrMap1' :: (a -> b) -> (a -> b -> b) -> Identity a -> b # | |||||
Eq1 Identity | Since: base-4.9.0.0 | ||||
Ord1 Identity | Since: base-4.9.0.0 | ||||
Defined in Data.Functor.Classes | |||||
Read1 Identity | Since: base-4.9.0.0 | ||||
Defined in Data.Functor.Classes | |||||
Show1 Identity | Since: base-4.9.0.0 | ||||
NFData1 Identity | Since: deepseq-1.4.3.0 | ||||
Defined in Control.DeepSeq | |||||
Applicative Identity | @since base-4.8.0.0 | ||||
Functor Identity | @since base-4.8.0.0 | ||||
Monad Identity | @since base-4.8.0.0 | ||||
MonadFix Identity | @since base-4.8.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Identity | |||||
Foldable Identity | @since base-4.8.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Identity Methods fold :: Monoid m => Identity m -> m # foldMap :: Monoid m => (a -> m) -> Identity a -> m # foldMap' :: Monoid m => (a -> m) -> Identity a -> m # foldr :: (a -> b -> b) -> b -> Identity a -> b # foldr' :: (a -> b -> b) -> b -> Identity a -> b # foldl :: (b -> a -> b) -> b -> Identity a -> b # foldl' :: (b -> a -> b) -> b -> Identity a -> b # foldr1 :: (a -> a -> a) -> Identity a -> a # foldl1 :: (a -> a -> a) -> Identity a -> a # elem :: Eq a => a -> Identity a -> Bool # maximum :: Ord a => Identity a -> a # minimum :: Ord a => Identity a -> a # | |||||
Traversable Identity | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Traversable | |||||
Hashable1 Identity | |||||
Defined in Data.Hashable.Class | |||||
Generic1 Identity | |||||
Defined in GHC.Internal.Data.Functor.Identity Associated Types
| |||||
FromBackendRow be a => FromBackendRow be (Identity a) Source # | |||||
Defined in Database.Beam.Backend.SQL.Row Methods fromBackendRow :: FromBackendRowM be (Identity a) Source # valuesNeeded :: Proxy be -> Proxy (Identity a) -> Int Source # | |||||
(BeamBackend be, Generic (tbl (Nullable Identity)), Generic (tbl (Nullable Exposed)), GFromBackendRow be (Rep (tbl (Nullable Exposed))) (Rep (tbl (Nullable Identity)))) => FromBackendRow be (tbl (Nullable Identity)) Source # | |||||
Defined in Database.Beam.Backend.SQL.Row Methods fromBackendRow :: FromBackendRowM be (tbl (Nullable Identity)) Source # valuesNeeded :: Proxy be -> Proxy (tbl (Nullable Identity)) -> Int Source # | |||||
(BeamBackend be, Generic (tbl Identity), Generic (tbl Exposed), GFromBackendRow be (Rep (tbl Exposed)) (Rep (tbl Identity))) => FromBackendRow be (tbl Identity) Source # | |||||
Defined in Database.Beam.Backend.SQL.Row Methods fromBackendRow :: FromBackendRowM be (tbl Identity) Source # valuesNeeded :: Proxy be -> Proxy (tbl Identity) -> Int Source # | |||||
Comonad w => ComonadCofree Identity (CoiterT w) | |||||
Monad m => MonadFree Identity (IterT m) | |||||
Unbox a => Vector Vector (Identity a) | |||||
Defined in Data.Vector.Unboxed.Base Methods basicUnsafeFreeze :: Mutable Vector s (Identity a) -> ST s (Vector (Identity a)) # basicUnsafeThaw :: Vector (Identity a) -> ST s (Mutable Vector s (Identity a)) # basicLength :: Vector (Identity a) -> Int # basicUnsafeSlice :: Int -> Int -> Vector (Identity a) -> Vector (Identity a) # basicUnsafeIndexM :: Vector (Identity a) -> Int -> Box (Identity a) # basicUnsafeCopy :: Mutable Vector s (Identity a) -> Vector (Identity a) -> ST s () # | |||||
Unbox a => MVector MVector (Identity a) | |||||
Defined in Data.Vector.Unboxed.Base Methods basicLength :: MVector s (Identity a) -> Int # basicUnsafeSlice :: Int -> Int -> MVector s (Identity a) -> MVector s (Identity a) # basicOverlaps :: MVector s (Identity a) -> MVector s (Identity a) -> Bool # basicUnsafeNew :: Int -> ST s (MVector s (Identity a)) # basicInitialize :: MVector s (Identity a) -> ST s () # basicUnsafeReplicate :: Int -> Identity a -> ST s (MVector s (Identity a)) # basicUnsafeRead :: MVector s (Identity a) -> Int -> ST s (Identity a) # basicUnsafeWrite :: MVector s (Identity a) -> Int -> Identity a -> ST s () # basicClear :: MVector s (Identity a) -> ST s () # basicSet :: MVector s (Identity a) -> Identity a -> ST s () # basicUnsafeCopy :: MVector s (Identity a) -> MVector s (Identity a) -> ST s () # basicUnsafeMove :: MVector s (Identity a) -> MVector s (Identity a) -> ST s () # basicUnsafeGrow :: MVector s (Identity a) -> Int -> ST s (MVector s (Identity a)) # | |||||
Monoid w => MonadAccum w (AccumT w Identity) | Since: mtl-2.3 | ||||
MonadSelect r (SelectT r Identity) | Since: mtl-2.3 | ||||
Defined in Control.Monad.Select | |||||
FromBackendRow be x => GFromBackendRow be (K1 R (Exposed x) :: Type -> Type) (K1 R (Identity x) :: Type -> Type) Source # | |||||
FromBackendRow be (t Identity) => GFromBackendRow be (K1 R (t Exposed) :: Type -> Type) (K1 R (t Identity) :: Type -> Type) Source # | |||||
FromBackendRow be (t (Nullable Identity)) => GFromBackendRow be (K1 R (t (Nullable Exposed)) :: Type -> Type) (K1 R (t (Nullable Identity)) :: Type -> Type) Source # | |||||
Defined in Database.Beam.Backend.SQL.Row | |||||
FromJSON a => FromJSON (Identity a) | |||||
Defined in Data.Aeson.Types.FromJSON | |||||
FromJSONKey a => FromJSONKey (Identity a) | |||||
Defined in Data.Aeson.Types.FromJSON Methods fromJSONKey :: FromJSONKeyFunction (Identity a) # | |||||
ToJSON a => ToJSON (Identity a) | |||||
ToJSONKey a => ToJSONKey (Identity a) | |||||
Defined in Data.Aeson.Types.ToJSON Methods toJSONKey :: ToJSONKeyFunction (Identity a) # toJSONKeyList :: ToJSONKeyFunction [Identity a] # | |||||
NFData a => NFData (Identity a) | Since: deepseq-1.4.0.0 | ||||
Defined in Control.DeepSeq | |||||
Monoid a => Monoid (Identity a) | @since base-4.9.0.0 | ||||
Semigroup a => Semigroup (Identity a) | @since base-4.9.0.0 | ||||
Bits a => Bits (Identity a) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Identity Methods (.&.) :: Identity a -> Identity a -> Identity a # (.|.) :: Identity a -> Identity a -> Identity a # xor :: Identity a -> Identity a -> Identity a # complement :: Identity a -> Identity a # shift :: Identity a -> Int -> Identity a # rotate :: Identity a -> Int -> Identity a # setBit :: Identity a -> Int -> Identity a # clearBit :: Identity a -> Int -> Identity a # complementBit :: Identity a -> Int -> Identity a # testBit :: Identity a -> Int -> Bool # bitSizeMaybe :: Identity a -> Maybe Int # bitSize :: Identity a -> Int # isSigned :: Identity a -> Bool # shiftL :: Identity a -> Int -> Identity a # unsafeShiftL :: Identity a -> Int -> Identity a # shiftR :: Identity a -> Int -> Identity a # unsafeShiftR :: Identity a -> Int -> Identity a # rotateL :: Identity a -> Int -> Identity a # | |||||
FiniteBits a => FiniteBits (Identity a) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Identity Methods finiteBitSize :: Identity a -> Int # countLeadingZeros :: Identity a -> Int # countTrailingZeros :: Identity a -> Int # | |||||
IsString a => IsString (Identity a) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.String Methods fromString :: String -> Identity a # | |||||
Bounded a => Bounded (Identity a) | @since base-4.9.0.0 | ||||
Enum a => Enum (Identity a) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Identity Methods succ :: Identity a -> Identity a # pred :: Identity a -> Identity a # fromEnum :: Identity a -> Int # enumFrom :: Identity a -> [Identity a] # enumFromThen :: Identity a -> Identity a -> [Identity a] # enumFromTo :: Identity a -> Identity a -> [Identity a] # enumFromThenTo :: Identity a -> Identity a -> Identity a -> [Identity a] # | |||||
Floating a => Floating (Identity a) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Identity Methods exp :: Identity a -> Identity a # log :: Identity a -> Identity a # sqrt :: Identity a -> Identity a # (**) :: Identity a -> Identity a -> Identity a # logBase :: Identity a -> Identity a -> Identity a # sin :: Identity a -> Identity a # cos :: Identity a -> Identity a # tan :: Identity a -> Identity a # asin :: Identity a -> Identity a # acos :: Identity a -> Identity a # atan :: Identity a -> Identity a # sinh :: Identity a -> Identity a # cosh :: Identity a -> Identity a # tanh :: Identity a -> Identity a # asinh :: Identity a -> Identity a # acosh :: Identity a -> Identity a # atanh :: Identity a -> Identity a # log1p :: Identity a -> Identity a # expm1 :: Identity a -> Identity a # | |||||
RealFloat a => RealFloat (Identity a) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Identity Methods floatRadix :: Identity a -> Integer # floatDigits :: Identity a -> Int # floatRange :: Identity a -> (Int, Int) # decodeFloat :: Identity a -> (Integer, Int) # encodeFloat :: Integer -> Int -> Identity a # exponent :: Identity a -> Int # significand :: Identity a -> Identity a # scaleFloat :: Int -> Identity a -> Identity a # isInfinite :: Identity a -> Bool # isDenormalized :: Identity a -> Bool # isNegativeZero :: Identity a -> Bool # | |||||
Storable a => Storable (Identity a) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Identity Methods alignment :: Identity a -> Int # peekElemOff :: Ptr (Identity a) -> Int -> IO (Identity a) # pokeElemOff :: Ptr (Identity a) -> Int -> Identity a -> IO () # peekByteOff :: Ptr b -> Int -> IO (Identity a) # pokeByteOff :: Ptr b -> Int -> Identity a -> IO () # | |||||
Generic (Identity a) | |||||
Defined in GHC.Internal.Data.Functor.Identity Associated Types
| |||||
Ix a => Ix (Identity a) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Identity Methods range :: (Identity a, Identity a) -> [Identity a] # index :: (Identity a, Identity a) -> Identity a -> Int # unsafeIndex :: (Identity a, Identity a) -> Identity a -> Int # inRange :: (Identity a, Identity a) -> Identity a -> Bool # rangeSize :: (Identity a, Identity a) -> Int # unsafeRangeSize :: (Identity a, Identity a) -> Int # | |||||
Num a => Num (Identity a) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Identity | |||||
Read a => Read (Identity a) | This instance would be equivalent to the derived instances of the
@since base-4.8.0.0 | ||||
Fractional a => Fractional (Identity a) | @since base-4.9.0.0 | ||||
Integral a => Integral (Identity a) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Identity Methods quot :: Identity a -> Identity a -> Identity a # rem :: Identity a -> Identity a -> Identity a # div :: Identity a -> Identity a -> Identity a # mod :: Identity a -> Identity a -> Identity a # quotRem :: Identity a -> Identity a -> (Identity a, Identity a) # divMod :: Identity a -> Identity a -> (Identity a, Identity a) # | |||||
Real a => Real (Identity a) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Identity Methods toRational :: Identity a -> Rational # | |||||
RealFrac a => RealFrac (Identity a) | @since base-4.9.0.0 | ||||
Show a => Show (Identity a) | This instance would be equivalent to the derived instances of the
@since base-4.8.0.0 | ||||
Eq a => Eq (Identity a) | @since base-4.8.0.0 | ||||
Ord a => Ord (Identity a) | @since base-4.8.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Identity | |||||
Hashable a => Hashable (Identity a) | |||||
Defined in Data.Hashable.Class | |||||
Unbox a => Unbox (Identity a) | |||||
Defined in Data.Vector.Unboxed.Base | |||||
Table t => SqlJustable (t Identity) (t (Nullable Identity)) Source # | |||||
Table t => SqlJustable (PrimaryKey t Identity) (PrimaryKey t (Nullable Identity)) Source # | |||||
Defined in Database.Beam.Query.Combinators Methods just_ :: PrimaryKey t Identity -> PrimaryKey t (Nullable Identity) Source # | |||||
type Rep Identity | |||||
Defined in Data.Functor.Rep | |||||
type Rep1 Identity | @since base-4.8.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Identity | |||||
newtype MVector s (Identity a) | |||||
Defined in Data.Vector.Unboxed.Base | |||||
type Rep (Identity a) | @since base-4.8.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Identity | |||||
newtype Vector (Identity a) | |||||
Defined in Data.Vector.Unboxed.Base |