esqueleto-3.5.10.3: Type-safe EDSL for SQL queries on persistent backends.

Safe Haskell | Safe-Inferred
Language | Haskell2010

Database.Esqueleto.Experimental

Contents

- Setup
- Introduction
- A New Syntax
- Documentation
  - Basic Queries
  - Joins
  - Set Operations
  - Common Table Expressions
  - Internals
- The Normal Stuff
  - Joins
    - Join Helpers
  - SQL backend
  - Rendering Queries
  - Helpers
  - Re-exports

Description

This module contains a new way (introduced in 3.3.3.0) of using `FROM` in Haskell. The old method was a bit finicky and could permit runtime errors, and this new way is both significantly safer and much more powerful.

This syntax will become the default syntax exported from the library in version `3.6.0.0`. To use the old syntax, see Database.Esqueleto.Legacy.

Synopsis

- from :: ToFrom a a' => a -> SqlQuery a'
- table :: forall ent. PersistEntity ent => From (SqlExpr (Entity ent))
- data Table a = Table
- newtype SubQuery a = SubQuery a
- selectQuery :: (SqlSelect a r, ToAlias a, ToAliasReference a) => SqlQuery a -> From a
- data a :& b = a :& b
- on :: ValidOnClause a => a -> (b -> SqlExpr (Value Bool)) -> (a, b -> SqlExpr (Value Bool))
- innerJoin :: (ToFrom a a', ToFrom b b', HasOnClause rhs (a' :& b'), rhs ~ (b, (a' :& b') -> SqlExpr (Value Bool))) => a -> rhs -> From (a' :& b')
- innerJoinLateral :: (ToFrom a a', HasOnClause rhs (a' :& b), SqlSelect b r, ToAlias b, ToAliasReference b, rhs ~ (a' -> SqlQuery b, (a' :& b) -> SqlExpr (Value Bool))) => a -> rhs -> From (a' :& b)
- leftJoin :: (ToFrom a a', ToFrom b b', ToMaybe b', HasOnClause rhs (a' :& ToMaybeT b'), rhs ~ (b, (a' :& ToMaybeT b') -> SqlExpr (Value Bool))) => a -> rhs -> From (a' :& ToMaybeT b')
- leftJoinLateral :: (ToFrom a a', SqlSelect b r, HasOnClause rhs (a' :& ToMaybeT b), ToAlias b, ToAliasReference b, ToMaybe b, rhs ~ (a' -> SqlQuery b, (a' :& ToMaybeT b) -> SqlExpr (Value Bool))) => a -> rhs -> From (a' :& ToMaybeT b)
- rightJoin :: (ToFrom a a', ToFrom b b', ToMaybe a', HasOnClause rhs (ToMaybeT a' :& b'), rhs ~ (b, (ToMaybeT a' :& b') -> SqlExpr (Value Bool))) => a -> rhs -> From (ToMaybeT a' :& b')
- fullOuterJoin :: (ToFrom a a', ToFrom b b', ToMaybe a', ToMaybe b', HasOnClause rhs (ToMaybeT a' :& ToMaybeT b'), rhs ~ (b, (ToMaybeT a' :& ToMaybeT b') -> SqlExpr (Value Bool))) => a -> rhs -> From (ToMaybeT a' :& ToMaybeT b')
- crossJoin :: (ToFrom a a', ToFrom b b') => a -> b -> From (a' :& b')
- crossJoinLateral :: (ToFrom a a', SqlSelect b r, ToAlias b, ToAliasReference b) => a -> (a' -> SqlQuery b) -> From (a' :& b)
- union_ :: Union_ a => a
- data Union a b = a `Union` b
- unionAll_ :: UnionAll_ a => a
- data UnionAll a b = a `UnionAll` b
- except_ :: (ToSqlSetOperation a a', ToSqlSetOperation b a') => a -> b -> SqlSetOperation a'
- data Except a b = a `Except` b
- intersect_ :: (ToSqlSetOperation a a', ToSqlSetOperation b a') => a -> b -> SqlSetOperation a'
- data Intersect a b = a `Intersect` b
- pattern SelectQuery :: p -> p
- with :: (ToAlias a, ToAliasReference a, SqlSelect a r) => SqlQuery a -> SqlQuery (From a)
- withRecursive :: (ToAlias a, ToAliasReference a, SqlSelect a r) => SqlQuery a -> UnionKind -> (From a -> SqlQuery a) -> SqlQuery (From a)
- newtype From a = From {
  - unFrom :: SqlQuery (a, RawFn)
  }
- class ToMaybe a where
  - type ToMaybeT a
  - toMaybe :: a -> ToMaybeT a
- class ToAlias a where
  - toAlias :: a -> SqlQuery a
- type ToAliasT a = a
- class ToAliasReference a where
  - toAliasReference :: Ident -> a -> SqlQuery a
- type ToAliasReferenceT a = a
- class ToSqlSetOperation a r | a -> r where
  - toSqlSetOperation :: a -> SqlSetOperation r
- where_ :: SqlExpr (Value Bool) -> SqlQuery ()
- groupBy :: ToSomeValues a => a -> SqlQuery ()
- groupBy_ :: ToSomeValues a => a -> SqlQuery ()
- orderBy :: [SqlExpr OrderBy] -> SqlQuery ()
- rand :: SqlExpr OrderBy
- asc :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy
- desc :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy
- limit :: Int64 -> SqlQuery ()
- offset :: Int64 -> SqlQuery ()
- distinct :: SqlQuery a -> SqlQuery a
- distinctOn :: [SqlExpr DistinctOn] -> SqlQuery a -> SqlQuery a
- don :: SqlExpr (Value a) -> SqlExpr DistinctOn
- distinctOnOrderBy :: [SqlExpr OrderBy] -> SqlQuery a -> SqlQuery a
- having :: SqlExpr (Value Bool) -> SqlQuery ()
- locking :: LockingKind -> SqlQuery ()
- sub_select :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
- (^.) :: forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ)
- (?.) :: (PersistEntity val, PersistField typ) => SqlExpr (Maybe (Entity val)) -> EntityField val typ -> SqlExpr (Value (Maybe typ))
- val :: PersistField typ => typ -> SqlExpr (Value typ)
- isNothing :: PersistField typ => SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool)
- isNothing_ :: PersistField typ => SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool)
- just :: SqlExpr (Value typ) -> SqlExpr (Value (Maybe typ))
- nothing :: SqlExpr (Value (Maybe typ))
- joinV :: SqlExpr (Value (Maybe (Maybe typ))) -> SqlExpr (Value (Maybe typ))
- withNonNull :: PersistField typ => SqlExpr (Value (Maybe typ)) -> (SqlExpr (Value typ) -> SqlQuery a) -> SqlQuery a
- countRows :: Num a => SqlExpr (Value a)
- count :: Num a => SqlExpr (Value typ) -> SqlExpr (Value a)
- countDistinct :: Num a => SqlExpr (Value typ) -> SqlExpr (Value a)
- not_ :: SqlExpr (Value Bool) -> SqlExpr (Value Bool)
- (==.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
- (>=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
- (>.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
- (<=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
- (<.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
- (!=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
- (&&.) :: SqlExpr (Value Bool) -> SqlExpr (Value Bool) -> SqlExpr (Value Bool)
- (||.) :: SqlExpr (Value Bool) -> SqlExpr (Value Bool) -> SqlExpr (Value Bool)
- between :: PersistField a => SqlExpr (Value a) -> (SqlExpr (Value a), SqlExpr (Value a)) -> SqlExpr (Value Bool)
- (+.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
- (-.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
- (/.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
- (*.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
- random_ :: (PersistField a, Num a) => SqlExpr (Value a)
- round_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
- ceiling_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
- floor_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
- min_ :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value (Maybe a))
- max_ :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value (Maybe a))
- sum_ :: (PersistField a, PersistField b) => SqlExpr (Value a) -> SqlExpr (Value (Maybe b))
- avg_ :: (PersistField a, PersistField b) => SqlExpr (Value a) -> SqlExpr (Value (Maybe b))
- castNum :: (Num a, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
- castNumM :: (Num a, Num b) => SqlExpr (Value (Maybe a)) -> SqlExpr (Value (Maybe b))
- coalesce :: PersistField a => [SqlExpr (Value (Maybe a))] -> SqlExpr (Value (Maybe a))
- coalesceDefault :: PersistField a => [SqlExpr (Value (Maybe a))] -> SqlExpr (Value a) -> SqlExpr (Value a)
- lower_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
- upper_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
- trim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
- ltrim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
- rtrim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
- length_ :: (SqlString s, Num a) => SqlExpr (Value s) -> SqlExpr (Value a)
- left_ :: (SqlString s, Num a) => (SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s)
- right_ :: (SqlString s, Num a) => (SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s)
- like :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool)
- ilike :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool)
- (%) :: SqlString s => SqlExpr (Value s)
- concat_ :: SqlString s => [SqlExpr (Value s)] -> SqlExpr (Value s)
- (++.) :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value s)
- castString :: (SqlString s, SqlString r) => SqlExpr (Value s) -> SqlExpr (Value r)
- subList_select :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (ValueList a)
- valList :: PersistField typ => [typ] -> SqlExpr (ValueList typ)
- justList :: SqlExpr (ValueList typ) -> SqlExpr (ValueList (Maybe typ))
- in_ :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (ValueList typ) -> SqlExpr (Value Bool)
- notIn :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (ValueList typ) -> SqlExpr (Value Bool)
- exists :: SqlQuery () -> SqlExpr (Value Bool)
- notExists :: SqlQuery () -> SqlExpr (Value Bool)
- set :: PersistEntity val => SqlExpr (Entity val) -> [SqlExpr (Entity val) -> SqlExpr Update] -> SqlQuery ()
- (=.) :: (PersistEntity val, PersistField typ) => EntityField val typ -> SqlExpr (Value typ) -> SqlExpr (Entity val) -> SqlExpr Update
- (+=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Entity val) -> SqlExpr Update
- (-=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Entity val) -> SqlExpr Update
- (*=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Entity val) -> SqlExpr Update
- (/=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Entity val) -> SqlExpr Update
- case_ :: PersistField a => [(SqlExpr (Value Bool), SqlExpr (Value a))] -> SqlExpr (Value a) -> SqlExpr (Value a)
- toBaseId :: ToBaseId ent => SqlExpr (Value (Key ent)) -> SqlExpr (Value (Key (BaseEnt ent)))
- subSelect :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value (Maybe a))
- subSelectMaybe :: PersistField a => SqlQuery (SqlExpr (Value (Maybe a))) -> SqlExpr (Value (Maybe a))
- subSelectCount :: (Num a, PersistField a) => SqlQuery ignored -> SqlExpr (Value a)
- subSelectForeign :: (BackendCompatible SqlBackend (PersistEntityBackend val1), PersistEntity val1, PersistEntity val2, PersistField a) => SqlExpr (Entity val2) -> EntityField val2 (Key val1) -> (SqlExpr (Entity val1) -> SqlExpr (Value a)) -> SqlExpr (Value a)
- subSelectList :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (ValueList a)
- subSelectUnsafe :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
- class ToBaseId ent where
  - type BaseEnt ent :: Type
  - toBaseIdWitness :: Key (BaseEnt ent) -> Key ent
- when_ :: expr (Value Bool) -> () -> expr a -> (expr (Value Bool), expr a)
- then_ :: ()
- else_ :: expr a -> expr a
- newtype Value a = Value {
  - unValue :: a
  }
- newtype ValueList a = ValueList a
- data OrderBy
- data DistinctOn
- data LockingKind
  - = ForUpdate
  - | ForUpdateSkipLocked
  - | ForShare
  - | LockInShareMode
- class LockableEntity a where
  - flattenLockableEntity :: a -> NonEmpty LockableSqlExpr
- class PersistField a => SqlString a
- data InnerJoin a b = a `InnerJoin` b
- data CrossJoin a b = a `CrossJoin` b
- data LeftOuterJoin a b = a `LeftOuterJoin` b
- data RightOuterJoin a b = a `RightOuterJoin` b
- data FullOuterJoin a b = a `FullOuterJoin` b
- data JoinKind
  - = InnerJoinKind
  - | CrossJoinKind
  - | LeftOuterJoinKind
  - | RightOuterJoinKind
  - | FullOuterJoinKind
- data OnClauseWithoutMatchingJoinException = OnClauseWithoutMatchingJoinException String
- getTable :: forall t ts. GetFirstTable (SqlExpr (Entity t)) ts => ts -> SqlExpr (Entity t)
- getTableMaybe :: forall t ts. GetFirstTable (SqlExpr (Maybe (Entity t))) ts => ts -> SqlExpr (Maybe (Entity t))
- class GetFirstTable t ts where
  - getFirstTable :: ts -> t
- data SqlQuery a
- data SqlExpr a
- type SqlEntity ent = (PersistEntity ent, PersistEntityBackend ent ~ SqlBackend)
- select :: (SqlSelect a r, MonadIO m, SqlBackendCanRead backend) => SqlQuery a -> ReaderT backend m [r]
- selectOne :: (SqlSelect a r, MonadIO m, SqlBackendCanRead backend) => SqlQuery a -> ReaderT backend m (Maybe r)
- selectSource :: (SqlSelect a r, BackendCompatible SqlBackend backend, IsPersistBackend backend, PersistQueryRead backend, PersistStoreRead backend, PersistUniqueRead backend, MonadResource m) => SqlQuery a -> ConduitT () r (ReaderT backend m) ()
- delete :: (MonadIO m, SqlBackendCanWrite backend) => SqlQuery () -> ReaderT backend m ()
- deleteCount :: (MonadIO m, SqlBackendCanWrite backend) => SqlQuery () -> ReaderT backend m Int64
- update :: (MonadIO m, PersistEntity val, BackendCompatible SqlBackend (PersistEntityBackend val), SqlBackendCanWrite backend) => (SqlExpr (Entity val) -> SqlQuery ()) -> ReaderT backend m ()
- updateCount :: (MonadIO m, PersistEntity val, BackendCompatible SqlBackend (PersistEntityBackend val), SqlBackendCanWrite backend) => (SqlExpr (Entity val) -> SqlQuery ()) -> ReaderT backend m Int64
- insertSelect :: (MonadIO m, PersistEntity a, SqlBackendCanWrite backend) => SqlQuery (SqlExpr (Insertion a)) -> ReaderT backend m ()
- insertSelectCount :: (MonadIO m, PersistEntity a, SqlBackendCanWrite backend) => SqlQuery (SqlExpr (Insertion a)) -> ReaderT backend m Int64
- (<#) :: (a -> b) -> SqlExpr (Value a) -> SqlExpr (Insertion b)
- (<&>) :: SqlExpr (Insertion (a -> b)) -> SqlExpr (Value a) -> SqlExpr (Insertion b)
- renderQueryToText :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => Mode -> SqlQuery a -> ReaderT backend m (Text, [PersistValue])
- renderQuerySelect :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => SqlQuery a -> ReaderT backend m (Text, [PersistValue])
- renderQueryUpdate :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => SqlQuery a -> ReaderT backend m (Text, [PersistValue])
- renderQueryDelete :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => SqlQuery a -> ReaderT backend m (Text, [PersistValue])
- renderQueryInsertInto :: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) => SqlQuery a -> ReaderT backend m (Text, [PersistValue])
- valkey :: (ToBackendKey SqlBackend entity, PersistField (Key entity)) => Int64 -> SqlExpr (Value (Key entity))
- valJ :: PersistField (Key entity) => Value (Key entity) -> SqlExpr (Value (Key entity))
- associateJoin :: forall e1 e0. Ord (Key e0) => [(Entity e0, e1)] -> Map (Key e0) (e0, [e1])
- deleteKey :: (PersistStore backend, BaseBackend backend ~ PersistEntityBackend val, MonadIO m, PersistEntity val) => Key val -> ReaderT backend m ()
- class (PersistField (Key record), ToJSON (Key record), FromJSON (Key record), Show (Key record), Read (Key record), Eq (Key record), Ord (Key record)) => PersistEntity record where
  - type PersistEntityBackend record
  - data Key record
  - data EntityField record :: Type -> Type
  - data Unique record
  - keyToValues :: Key record -> [PersistValue]
  - keyFromValues :: [PersistValue] -> Either Text (Key record)
  - persistIdField :: EntityField record (Key record)
  - entityDef :: proxy record -> EntityDef
  - persistFieldDef :: EntityField record typ -> FieldDef
  - toPersistFields :: record -> [PersistValue]
  - fromPersistValues :: [PersistValue] -> Either Text record
  - tabulateEntityA :: Applicative f => (forall a. EntityField record a -> f a) -> f (Entity record)
  - persistUniqueKeys :: record -> [Unique record]
  - persistUniqueToFieldNames :: Unique record -> NonEmpty (FieldNameHS, FieldNameDB)
  - persistUniqueToValues :: Unique record -> [PersistValue]
  - fieldLens :: EntityField record field -> forall (f :: Type -> Type). Functor f => (field -> f field) -> Entity record -> f (Entity record)
  - keyFromRecordM :: Maybe (record -> Key record)
- data family Key record
- data family Unique record
- newtype Single a = Single {
  - unSingle :: a
  }
- class PersistConfig c where
  - type PersistConfigBackend c :: (Type -> Type) -> Type -> Type
  - type PersistConfigPool c
  - loadConfig :: Value -> Parser c
  - applyEnv :: c -> IO c
  - createPoolConfig :: c -> IO (PersistConfigPool c)
  - runPool :: MonadUnliftIO m => c -> PersistConfigBackend c m a -> PersistConfigPool c -> m a
- type family PersistConfigBackend c :: (Type -> Type) -> Type -> Type
- type family PersistConfigPool c
- newtype ConstraintNameHS = ConstraintNameHS {
  - unConstraintNameHS :: Text
  }
- newtype ConstraintNameDB = ConstraintNameDB {
  - unConstraintNameDB :: Text
  }
- newtype EntityNameDB = EntityNameDB {
  - unEntityNameDB :: Text
  }
- newtype EntityNameHS = EntityNameHS {
  - unEntityNameHS :: Text
  }
- newtype FieldNameHS = FieldNameHS {
  - unFieldNameHS :: Text
  }
- newtype FieldNameDB = FieldNameDB {
  - unFieldNameDB :: Text
  }
- class DatabaseName a where
  - escapeWith :: (Text -> str) -> a -> str
- data LiteralType
  - = Escaped
  - | Unescaped
  - | DbSpecific
- data PersistValue where
  - PersistText Text
  - PersistByteString ByteString
  - PersistInt64 Int64
  - PersistDouble Double
  - PersistRational Rational
  - PersistBool Bool
  - PersistDay Day
  - PersistTimeOfDay TimeOfDay
  - PersistUTCTime UTCTime
  - PersistNull
  - PersistList [PersistValue]
  - PersistMap [(Text, PersistValue)]
  - PersistObjectId ByteString
  - PersistArray [PersistValue]
  - PersistLiteral_ LiteralType ByteString
  - pattern PersistDbSpecific :: ByteString -> PersistValue
  - pattern PersistLiteralEscaped :: ByteString -> PersistValue
  - pattern PersistLiteral :: ByteString -> PersistValue
- data IsolationLevel
  - = ReadUncommitted
  - | ReadCommitted
  - | RepeatableRead
  - | Serializable
- data FieldDef = FieldDef {
  - fieldHaskell :: !FieldNameHS
  - fieldDB :: !FieldNameDB
  - fieldType :: !FieldType
  - fieldSqlType :: !SqlType
  - fieldAttrs :: ![FieldAttr]
  - fieldStrict :: !Bool
  - fieldReference :: !ReferenceDef
  - fieldCascade :: !FieldCascade
  - fieldComments :: !(Maybe Text)
  - fieldGenerated :: !(Maybe Text)
  - fieldIsImplicitIdColumn :: !Bool
  }
- data PersistUpdate
  - = Assign
  - | Add
  - | Subtract
  - | Multiply
  - | Divide
  - | BackendSpecificUpdate Text
- type family BackendSpecificUpdate backend record
- data UpdateException
  - = KeyNotFound String
  - | UpsertError String
- data PersistFilter
  - = Eq
  - | Ne
  - | Gt
  - | Lt
  - | Ge
  - | Le
  - | In
  - | NotIn
- data SqlType
  - = SqlString
  - | SqlInt32
  - | SqlInt64
  - | SqlReal
  - | SqlNumeric Word32 Word32
  - | SqlBool
  - | SqlDay
  - | SqlTime
  - | SqlDayTime
  - | SqlBlob
  - | SqlOther Text
- data PersistException
  - = PersistError Text
  - | PersistMarshalError Text
  - | PersistInvalidField Text
  - | PersistForeignConstraintUnmet Text
  - | PersistMongoDBError Text
  - | PersistMongoDBUnsupported Text
- data CascadeAction
  - = Cascade
  - | Restrict
  - | SetNull
  - | SetDefault
- data FieldCascade = FieldCascade {
  - fcOnUpdate :: !(Maybe CascadeAction)
  - fcOnDelete :: !(Maybe CascadeAction)
  }
- data ForeignDef = ForeignDef {
  - foreignRefTableHaskell :: !EntityNameHS
  - foreignRefTableDBName :: !EntityNameDB
  - foreignConstraintNameHaskell :: !ConstraintNameHS
  - foreignConstraintNameDBName :: !ConstraintNameDB
  - foreignFieldCascade :: !FieldCascade
  - foreignFields :: ![(ForeignFieldDef, ForeignFieldDef)]
  - foreignAttrs :: ![Attr]
  - foreignNullable :: Bool
  - foreignToPrimary :: Bool
  }
- type ForeignFieldDef = (FieldNameHS, FieldNameDB)
- data CompositeDef = CompositeDef {
  - compositeFields :: !(NonEmpty FieldDef)
  - compositeAttrs :: ![Attr]
  }
- data UniqueDef = UniqueDef {
  - uniqueHaskell :: !ConstraintNameHS
  - uniqueDBName :: !ConstraintNameDB
  - uniqueFields :: !(NonEmpty (FieldNameHS, FieldNameDB))
  - uniqueAttrs :: ![Attr]
  }
- data EmbedFieldDef = EmbedFieldDef {
  - emFieldDB :: FieldNameDB
  - emFieldEmbed :: Maybe (Either SelfEmbed EntityNameHS)
  }
- data EmbedEntityDef = EmbedEntityDef {
  - embeddedHaskell :: EntityNameHS
  - embeddedFields :: [EmbedFieldDef]
  }
- data ReferenceDef
  - = NoReference
  - | ForeignRef !EntityNameHS
  - | EmbedRef EntityNameHS
  - | SelfReference
- data FieldType
  - = FTTypeCon (Maybe Text) Text
  - | FTLit FieldTypeLit
  - | FTTypePromoted Text
  - | FTApp FieldType FieldType
  - | FTList FieldType
- data FieldAttr
  - = FieldAttrMaybe
  - | FieldAttrNullable
  - | FieldAttrMigrationOnly
  - | FieldAttrSafeToRemove
  - | FieldAttrNoreference
  - | FieldAttrReference Text
  - | FieldAttrConstraint Text
  - | FieldAttrDefault Text
  - | FieldAttrSqltype Text
  - | FieldAttrMaxlen Integer
  - | FieldAttrSql Text
  - | FieldAttrOther Text
- type Attr = Text
- type ExtraLine = [Text]
- data EntityIdDef
  - = EntityIdField !FieldDef
  - | EntityIdNaturalKey !CompositeDef
- data EntityDef
- data WhyNullable
  - = ByMaybeAttr
  - | ByNullableAttr
- data IsNullable
  - = Nullable !WhyNullable
  - | NotNullable
- data Checkmark
  - = Active
  - | Inactive
- data Statement = Statement {
  - stmtFinalize :: IO ()
  - stmtReset :: IO ()
  - stmtExecute :: [PersistValue] -> IO Int64
  - stmtQuery :: forall (m :: Type -> Type). MonadIO m => [PersistValue] -> Acquire (ConduitM () [PersistValue] m ())
  }
- data InsertSqlResult
  - = ISRSingle Text
  - | ISRInsertGet Text Text
  - | ISRManyKeys Text [PersistValue]
- type LogFunc = Loc -> LogSource -> LogLevel -> LogStr -> IO ()
- newtype OverflowNatural = OverflowNatural {
  - unOverflowNatural :: Natural
  }
- class PersistField a where
  - toPersistValue :: a -> PersistValue
  - fromPersistValue :: PersistValue -> Either Text a
- class SafeToInsert a
- class SymbolToField (sym :: Symbol) rec typ | sym rec -> typ where
  - symbolToField :: EntityField rec typ
- data Entity record = Entity {
  - entityKey :: Key record
  - entityVal :: record
  }
- data FilterValue typ where
  - FilterValue :: forall typ. typ -> FilterValue typ
  - FilterValues :: forall typ. [typ] -> FilterValue typ
  - UnsafeValue :: forall a typ. PersistField a => a -> FilterValue typ
- type family PersistEntityBackend record
- data family EntityField record :: Type -> Type
- class (Show (BackendKey backend), Read (BackendKey backend), Eq (BackendKey backend), Ord (BackendKey backend), PersistStoreRead backend, PersistField (BackendKey backend), ToJSON (BackendKey backend), FromJSON (BackendKey backend)) => PersistStoreWrite backend where
  - insert :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, SafeToInsert record) => record -> ReaderT backend m (Key record)
  - insert_ :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, SafeToInsert record) => record -> ReaderT backend m ()
  - insertMany :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, SafeToInsert record) => [record] -> ReaderT backend m [Key record]
  - insertMany_ :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, SafeToInsert record) => [record] -> ReaderT backend m ()
  - insertEntityMany :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => [Entity record] -> ReaderT backend m ()
  - insertKey :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => Key record -> record -> ReaderT backend m ()
  - repsert :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => Key record -> record -> ReaderT backend m ()
  - repsertMany :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => [(Key record, record)] -> ReaderT backend m ()
  - replace :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => Key record -> record -> ReaderT backend m ()
  - updateGet :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => Key record -> [Update record] -> ReaderT backend m record
- class (Show (BackendKey backend), Read (BackendKey backend), Eq (BackendKey backend), Ord (BackendKey backend), PersistCore backend, PersistField (BackendKey backend), ToJSON (BackendKey backend), FromJSON (BackendKey backend)) => PersistStoreRead backend where
  - get :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => Key record -> ReaderT backend m (Maybe record)
  - getMany :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => [Key record] -> ReaderT backend m (Map (Key record) record)
- class PersistCore backend where
  - data BackendKey backend
- data family BackendKey backend
- class (PersistEntity record, PersistEntityBackend record ~ backend, PersistCore backend) => ToBackendKey backend record where
  - toBackendKey :: Key record -> BackendKey backend
  - fromBackendKey :: BackendKey backend -> Key record
- type PersistRecordBackend record backend = (PersistEntity record, PersistEntityBackend record ~ BaseBackend backend)
- class BackendCompatible sup sub where
  - projectBackend :: sub -> sup
- class HasPersistBackend backend => IsPersistBackend backend
- class HasPersistBackend backend where
  - type BaseBackend backend
  - persistBackend :: backend -> BaseBackend backend
- type family BaseBackend backend
- data SqlBackend
- class PersistEntity record => AtLeastOneUniqueKey record where
  - requireUniquesP :: record -> NonEmpty (Unique record)
- type MultipleUniqueKeysError ty = ((('Text "The entity " ':<>: 'ShowType ty) ':<>: 'Text " has multiple unique keys.") ':$$: ('Text "The function you are trying to call requires only a single " ':<>: 'Text "unique key.")) ':$$: (('Text "There is probably a variant of the function with 'By' " ':<>: 'Text "appended that will allow you to select a unique key ") ':<>: 'Text "for the operation.")
- type NoUniqueKeysError ty = (('Text "The entity " ':<>: 'ShowType ty) ':<>: 'Text " does not have any unique keys.") ':$$: ('Text "The function you are trying to call requires a unique key " ':<>: 'Text "to be defined on the entity.")
- class PersistEntity record => OnlyOneUniqueKey record where
  - onlyUniqueP :: record -> Unique record
- class (PersistUniqueRead backend, PersistStoreWrite backend) => PersistUniqueWrite backend where
  - deleteBy :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => Unique record -> ReaderT backend m ()
  - insertUnique :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, SafeToInsert record) => record -> ReaderT backend m (Maybe (Key record))
  - insertUnique_ :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, SafeToInsert record) => record -> ReaderT backend m (Maybe ())
  - upsert :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, OnlyOneUniqueKey record, SafeToInsert record) => record -> [Update record] -> ReaderT backend m (Entity record)
  - upsertBy :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, SafeToInsert record) => Unique record -> record -> [Update record] -> ReaderT backend m (Entity record)
  - putMany :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, SafeToInsert record) => [record] -> ReaderT backend m ()
- class PersistStoreRead backend => PersistUniqueRead backend where
  - getBy :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => Unique record -> ReaderT backend m (Maybe (Entity record))
  - existsBy :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => Unique record -> ReaderT backend m Bool
- class (PersistQueryRead backend, PersistStoreWrite backend) => PersistQueryWrite backend where
  - updateWhere :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [Filter record] -> [Update record] -> ReaderT backend m ()
  - deleteWhere :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [Filter record] -> ReaderT backend m ()
- class (PersistCore backend, PersistStoreRead backend) => PersistQueryRead backend where
  - selectSourceRes :: forall record (m1 :: Type -> Type) (m2 :: Type -> Type). (PersistRecordBackend record backend, MonadIO m1, MonadIO m2) => [Filter record] -> [SelectOpt record] -> ReaderT backend m1 (Acquire (ConduitM () (Entity record) m2 ()))
  - selectFirst :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [Filter record] -> [SelectOpt record] -> ReaderT backend m (Maybe (Entity record))
  - selectKeysRes :: forall (m1 :: Type -> Type) (m2 :: Type -> Type) record. (MonadIO m1, MonadIO m2, PersistRecordBackend record backend) => [Filter record] -> [SelectOpt record] -> ReaderT backend m1 (Acquire (ConduitM () (Key record) m2 ()))
- type PersistStore a = PersistStoreWrite a
- type PersistUnique a = PersistUniqueWrite a
- type IsSqlBackend backend = (IsPersistBackend backend, BaseBackend backend ~ SqlBackend)
- type SqlWriteT (m :: Type -> Type) a = forall backend. SqlBackendCanWrite backend => ReaderT backend m a
- type SqlReadT (m :: Type -> Type) a = forall backend. SqlBackendCanRead backend => ReaderT backend m a
- type SqlBackendCanWrite backend = (SqlBackendCanRead backend, PersistQueryWrite backend, PersistStoreWrite backend, PersistUniqueWrite backend)
- type SqlBackendCanRead backend = (BackendCompatible SqlBackend backend, PersistQueryRead backend, PersistStoreRead backend, PersistUniqueRead backend)
- newtype SqlWriteBackend = SqlWriteBackend {
  - unSqlWriteBackend :: SqlBackend
  }
- newtype SqlReadBackend = SqlReadBackend {
  - unSqlReadBackend :: SqlBackend
  }
- data ConnectionPoolConfig = ConnectionPoolConfig {
  - connectionPoolConfigStripes :: Int
  - connectionPoolConfigIdleTimeout :: NominalDiffTime
  - connectionPoolConfigSize :: Int
  }
- type ConnectionPool = Pool SqlBackend
- type SqlPersistM = SqlPersistT (NoLoggingT (ResourceT IO))
- type SqlPersistT = ReaderT SqlBackend
- data PersistentSqlException
  - = StatementAlreadyFinalized Text
  - | Couldn'tGetSQLConnection
- data ColumnReference = ColumnReference {
  - crTableName :: !EntityNameDB
  - crConstraintName :: !ConstraintNameDB
  - crFieldCascade :: !FieldCascade
  }
- data Column = Column {
  - cName :: !FieldNameDB
  - cNull :: !Bool
  - cSqlType :: !SqlType
  - cDefault :: !(Maybe Text)
  - cGenerated :: !(Maybe Text)
  - cDefaultConstraintName :: !(Maybe ConstraintNameDB)
  - cMaxLen :: !(Maybe Integer)
  - cReference :: !(Maybe ColumnReference)
  }
- data BackendSpecificOverrides
- class PersistField a => PersistFieldSql a where
  - sqlType :: Proxy a -> SqlType
- newtype EntityWithPrefix (prefix :: Symbol) record = EntityWithPrefix {
  - unEntityWithPrefix :: Entity record
  }
- class RawSql a where
  - rawSqlCols :: (Text -> Text) -> a -> (Int, [Text])
  - rawSqlColCountReason :: a -> String
  - rawSqlProcessRow :: [PersistValue] -> Either Text a
- data FilterTablePrefix
  - = PrefixTableName
  - | PrefixExcluded
- newtype PersistUnsafeMigrationException = PersistUnsafeMigrationException [(Bool, Sql)]
- type Migration = WriterT [Text] (WriterT CautiousMigration (ReaderT SqlBackend IO)) ()
- type CautiousMigration = [(Bool, Sql)]
- type Sql = Text
- insertBy :: forall record backend (m :: Type -> Type). (MonadIO m, PersistUniqueWrite backend, PersistRecordBackend record backend, AtLeastOneUniqueKey record, SafeToInsert record) => record -> ReaderT backend m (Either (Entity record) (Key record))
- migrate :: [EntityDef] -> EntityDef -> Migration
- reportError :: Text -> Migration
- rawSql :: forall a (m :: Type -> Type) backend. (RawSql a, MonadIO m, BackendCompatible SqlBackend backend) => Text -> [PersistValue] -> ReaderT backend m [a]
- fromPersistValueText :: PersistValue -> Either Text Text
- fieldAttrsContainsNullable :: [FieldAttr] -> IsNullable
- entitiesPrimary :: EntityDef -> NonEmpty FieldDef
- entityPrimary :: EntityDef -> Maybe CompositeDef
- keyAndEntityFields :: EntityDef -> NonEmpty FieldDef
- parseFieldAttrs :: [Text] -> [FieldAttr]
- isFieldNotGenerated :: FieldDef -> Bool
- isHaskellField :: FieldDef -> Bool
- noCascade :: FieldCascade
- renderFieldCascade :: FieldCascade -> Text
- renderCascadeAction :: CascadeAction -> Text
- setFieldAttrs :: [FieldAttr] -> FieldDef -> FieldDef
- overFieldAttrs :: ([FieldAttr] -> [FieldAttr]) -> FieldDef -> FieldDef
- addFieldAttr :: FieldAttr -> FieldDef -> FieldDef
- isFieldNullable :: FieldDef -> IsNullable
- isFieldMaybe :: FieldDef -> Bool
- getEntityUniquesNoPrimaryKey :: EntityDef -> [UniqueDef]
- getEntityUniques :: EntityDef -> [UniqueDef]
- getEntityHaskellName :: EntityDef -> EntityNameHS
- getEntityDBName :: EntityDef -> EntityNameDB
- getEntityExtra :: EntityDef -> Map Text [[Text]]
- setEntityDBName :: EntityNameDB -> EntityDef -> EntityDef
- getEntityComments :: EntityDef -> Maybe Text
- getEntityForeignDefs :: EntityDef -> [ForeignDef]
- getEntityFields :: EntityDef -> [FieldDef]
- getEntityFieldsDatabase :: EntityDef -> [FieldDef]
- isEntitySum :: EntityDef -> Bool
- getEntityId :: EntityDef -> EntityIdDef
- getEntityIdField :: EntityDef -> Maybe FieldDef
- setEntityId :: FieldDef -> EntityDef -> EntityDef
- setEntityIdDef :: EntityIdDef -> EntityDef -> EntityDef
- getEntityKeyFields :: EntityDef -> NonEmpty FieldDef
- overEntityFields :: ([FieldDef] -> [FieldDef]) -> EntityDef -> EntityDef
- tabulateEntity :: PersistEntity record => (forall a. EntityField record a -> a) -> Entity record
- entityValues :: PersistEntity record => Entity record -> [PersistValue]
- keyValueEntityToJSON :: (PersistEntity record, ToJSON record) => Entity record -> Value
- keyValueEntityFromJSON :: (PersistEntity record, FromJSON record) => Value -> Parser (Entity record)
- entityIdToJSON :: (PersistEntity record, ToJSON record) => Entity record -> Value
- entityIdFromJSON :: (PersistEntity record, FromJSON record) => Value -> Parser (Entity record)
- toPersistValueJSON :: ToJSON a => a -> PersistValue
- fromPersistValueJSON :: FromJSON a => PersistValue -> Either Text a
- withBaseBackend :: forall backend (m :: Type -> Type) a. HasPersistBackend backend => ReaderT (BaseBackend backend) m a -> ReaderT backend m a
- withCompatibleBackend :: forall sup sub (m :: Type -> Type) a. BackendCompatible sup sub => ReaderT sup m a -> ReaderT sub m a
- liftPersist :: (MonadIO m, MonadReader backend m) => ReaderT backend IO b -> m b
- getJust :: forall record backend (m :: Type -> Type). (PersistStoreRead backend, PersistRecordBackend record backend, MonadIO m) => Key record -> ReaderT backend m record
- getJustEntity :: forall record backend (m :: Type -> Type). (PersistEntityBackend record ~ BaseBackend backend, MonadIO m, PersistEntity record, PersistStoreRead backend) => Key record -> ReaderT backend m (Entity record)
- belongsTo :: forall ent1 ent2 backend (m :: Type -> Type). (PersistStoreRead backend, PersistEntity ent1, PersistRecordBackend ent2 backend, MonadIO m) => (ent1 -> Maybe (Key ent2)) -> ent1 -> ReaderT backend m (Maybe ent2)
- belongsToJust :: forall ent1 ent2 backend (m :: Type -> Type). (PersistStoreRead backend, PersistEntity ent1, PersistRecordBackend ent2 backend, MonadIO m) => (ent1 -> Key ent2) -> ent1 -> ReaderT backend m ent2
- insertEntity :: forall e backend (m :: Type -> Type). (PersistStoreWrite backend, PersistRecordBackend e backend, SafeToInsert e, MonadIO m, HasCallStack) => e -> ReaderT backend m (Entity e)
- getEntity :: forall e backend (m :: Type -> Type). (PersistStoreRead backend, PersistRecordBackend e backend, MonadIO m) => Key e -> ReaderT backend m (Maybe (Entity e))
- insertRecord :: forall record backend (m :: Type -> Type). (PersistEntityBackend record ~ BaseBackend backend, PersistEntity record, MonadIO m, PersistStoreWrite backend, SafeToInsert record, HasCallStack) => record -> ReaderT backend m record
- onlyOneUniqueDef :: (OnlyOneUniqueKey record, Monad proxy) => proxy record -> UniqueDef
- insertUniqueEntity :: forall record backend (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, PersistUniqueWrite backend, SafeToInsert record) => record -> ReaderT backend m (Maybe (Entity record))
- onlyUnique :: forall record backend (m :: Type -> Type). (MonadIO m, PersistUniqueWrite backend, PersistRecordBackend record backend, OnlyOneUniqueKey record) => record -> ReaderT backend m (Unique record)
- getByValue :: forall record (m :: Type -> Type) backend. (MonadIO m, PersistUniqueRead backend, PersistRecordBackend record backend, AtLeastOneUniqueKey record) => record -> ReaderT backend m (Maybe (Entity record))
- replaceUnique :: forall record backend (m :: Type -> Type). (MonadIO m, Eq (Unique record), PersistRecordBackend record backend, PersistUniqueWrite backend) => Key record -> record -> ReaderT backend m (Maybe (Unique record))
- checkUnique :: forall record backend (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, PersistUniqueRead backend) => record -> ReaderT backend m (Maybe (Unique record))
- checkUniqueUpdateable :: forall record backend (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, PersistUniqueRead backend) => Entity record -> ReaderT backend m (Maybe (Unique record))
- selectKeys :: forall record backend (m :: Type -> Type). (PersistQueryRead backend, MonadResource m, PersistRecordBackend record backend, MonadReader backend m) => [Filter record] -> [SelectOpt record] -> ConduitM () (Key record) m ()
- writeToUnknown :: forall (m :: Type -> Type) a. Monad m => ReaderT SqlWriteBackend m a -> ReaderT SqlBackend m a
- readToWrite :: forall (m :: Type -> Type) a. Monad m => ReaderT SqlReadBackend m a -> ReaderT SqlWriteBackend m a
- readToUnknown :: forall (m :: Type -> Type) a. Monad m => ReaderT SqlReadBackend m a -> ReaderT SqlBackend m a
- defaultConnectionPoolConfig :: ConnectionPoolConfig
- getBackendSpecificForeignKeyName :: BackendSpecificOverrides -> Maybe (EntityNameDB -> FieldNameDB -> ConstraintNameDB)
- setBackendSpecificForeignKeyName :: (EntityNameDB -> FieldNameDB -> ConstraintNameDB) -> BackendSpecificOverrides -> BackendSpecificOverrides
- emptyBackendSpecificOverrides :: BackendSpecificOverrides
- defaultAttribute :: [FieldAttr] -> Maybe Text
- mkColumns :: [EntityDef] -> EntityDef -> BackendSpecificOverrides -> ([Column], [UniqueDef], [ForeignDef])
- toJsonText :: ToJSON j => j -> Text
- unPrefix :: forall (prefix :: Symbol) record. EntityWithPrefix prefix record -> Entity record
- rawQuery :: forall (m :: Type -> Type) env. (MonadResource m, MonadReader env m, BackendCompatible SqlBackend env) => Text -> [PersistValue] -> ConduitM () [PersistValue] m ()
- rawQueryRes :: forall (m1 :: Type -> Type) (m2 :: Type -> Type) env. (MonadIO m1, MonadIO m2, BackendCompatible SqlBackend env) => Text -> [PersistValue] -> ReaderT env m1 (Acquire (ConduitM () [PersistValue] m2 ()))
- rawExecute :: forall (m :: Type -> Type) backend. (MonadIO m, BackendCompatible SqlBackend backend) => Text -> [PersistValue] -> ReaderT backend m ()
- rawExecuteCount :: forall (m :: Type -> Type) backend. (MonadIO m, BackendCompatible SqlBackend backend) => Text -> [PersistValue] -> ReaderT backend m Int64
- getStmtConn :: SqlBackend -> Text -> IO Statement
- runSqlPool :: forall backend m a. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> Pool backend -> m a
- runSqlPoolWithIsolation :: forall backend m a. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> Pool backend -> IsolationLevel -> m a
- runSqlPoolNoTransaction :: forall backend m a. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> Pool backend -> Maybe IsolationLevel -> m a
- runSqlPoolWithHooks :: forall backend m a before after onException. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> Pool backend -> Maybe IsolationLevel -> (backend -> m before) -> (backend -> m after) -> (backend -> SomeException -> m onException) -> m a
- runSqlPoolWithExtensibleHooks :: forall backend m a. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> Pool backend -> Maybe IsolationLevel -> SqlPoolHooks m backend -> m a
- acquireSqlConn :: (MonadReader backend m, BackendCompatible SqlBackend backend) => m (Acquire backend)
- acquireSqlConnWithIsolation :: (MonadReader backend m, BackendCompatible SqlBackend backend) => IsolationLevel -> m (Acquire backend)
- runSqlConn :: forall backend m a. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> backend -> m a
- runSqlConnWithIsolation :: forall backend m a. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> backend -> IsolationLevel -> m a
- runSqlPersistM :: BackendCompatible SqlBackend backend => ReaderT backend (NoLoggingT (ResourceT IO)) a -> backend -> IO a
- runSqlPersistMPool :: BackendCompatible SqlBackend backend => ReaderT backend (NoLoggingT (ResourceT IO)) a -> Pool backend -> IO a
- liftSqlPersistMPool :: forall backend m a. (MonadIO m, BackendCompatible SqlBackend backend) => ReaderT backend (NoLoggingT (ResourceT IO)) a -> Pool backend -> m a
- withSqlPool :: forall backend m a. (MonadLoggerIO m, MonadUnliftIO m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> Int -> (Pool backend -> m a) -> m a
- withSqlPoolWithConfig :: forall backend m a. (MonadLoggerIO m, MonadUnliftIO m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> ConnectionPoolConfig -> (Pool backend -> m a) -> m a
- createSqlPool :: forall backend m. (MonadLoggerIO m, MonadUnliftIO m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> Int -> m (Pool backend)
- createSqlPoolWithConfig :: (MonadLoggerIO m, MonadUnliftIO m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> ConnectionPoolConfig -> m (Pool backend)
- withSqlConn :: forall backend m a. (MonadUnliftIO m, MonadLoggerIO m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> (backend -> m a) -> m a
- close' :: BackendCompatible SqlBackend backend => backend -> IO ()
- withRawQuery :: forall (m :: Type -> Type) a. MonadIO m => Text -> [PersistValue] -> ConduitM [PersistValue] Void IO a -> ReaderT SqlBackend m a
- toSqlKey :: ToBackendKey SqlBackend record => Int64 -> Key record
- fromSqlKey :: ToBackendKey SqlBackend record => Key record -> Int64
- getTableName :: forall record (m :: Type -> Type) backend. (PersistEntity record, BackendCompatible SqlBackend backend, Monad m) => record -> ReaderT backend m Text
- tableDBName :: PersistEntity record => record -> EntityNameDB
- getFieldName :: forall record typ (m :: Type -> Type) backend. (PersistEntity record, PersistEntityBackend record ~ SqlBackend, BackendCompatible SqlBackend backend, Monad m) => EntityField record typ -> ReaderT backend m Text
- fieldDBName :: PersistEntity record => EntityField record typ -> FieldNameDB
- filterClause :: PersistEntity val => Maybe FilterTablePrefix -> SqlBackend -> [Filter val] -> Text
- filterClauseWithVals :: PersistEntity val => Maybe FilterTablePrefix -> SqlBackend -> [Filter val] -> (Text, [PersistValue])
- orderClause :: PersistEntity val => Maybe FilterTablePrefix -> SqlBackend -> [SelectOpt val] -> Text
- decorateSQLWithLimitOffset :: Text -> (Int, Int) -> Text -> Text
- parseMigration :: forall (m :: Type -> Type). (HasCallStack, MonadIO m) => Migration -> ReaderT SqlBackend m (Either [Text] CautiousMigration)
- parseMigration' :: forall (m :: Type -> Type). (HasCallStack, MonadIO m) => Migration -> ReaderT SqlBackend m CautiousMigration
- printMigration :: forall (m :: Type -> Type). (HasCallStack, MonadIO m) => Migration -> ReaderT SqlBackend m ()
- showMigration :: forall (m :: Type -> Type). (HasCallStack, MonadIO m) => Migration -> ReaderT SqlBackend m [Text]
- getMigration :: forall (m :: Type -> Type). (MonadIO m, HasCallStack) => Migration -> ReaderT SqlBackend m [Sql]
- runMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m ()
- runMigrationQuiet :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m [Text]
- runMigrationSilent :: forall (m :: Type -> Type). MonadUnliftIO m => Migration -> ReaderT SqlBackend m [Text]
- runMigrationUnsafe :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m ()
- runMigrationUnsafeQuiet :: forall (m :: Type -> Type). (HasCallStack, MonadIO m) => Migration -> ReaderT SqlBackend m [Text]
- reportErrors :: [Text] -> Migration
- addMigration :: Bool -> Sql -> Migration
- addMigrations :: CautiousMigration -> Migration
- runSqlCommand :: SqlPersistT IO () -> Migration
- transactionSave :: forall (m :: Type -> Type). MonadIO m => ReaderT SqlBackend m ()
- transactionSaveWithIsolation :: forall (m :: Type -> Type). MonadIO m => IsolationLevel -> ReaderT SqlBackend m ()
- transactionUndo :: forall (m :: Type -> Type). MonadIO m => ReaderT SqlBackend m ()
- transactionUndoWithIsolation :: forall (m :: Type -> Type). MonadIO m => IsolationLevel -> ReaderT SqlBackend m ()

# Setup

If you're already using Database.Esqueleto, then you can get started using this module just by changing your imports slightly, as well as enabling the TypeApplications extension.

    {-# LANGUAGE TypeApplications #-}

    ...

    import Database.Esqueleto.Experimental

Note: Prior to `esqueleto-3.3.4.0`, the `Database.Esqueleto.Experimental` module did not reexport `Data.Esqueleto`.

# Introduction

This module is fully backwards-compatible extension to the `esqueleto` EDSL that expands subquery functionality and enables SQL set operations to be written directly in Haskell. Specifically, this enables:

- Subqueries in `JOIN` statements
- `UNION`
- `UNION` `ALL`
- `INTERSECT`
- `EXCEPT`

As a consequence of this, several classes of runtime errors are now caught at compile time. This includes missing `on` clauses and improper handling of `Maybe` values in outer joins.

This module can be used in conjunction with the main Database.Esqueleto module, but doing so requires qualified imports to avoid ambiguous definitions of `on` and `from`, which are defined in both modules.

Below we will give an overview of how to use this module and the features it enables.

# A New Syntax

This module introduces a new syntax that serves to enable the aforementioned features. This new syntax also changes how joins written in the `esqueleto` EDSL to more closely resemble the underlying SQL.

For our examples, we'll use a schema similar to the one in the Getting Started section of Database.Esqueleto:

    share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persist|
      Person
        name String
        age Int Maybe
        deriving Eq Show
      BlogPost
        title String
        authorId PersonId
        deriving Eq Show
      Follow
        follower PersonId
        followed PersonId
        deriving Eq Show
    |]

### Example 1: Simple select

Let's select all people who are named "John".

#### Database.Esqueleto:

    select $
    from $ \people -> do
    where_ (people ^. PersonName ==. val "John")
    pure people

#### Database.Esqueleto.Experimental:

    select $ do
    people <- from $ table @Person
    where_ (people ^. PersonName ==. val "John")
    pure people

### Example 2: Select with join

Let's select all people and their blog posts who are over the age of 18.

#### Database.Esqueleto:

    select $
    from $ \(people `LeftOuterJoin` blogPosts) -> do
    on (just (people ^. PersonId) ==. blogPosts ?. BlogPostAuthorId)
    where_ (people ^. PersonAge >. just (val 18))
    pure (people, blogPosts)

#### Database.Esqueleto.Experimental:

Here we use the `:&` operator to pattern match against the joined tables.

    select $ do
    (people :& blogPosts) <-
        from $ table @Person
        `leftJoin` table @BlogPost
        `on` (\(people :& blogPosts) ->
                just (people ^. PersonId) ==. blogPosts ?. BlogPostAuthorId)
    where_ (people ^. PersonAge >. just (val 18))
    pure (people, blogPosts)

### Example 3: Select with multi-table join

Let's select all people who follow a person named "John", including the name of each follower.

#### Database.Esqueleto:

    select $
    from $ \(
     people1
     `InnerJoin` followers
     `InnerJoin` people2
    ) -> do
    on (people1 ^. PersonId ==. followers ^. FollowFollowed)
    on (followers ^. FollowFollower ==. people2 ^. PersonId)
    where_ (people1 ^. PersonName ==. val "John")
    pure (followers, people2)

#### Database.Esqueleto.Experimental:

In this version, with each successive `on` clause, only the tables we have already joined into are in scope, so we must pattern match accordingly. In this case, in the second `innerJoin`, we do not use the first `Person` reference, so we use `_` as a placeholder to ignore it. This prevents a possible runtime error where a table is referenced before it appears in the sequence of `JOIN`s.

    select $ do
    (people1 :& followers :& people2) <-
        from $ table @Person
        `innerJoin` table @Follow
        `on` (\(people1 :& followers) ->
                people1 ^. PersonId ==. followers ^. FollowFollowed)
        `innerJoin` table @Person
        `on` (\(_ :& followers :& people2) ->
                followers ^. FollowFollower ==. people2 ^. PersonId)
    where_ (people1 ^. PersonName ==. val "John")
    pure (followers, people2)

### Example 4: Counting results of a subquery

Let's count the number of people who have posted at least 10 posts

#### Database.Esqueleto:

    select $ pure $ subSelectCount $
    from $ \(
      people
      `InnerJoin` blogPosts
    ) -> do
    on (people ^. PersonId ==. blogPosts ^. BlogPostAuthorId)
    groupBy (people ^. PersonId)
    having ((count $ blogPosts ^. BlogPostId) >. val 10)
    pure people

#### Database.Esqueleto.Experimental:

    select $ do
    peopleWithPosts <-
      from $ do
        (people :& blogPosts) <-
          from $ table @Person
          `innerJoin` table @BlogPost
          `on` (\(p :& bP) ->
                  p ^. PersonId ==. bP ^. BlogPostAuthorId)
        groupBy (people ^. PersonId)
        having ((count $ blogPosts ^. BlogPostId) >. val 10)
        pure people
    pure $ count (peopleWithPosts ^. PersonId)

We now have the ability to refactor this

### Example 5: Sorting the results of a UNION with limits

Out of all of the posts created by a person and the people they follow, generate a list of the first 25 posts, sorted alphabetically.

#### Database.Esqueleto:

Since `UNION` is not supported, this requires using `rawSql`. (Not shown)

#### Database.Esqueleto.Experimental:

Since this module supports all set operations (see `SqlSetOperation`), we can use `Union` to write this query.

    select $ do
    (authors, blogPosts) <- from $
      (do
        (author :& blogPost) <-
          from $ table @Person
          `innerJoin` table @BlogPost
          `on` (\(a :& bP) ->
                  a ^. PersonId ==. bP ^. BlogPostAuthorId)
        where_ (author ^. PersonId ==. val currentPersonId)
        pure (author, blogPost)
      )
      `union_`
      (do
        (follow :& blogPost :& author) <-
          from $ table @Follow
          `innerJoin` table @BlogPost
          `on` (\(f :& bP) ->
                  f ^. FollowFollowed ==. bP ^. BlogPostAuthorId)
          `innerJoin` table @Person
          `on` (\(_ :& bP :& a) ->
                  bP ^. BlogPostAuthorId ==. a ^. PersonId)
        where_ (follow ^. FollowFollower ==. val currentPersonId)
        pure (author, blogPost)
      )
    orderBy [ asc (blogPosts ^. BlogPostTitle) ]
    limit 25
    pure (authors, blogPosts)

### Example 6: LATERAL JOIN

As of version `3.4.0.0`, lateral subquery joins are supported.

    select $ do
    (salesPerson :& maxSaleAmount :& maxSaleCustomerName) <-
      from $ table @SalesPerson
      `crossJoinLateral` (\salesPerson -> do
            sales <- from $ table @Sale
            where_ $ sales ^. SaleSalesPersonId ==. salesPerson ^. SalesPersonId
            pure $ max_ (sales ^. SaleAmount)
            )
      `crossJoinLateral` (\(salesPerson :& maxSaleAmount) -> do
            sales <- from $ table @Sale
            where_ $ sales ^. SaleSalesPersonId ==. salesPerson ^. SalesPersonId
                 &&. sales ^. SaleAmount ==. maxSaleAmount
            pure $ sales ^. SaleCustomerName)
            )
    pure (salesPerson ^. SalesPersonName, maxSaleAmount, maxSaleCustomerName)

This is the equivalent to the following SQL (example taken from the MySQL Lateral Derived Table documentation):

    SELECT
      salesperson.name,
      max_sale.amount,
      max_sale_customer.customer_name
    FROM
      salesperson,
      -- calculate maximum size, cache it in transient derived table max_sale
      LATERAL
      (SELECT MAX(amount) AS amount
        FROM all_sales
        WHERE all_sales.salesperson_id = salesperson.id)
      AS max_sale,
      LATERAL
      (SELECT customer_name
        FROM all_sales
        WHERE all_sales.salesperson_id = salesperson.id
        AND all_sales.amount =
            -- the cached maximum size
            max_sale.amount)
      AS max_sale_customer;

# Documentation

## Basic Queries

from :: ToFrom a a' => a -> SqlQuery a' Source #

`FROM` clause, used to bring entities into scope.

Internally, this function uses the `From` datatype. Unlike the old `from`, this does not take a function as a parameter, but rather a value that represents a `JOIN` tree constructed out of instances of `From`. This implementation eliminates certain types of runtime errors by preventing the construction of invalid SQL (e.g. illegal nested-`from`).

table :: forall ent. PersistEntity ent => From (SqlExpr (Entity ent)) Source #

Bring a PersistEntity into scope from a table

    select $ from $ table @People

Since: 3.5.0.0

data Table a Source #

Deprecated: @since 3.5.0.0 - use `table` instead

Constructors

Table | Deprecated: @since 3.5.0.0 - use `table` instead

#### Instances

Instances details

PersistEntity ent => ToFrom (Table ent) (SqlExpr (Entity ent)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.From Methods toFrom :: Table ent -> From (SqlExpr (Entity ent)) Source #

newtype SubQuery a Source #

Deprecated: Since: 3.4.0.0 - It is no longer necessary to tag `SqlQuery` values with `SubQuery`

Constructors

SubQuery a | Deprecated: Since: 3.4.0.0 - It is no longer necessary to tag `SqlQuery` values with `SubQuery`

#### Instances

Instances details

(SqlSelect a r, ToAlias a, ToAliasReference a) => ToFrom (SubQuery (SqlQuery a)) a Source # |
Instance details Defined in Database.Esqueleto.Experimental.From Methods toFrom :: SubQuery (SqlQuery a) -> From a Source #

selectQuery :: (SqlSelect a r, ToAlias a, ToAliasReference a) => SqlQuery a -> From a Source #

Select from a subquery, often used in conjuction with joins but can be used without any joins. Because `SqlQuery` has a `ToFrom` instance you probably dont need to use this function directly.

    select $
         p <- from $
                 selectQuery do
                 p <- from $ table @Person
                 limit 5
                 orderBy [ asc p ^. PersonAge ]
         ...

Since: 3.5.0.0

## Joins

data a :& b infixl 2 Source #

A left-precedence pair. Pronounced "and". Used to represent expressions that have been joined together.

The precedence behavior can be demonstrated by:

    a :& b :& c == ((a :& b) :& c)

See the examples at the beginning of this module to see how this operator is used in `JOIN` operations.

Constructors

a :& b infixl 2 |

#### Instances

Instances details

(ToFrom a a', ToFrom b b') => DoCrossJoin NotLateral a b (a' :& b') Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods doCrossJoin :: Proxy NotLateral -> a -> b -> From (a' :& b') Source #
(ToFrom a a', ToFrom b b', HasOnClause rhs (a' :& b'), rhs ~ (b, (a' :& b') -> SqlExpr (Value Bool))) => DoInnerJoin NotLateral a rhs (a' :& b') Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods doInnerJoin :: Proxy NotLateral -> a -> rhs -> From (a' :& b') Source #
(ToFrom a a', ToFrom b b', ToMaybe b', ToMaybeT b' ~ mb, HasOnClause rhs (a' :& mb), rhs ~ (b, (a' :& mb) -> SqlExpr (Value Bool))) => DoLeftJoin NotLateral a rhs (a' :& mb) Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods doLeftJoin :: Proxy NotLateral -> a -> rhs -> From (a' :& mb) Source #
(ToFrom a a', SqlSelect b r, ToAlias b, ToAliasReference b) => DoCrossJoin Lateral a (a' -> SqlQuery b) (a' :& b) Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods doCrossJoin :: Proxy Lateral -> a -> (a' -> SqlQuery b) -> From (a' :& b) Source #
GetFirstTable t (t :& ts) Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods getFirstTable :: (t :& ts) -> t Source #
GetFirstTable t ts => GetFirstTable t (ts :& x) Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods getFirstTable :: (ts :& x) -> t Source #
GetFirstTable t (x :& t) Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods getFirstTable :: (x :& t) -> t Source #
(Show a, Show b) => Show (a :& b) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods showsPrec :: Int -> (a :& b) -> ShowS Source # show :: (a :& b) -> String Source # showList :: [a :& b] -> ShowS Source #
(ToAlias a, ToAlias b) => ToAlias (a :& b) Source # | Identical to the tuple instance and provided for convenience. Since: 3.5.3.0
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods toAlias :: (a :& b) -> SqlQuery (a :& b) Source #
(ToAliasReference a, ToAliasReference b) => ToAliasReference (a :& b) Source # | Identical to the tuple instance and provided for convenience. Since: 3.5.3.0
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods toAliasReference :: Ident -> (a :& b) -> SqlQuery (a :& b) Source #
(ToMaybe a, ToMaybe b) => ToMaybe (a :& b) Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Associated Types type ToMaybeT (a :& b) Source # Methods toMaybe :: (a :& b) -> ToMaybeT (a :& b) Source #
(LockableEntity a, LockableEntity b) => LockableEntity (a :& b) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods flattenLockableEntity :: (a :& b) -> NonEmpty LockableSqlExpr Source #
(Eq a, Eq b) => Eq (a :& b) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods (==) :: (a :& b) -> (a :& b) -> Bool Source # (/=) :: (a :& b) -> (a :& b) -> Bool Source #
(ToFrom a a', ToFrom b b', ToMaybe a', ToMaybeT a' ~ ma, ToMaybe b', ToMaybeT b' ~ mb, HasOnClause rhs (ma :& mb), ErrorOnLateral b, rhs ~ (b, (ma :& mb) -> SqlExpr (Value Bool))) => ToFrom (FullOuterJoin a rhs) (ma :& mb) Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods toFrom :: FullOuterJoin a rhs -> From (ma :& mb) Source #
(ToFrom a a', ToFrom b b', ToMaybe a', ToMaybeT a' ~ ma, HasOnClause rhs (ma :& b'), ErrorOnLateral b, rhs ~ (b, (ma :& b') -> SqlExpr (Value Bool))) => ToFrom (RightOuterJoin a rhs) (ma :& b') Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods toFrom :: RightOuterJoin a rhs -> From (ma :& b') Source #
(SqlSelect a ra, SqlSelect b rb) => SqlSelect (a :& b) (ra :& rb) Source # | You may return joined values from a `select` query - this is identical to the tuple instance, but is provided for convenience. Since: 3.5.2.0
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods sqlSelectCols :: IdentInfo -> (a :& b) -> (Builder, [PersistValue]) Source # sqlSelectColCount :: Proxy (a :& b) -> Int Source # sqlSelectProcessRow :: [PersistValue] -> Either Text (ra :& rb) Source # sqlInsertInto :: IdentInfo -> (a :& b) -> (Builder, [PersistValue]) Source #
type ToMaybeT (a :& b) Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join type ToMaybeT (a :& b) = ToMaybeT a :& ToMaybeT b

on :: ValidOnClause a => a -> (b -> SqlExpr (Value Bool)) -> (a, b -> SqlExpr (Value Bool)) infix 9 Source #

An `ON` clause that describes how two tables are related. This should be used as an infix operator after a `JOIN`. For example,

    select $
    from $ table @Person
    `innerJoin` table @BlogPost
    `on` (\(p :& bP) ->
            p ^. PersonId ==. bP ^. BlogPostAuthorId)

innerJoin :: (ToFrom a a', ToFrom b b', HasOnClause rhs (a' :& b'), rhs ~ (b, (a' :& b') -> SqlExpr (Value Bool))) => a -> rhs -> From (a' :& b') infixl 2 Source #

INNER JOIN

Used as an infix operator `innerJoin`

    select $
    from $ table @Person
    `innerJoin` table @BlogPost
    `on` (\(p :& bp) ->
            p ^. PersonId ==. bp ^. BlogPostAuthorId)

Since: 3.5.0.0

innerJoinLateral :: (ToFrom a a', HasOnClause rhs (a' :& b), SqlSelect b r, ToAlias b, ToAliasReference b, rhs ~ (a' -> SqlQuery b, (a' :& b) -> SqlExpr (Value Bool))) => a -> rhs -> From (a' :& b) infixl 2 Source #

INNER JOIN LATERAL

A Lateral subquery join allows the joined query to reference entities from the left hand side of the join. Discards rows that don't match the on clause

Used as an infix operator `innerJoinLateral`

See example 6

Since: 3.5.0.0

leftJoin :: (ToFrom a a', ToFrom b b', ToMaybe b', HasOnClause rhs (a' :& ToMaybeT b'), rhs ~ (b, (a' :& ToMaybeT b') -> SqlExpr (Value Bool))) => a -> rhs -> From (a' :& ToMaybeT b') infixl 2 Source #

LEFT OUTER JOIN

Join where the right side may not exist. If the on clause fails then the right side will be NULL'ed Because of this the right side needs to be handled as a Maybe

Used as an infix operator `leftJoin`

    select $
    from $ table @Person
    `leftJoin` table @BlogPost
    `on` (\(p :& bp) ->
            just (p ^. PersonId) ==. bp ?. BlogPostAuthorId)

Since: 3.5.0.0

leftJoinLateral :: (ToFrom a a', SqlSelect b r, HasOnClause rhs (a' :& ToMaybeT b), ToAlias b, ToAliasReference b, ToMaybe b, rhs ~ (a' -> SqlQuery b, (a' :& ToMaybeT b) -> SqlExpr (Value Bool))) => a -> rhs -> From (a' :& ToMaybeT b) infixl 2 Source #

LEFT OUTER JOIN LATERAL

Lateral join where the right side may not exist. In the case that the query returns nothing or the on clause fails the right side of the join will be NULL'ed Because of this the right side needs to be handled as a Maybe

Used as an infix operator `leftJoinLateral`

See example 6 for how to use LATERAL

Since: 3.5.0.0

rightJoin :: (ToFrom a a', ToFrom b b', ToMaybe a', HasOnClause rhs (ToMaybeT a' :& b'), rhs ~ (b, (ToMaybeT a' :& b') -> SqlExpr (Value Bool))) => a -> rhs -> From (ToMaybeT a' :& b') infixl 2 Source #

RIGHT OUTER JOIN

Join where the left side may not exist. If the on clause fails then the left side will be NULL'ed Because of this the left side needs to be handled as a Maybe

Used as an infix operator `rightJoin`

    select $
    from $ table @Person
    `rightJoin` table @BlogPost
    `on` (\(p :& bp) ->
            p ?. PersonId ==. bp ^. BlogPostAuthorId)

Since: 3.5.0.0

fullOuterJoin :: (ToFrom a a', ToFrom b b', ToMaybe a', ToMaybe b', HasOnClause rhs (ToMaybeT a' :& ToMaybeT b'), rhs ~ (b, (ToMaybeT a' :& ToMaybeT b') -> SqlExpr (Value Bool))) => a -> rhs -> From (ToMaybeT a' :& ToMaybeT b') infixl 2 Source #

FULL OUTER JOIN

Join where both sides of the join may not exist. Because of this the result needs to be handled as a Maybe

Used as an infix operator `fullOuterJoin`

    select $
    from $ table @Person
    `fullOuterJoin` table @BlogPost
    `on` (\(p :& bp) ->
            p ?. PersonId ==. bp ?. BlogPostAuthorId)

Since: 3.5.0.0

crossJoin :: (ToFrom a a', ToFrom b b') => a -> b -> From (a' :& b') infixl 2 Source #

CROSS JOIN

Used as an infix `crossJoin`

    select $ do
    from $ table @Person
    `crossJoin` table @BlogPost

Since: 3.5.0.0

crossJoinLateral :: (ToFrom a a', SqlSelect b r, ToAlias b, ToAliasReference b) => a -> (a' -> SqlQuery b) -> From (a' :& b) infixl 2 Source #

CROSS JOIN LATERAL

A Lateral subquery join allows the joined query to reference entities from the left hand side of the join.

Used as an infix operator `crossJoinLateral`

See example 6

Since: 3.5.0.0

## Set Operations

Data type that represents SQL set operations. This includes `UNION`, `UNION` `ALL`, `EXCEPT`, and `INTERSECT`. These types form a binary tree, with `SqlQuery` values on the leaves.

Each function corresponding to the aforementioned set operations can be used as an infix in a `from` to help with readability and lead to code that closely resembles the underlying SQL. For example,

    select $ from $
      (do
         a <- from $ table A
         pure $ a ^. ASomeCol
      )
      `union_`
      (do
         b <- from $ table B
         pure $ b ^. BSomeCol
      )

is translated into

    SELECT * FROM (
      (SELECT a.some_col FROM a)
      UNION
      (SELECT b.some_col FROM b)
    )

union_ :: Union_ a => a Source #

`UNION` SQL set operation. Can be used as an infix function between `SqlQuery` values.

data Union a b Source #

Deprecated: Since: 3.4.0.0 - Use the `union_` function instead of the `Union` data constructor

Constructors

a `Union` b | Deprecated: Since: 3.4.0.0 - Use the `union_` function instead of the `Union` data constructor

#### Instances

Instances details

ToSqlSetOperation a a' => ToSqlSetOperation (Union a a) a' Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.SqlSetOperation Methods toSqlSetOperation :: Union a a -> SqlSetOperation a' Source #

unionAll_ :: UnionAll_ a => a Source #

`UNION` `ALL` SQL set operation. Can be used as an infix function between `SqlQuery` values.

data UnionAll a b Source #

Deprecated: Since: 3.4.0.0 - Use the `unionAll_` function instead of the `UnionAll` data constructor

Constructors

a `UnionAll` b | Deprecated: Since: 3.4.0.0 - Use the `unionAll_` function instead of the `UnionAll` data constructor

#### Instances

Instances details

ToSqlSetOperation a a' => ToSqlSetOperation (UnionAll a a) a' Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.SqlSetOperation Methods toSqlSetOperation :: UnionAll a a -> SqlSetOperation a' Source #

except_ :: (ToSqlSetOperation a a', ToSqlSetOperation b a') => a -> b -> SqlSetOperation a' Source #

`EXCEPT` SQL set operation. Can be used as an infix function between `SqlQuery` values.

data Except a b Source #

Deprecated: Since: 3.4.0.0 - Use the `except_` function instead of the `Except` data constructor

Constructors

a `Except` b | Deprecated: Since: 3.4.0.0 - Use the `except_` function instead of the `Except` data constructor

#### Instances

Instances details

ToSqlSetOperation a a' => ToSqlSetOperation (Except a a) a' Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.SqlSetOperation Methods toSqlSetOperation :: Except a a -> SqlSetOperation a' Source #

intersect_ :: (ToSqlSetOperation a a', ToSqlSetOperation b a') => a -> b -> SqlSetOperation a' Source #

`INTERSECT` SQL set operation. Can be used as an infix function between `SqlQuery` values.

data Intersect a b Source #

Deprecated: Since: 3.4.0.0 - Use the `intersect_` function instead of the `Intersect` data constructor

Constructors

a `Intersect` b | Deprecated: Since: 3.4.0.0 - Use the `intersect_` function instead of the `Intersect` data constructor

#### Instances

Instances details

ToSqlSetOperation a a' => ToSqlSetOperation (Intersect a a) a' Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.SqlSetOperation Methods toSqlSetOperation :: Intersect a a -> SqlSetOperation a' Source #

pattern SelectQuery :: p -> p Source #

Deprecated: Since: 3.4.0.0 - It is no longer necessary to tag `SqlQuery` values with `SelectQuery`

## Common Table Expressions

with :: (ToAlias a, ToAliasReference a, SqlSelect a r) => SqlQuery a -> SqlQuery (From a) Source #

`WITH` clause used to introduce a Common Table Expression (CTE). CTEs are supported in most modern SQL engines and can be useful in performance tuning. In Esqueleto, CTEs should be used as a subquery memoization tactic. When writing plain SQL, CTEs are sometimes used to organize the SQL code, in Esqueleto, this is better achieved through function that return `SqlQuery` values.

    select $ do
    cte <- with subQuery
    cteResult <- from cte
    where_ $ cteResult ...
    pure cteResult

WARNING: In some SQL engines using a CTE can diminish performance. In these engines the CTE is treated as an optimization fence. You should always verify that using a CTE will in fact improve your performance over a regular subquery.

Notably, in PostgreSQL prior to version 12, CTEs are always fully calculated, which can potentially significantly pessimize queries. As of PostgreSQL 12, non-recursive and side-effect-free queries may be inlined and optimized accordingly if not declared `MATERIALIZED` to get the previous behaviour. See the PostgreSQL CTE documentation, section Materialization, for more information.

Since: 3.4.0.0

withRecursive :: (ToAlias a, ToAliasReference a, SqlSelect a r) => SqlQuery a -> UnionKind -> (From a -> SqlQuery a) -> SqlQuery (From a) Source #

`WITH` `RECURSIVE` allows one to make a recursive subquery, which can reference itself. Like `WITH`, this is supported in most modern SQL engines. Useful for hierarchical, self-referential data, like a tree of data.

    select $ do
    cte <- withRecursive
             (do
                 person <- from $ table @Person
                 where_ $ person ^. PersonId ==. val personId
                 pure person
             )
             unionAll_
             (\self -> do
                 (p :& f :& p2 :& pSelf) <- from self
                          `innerJoin` $ table @Follow
                          `on` (\(p :& f) ->
                                  p ^. PersonId ==. f ^. FollowFollower)
                          `innerJoin` $ table @Person
                          `on` (\(p :& f :& p2) ->
                                  f ^. FollowFollowed ==. p2 ^. PersonId)
                          `leftJoin` self
                          `on` (\(_ :& _ :& p2 :& pSelf) ->
                                  just (p2 ^. PersonId) ==. pSelf ?. PersonId)
                 where_ $ isNothing (pSelf ?. PersonId)
                 groupBy (p2 ^. PersonId)
                 pure p2
             )
    from cte

Since: 3.4.0.0

## Internals

newtype From a Source #

Data type defining the From language. This should not constructed directly in application code.

A `From` is a SqlQuery which returns a reference to the result of calling from and a function that produces a portion of a FROM clause. This gets passed to the FromRaw FromClause constructor directly when converting from a `From` to a `SqlQuery` using `from`

Since: 3.5.0.0

Constructors

From |

Fields

- unFrom :: SqlQuery (a, RawFn)

#### Instances

Instances details

ToFrom (From a) a Source # |
Instance details Defined in Database.Esqueleto.Experimental.From Methods toFrom :: From a -> From a Source #

class ToMaybe a where Source #

Associated Types

type ToMaybeT a Source #

Methods

toMaybe :: a -> ToMaybeT a Source #

#### Instances

Instances details

ToMaybe (SqlExpr (Value a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToMaybe Associated Types type ToMaybeT (SqlExpr (Value a)) Source # Methods toMaybe :: SqlExpr (Value a) -> ToMaybeT (SqlExpr (Value a)) Source #
ToMaybe (SqlExpr (Entity a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToMaybe Associated Types type ToMaybeT (SqlExpr (Entity a)) Source # Methods toMaybe :: SqlExpr (Entity a) -> ToMaybeT (SqlExpr (Entity a)) Source #
ToMaybe (SqlExpr (Maybe a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToMaybe Associated Types type ToMaybeT (SqlExpr (Maybe a)) Source # Methods toMaybe :: SqlExpr (Maybe a) -> ToMaybeT (SqlExpr (Maybe a)) Source #
(ToMaybe a, ToMaybe b) => ToMaybe (a :& b) Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Associated Types type ToMaybeT (a :& b) Source # Methods toMaybe :: (a :& b) -> ToMaybeT (a :& b) Source #
(ToMaybe a, ToMaybe b) => ToMaybe (a, b) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToMaybe Associated Types type ToMaybeT (a, b) Source # Methods toMaybe :: (a, b) -> ToMaybeT (a, b) Source #
(ToMaybe a, ToMaybe b, ToMaybe c) => ToMaybe (a, b, c) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToMaybe Associated Types type ToMaybeT (a, b, c) Source # Methods toMaybe :: (a, b, c) -> ToMaybeT (a, b, c) Source #
(ToMaybe a, ToMaybe b, ToMaybe c, ToMaybe d) => ToMaybe (a, b, c, d) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToMaybe Associated Types type ToMaybeT (a, b, c, d) Source # Methods toMaybe :: (a, b, c, d) -> ToMaybeT (a, b, c, d) Source #
(ToMaybe a, ToMaybe b, ToMaybe c, ToMaybe d, ToMaybe e) => ToMaybe (a, b, c, d, e) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToMaybe Associated Types type ToMaybeT (a, b, c, d, e) Source # Methods toMaybe :: (a, b, c, d, e) -> ToMaybeT (a, b, c, d, e) Source #
(ToMaybe a, ToMaybe b, ToMaybe c, ToMaybe d, ToMaybe e, ToMaybe f) => ToMaybe (a, b, c, d, e, f) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToMaybe Associated Types type ToMaybeT (a, b, c, d, e, f) Source # Methods toMaybe :: (a, b, c, d, e, f) -> ToMaybeT (a, b, c, d, e, f) Source #
(ToMaybe a, ToMaybe b, ToMaybe c, ToMaybe d, ToMaybe e, ToMaybe f, ToMaybe g) => ToMaybe (a, b, c, d, e, f, g) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToMaybe Associated Types type ToMaybeT (a, b, c, d, e, f, g) Source # Methods toMaybe :: (a, b, c, d, e, f, g) -> ToMaybeT (a, b, c, d, e, f, g) Source #
(ToMaybe a, ToMaybe b, ToMaybe c, ToMaybe d, ToMaybe e, ToMaybe f, ToMaybe g, ToMaybe h) => ToMaybe (a, b, c, d, e, f, g, h) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToMaybe Associated Types type ToMaybeT (a, b, c, d, e, f, g, h) Source # Methods toMaybe :: (a, b, c, d, e, f, g, h) -> ToMaybeT (a, b, c, d, e, f, g, h) Source #

class ToAlias a where Source #

Methods

toAlias :: a -> SqlQuery a Source #

#### Instances

Instances details

ToAlias (SqlExpr (Value a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: SqlExpr (Value a) -> SqlQuery (SqlExpr (Value a)) Source #
ToAlias (SqlExpr (Entity a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: SqlExpr (Entity a) -> SqlQuery (SqlExpr (Entity a)) Source #
ToAlias (SqlExpr (Maybe (Entity a))) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: SqlExpr (Maybe (Entity a)) -> SqlQuery (SqlExpr (Maybe (Entity a))) Source #
(ToAlias a, ToAlias b) => ToAlias (a :& b) Source # | Identical to the tuple instance and provided for convenience. Since: 3.5.3.0
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods toAlias :: (a :& b) -> SqlQuery (a :& b) Source #
(ToAlias a, ToAlias b) => ToAlias (a, b) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: (a, b) -> SqlQuery (a, b) Source #
(ToAlias a, ToAlias b, ToAlias c) => ToAlias (a, b, c) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: (a, b, c) -> SqlQuery (a, b, c) Source #
(ToAlias a, ToAlias b, ToAlias c, ToAlias d) => ToAlias (a, b, c, d) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: (a, b, c, d) -> SqlQuery (a, b, c, d) Source #
(ToAlias a, ToAlias b, ToAlias c, ToAlias d, ToAlias e) => ToAlias (a, b, c, d, e) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: (a, b, c, d, e) -> SqlQuery (a, b, c, d, e) Source #
(ToAlias a, ToAlias b, ToAlias c, ToAlias d, ToAlias e, ToAlias f) => ToAlias (a, b, c, d, e, f) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: (a, b, c, d, e, f) -> SqlQuery (a, b, c, d, e, f) Source #
(ToAlias a, ToAlias b, ToAlias c, ToAlias d, ToAlias e, ToAlias f, ToAlias g) => ToAlias (a, b, c, d, e, f, g) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: (a, b, c, d, e, f, g) -> SqlQuery (a, b, c, d, e, f, g) Source #
(ToAlias a, ToAlias b, ToAlias c, ToAlias d, ToAlias e, ToAlias f, ToAlias g, ToAlias h) => ToAlias (a, b, c, d, e, f, g, h) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: (a, b, c, d, e, f, g, h) -> SqlQuery (a, b, c, d, e, f, g, h) Source #
(ToAlias a, ToAlias b, ToAlias c, ToAlias d, ToAlias e, ToAlias f, ToAlias g, ToAlias h, ToAlias i) => ToAlias (a, b, c, d, e, f, g, h, i) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: (a, b, c, d, e, f, g, h, i) -> SqlQuery (a, b, c, d, e, f, g, h, i) Source #
(ToAlias a, ToAlias b, ToAlias c, ToAlias d, ToAlias e, ToAlias f, ToAlias g, ToAlias h, ToAlias i, ToAlias j) => ToAlias (a, b, c, d, e, f, g, h, i, j) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: (a, b, c, d, e, f, g, h, i, j) -> SqlQuery (a, b, c, d, e, f, g, h, i, j) Source #
(ToAlias a, ToAlias b, ToAlias c, ToAlias d, ToAlias e, ToAlias f, ToAlias g, ToAlias h, ToAlias i, ToAlias j, ToAlias k) => ToAlias (a, b, c, d, e, f, g, h, i, j, k) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: (a, b, c, d, e, f, g, h, i, j, k) -> SqlQuery (a, b, c, d, e, f, g, h, i, j, k) Source #
(ToAlias a, ToAlias b, ToAlias c, ToAlias d, ToAlias e, ToAlias f, ToAlias g, ToAlias h, ToAlias i, ToAlias j, ToAlias k, ToAlias l) => ToAlias (a, b, c, d, e, f, g, h, i, j, k, l) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: (a, b, c, d, e, f, g, h, i, j, k, l) -> SqlQuery (a, b, c, d, e, f, g, h, i, j, k, l) Source #
(ToAlias a, ToAlias b, ToAlias c, ToAlias d, ToAlias e, ToAlias f, ToAlias g, ToAlias h, ToAlias i, ToAlias j, ToAlias k, ToAlias l, ToAlias m) => ToAlias (a, b, c, d, e, f, g, h, i, j, k, l, m) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> SqlQuery (a, b, c, d, e, f, g, h, i, j, k, l, m) Source #
(ToAlias a, ToAlias b, ToAlias c, ToAlias d, ToAlias e, ToAlias f, ToAlias g, ToAlias h, ToAlias i, ToAlias j, ToAlias k, ToAlias l, ToAlias m, ToAlias n) => ToAlias (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> SqlQuery (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source #
(ToAlias a, ToAlias b, ToAlias c, ToAlias d, ToAlias e, ToAlias f, ToAlias g, ToAlias h, ToAlias i, ToAlias j, ToAlias k, ToAlias l, ToAlias m, ToAlias n, ToAlias o) => ToAlias (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> SqlQuery (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source #
(ToAlias a, ToAlias b, ToAlias c, ToAlias d, ToAlias e, ToAlias f, ToAlias g, ToAlias h, ToAlias i, ToAlias j, ToAlias k, ToAlias l, ToAlias m, ToAlias n, ToAlias o, ToAlias p) => ToAlias (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) -> SqlQuery (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) Source #

type ToAliasT a = a Source #

Deprecated: This type alias doesn't do anything. Please delete it. Will be removed in the next release.

class ToAliasReference a where Source #

Methods

toAliasReference :: Ident -> a -> SqlQuery a Source #

#### Instances

Instances details

ToAliasReference (SqlExpr (Value a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> SqlExpr (Value a) -> SqlQuery (SqlExpr (Value a)) Source #
ToAliasReference (SqlExpr (Entity a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> SqlExpr (Entity a) -> SqlQuery (SqlExpr (Entity a)) Source #
ToAliasReference (SqlExpr (Maybe (Entity a))) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> SqlExpr (Maybe (Entity a)) -> SqlQuery (SqlExpr (Maybe (Entity a))) Source #
(ToAliasReference a, ToAliasReference b) => ToAliasReference (a :& b) Source # | Identical to the tuple instance and provided for convenience. Since: 3.5.3.0
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods toAliasReference :: Ident -> (a :& b) -> SqlQuery (a :& b) Source #
(ToAliasReference a, ToAliasReference b) => ToAliasReference (a, b) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> (a, b) -> SqlQuery (a, b) Source #
(ToAliasReference a, ToAliasReference b, ToAliasReference c) => ToAliasReference (a, b, c) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> (a, b, c) -> SqlQuery (a, b, c) Source #
(ToAliasReference a, ToAliasReference b, ToAliasReference c, ToAliasReference d) => ToAliasReference (a, b, c, d) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> (a, b, c, d) -> SqlQuery (a, b, c, d) Source #
(ToAliasReference a, ToAliasReference b, ToAliasReference c, ToAliasReference d, ToAliasReference e) => ToAliasReference (a, b, c, d, e) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> (a, b, c, d, e) -> SqlQuery (a, b, c, d, e) Source #
(ToAliasReference a, ToAliasReference b, ToAliasReference c, ToAliasReference d, ToAliasReference e, ToAliasReference f) => ToAliasReference (a, b, c, d, e, f) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> (a, b, c, d, e, f) -> SqlQuery (a, b, c, d, e, f) Source #
(ToAliasReference a, ToAliasReference b, ToAliasReference c, ToAliasReference d, ToAliasReference e, ToAliasReference f, ToAliasReference g) => ToAliasReference (a, b, c, d, e, f, g) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> (a, b, c, d, e, f, g) -> SqlQuery (a, b, c, d, e, f, g) Source #
(ToAliasReference a, ToAliasReference b, ToAliasReference c, ToAliasReference d, ToAliasReference e, ToAliasReference f, ToAliasReference g, ToAliasReference h) => ToAliasReference (a, b, c, d, e, f, g, h) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> (a, b, c, d, e, f, g, h) -> SqlQuery (a, b, c, d, e, f, g, h) Source #
(ToAliasReference a, ToAliasReference b, ToAliasReference c, ToAliasReference d, ToAliasReference e, ToAliasReference f, ToAliasReference g, ToAliasReference h, ToAliasReference i) => ToAliasReference (a, b, c, d, e, f, g, h, i) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> (a, b, c, d, e, f, g, h, i) -> SqlQuery (a, b, c, d, e, f, g, h, i) Source #
(ToAliasReference a, ToAliasReference b, ToAliasReference c, ToAliasReference d, ToAliasReference e, ToAliasReference f, ToAliasReference g, ToAliasReference h, ToAliasReference i, ToAliasReference j) => ToAliasReference (a, b, c, d, e, f, g, h, i, j) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> (a, b, c, d, e, f, g, h, i, j) -> SqlQuery (a, b, c, d, e, f, g, h, i, j) Source #
(ToAliasReference a, ToAliasReference b, ToAliasReference c, ToAliasReference d, ToAliasReference e, ToAliasReference f, ToAliasReference g, ToAliasReference h, ToAliasReference i, ToAliasReference j, ToAliasReference k) => ToAliasReference (a, b, c, d, e, f, g, h, i, j, k) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> (a, b, c, d, e, f, g, h, i, j, k) -> SqlQuery (a, b, c, d, e, f, g, h, i, j, k) Source #
(ToAliasReference a, ToAliasReference b, ToAliasReference c, ToAliasReference d, ToAliasReference e, ToAliasReference f, ToAliasReference g, ToAliasReference h, ToAliasReference i, ToAliasReference j, ToAliasReference k, ToAliasReference l) => ToAliasReference (a, b, c, d, e, f, g, h, i, j, k, l) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> (a, b, c, d, e, f, g, h, i, j, k, l) -> SqlQuery (a, b, c, d, e, f, g, h, i, j, k, l) Source #
(ToAliasReference a, ToAliasReference b, ToAliasReference c, ToAliasReference d, ToAliasReference e, ToAliasReference f, ToAliasReference g, ToAliasReference h, ToAliasReference i, ToAliasReference j, ToAliasReference k, ToAliasReference l, ToAliasReference m) => ToAliasReference (a, b, c, d, e, f, g, h, i, j, k, l, m) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> SqlQuery (a, b, c, d, e, f, g, h, i, j, k, l, m) Source #
(ToAliasReference a, ToAliasReference b, ToAliasReference c, ToAliasReference d, ToAliasReference e, ToAliasReference f, ToAliasReference g, ToAliasReference h, ToAliasReference i, ToAliasReference j, ToAliasReference k, ToAliasReference l, ToAliasReference m, ToAliasReference n) => ToAliasReference (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> SqlQuery (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source #
(ToAliasReference a, ToAliasReference b, ToAliasReference c, ToAliasReference d, ToAliasReference e, ToAliasReference f, ToAliasReference g, ToAliasReference h, ToAliasReference i, ToAliasReference j, ToAliasReference k, ToAliasReference l, ToAliasReference m, ToAliasReference n, ToAliasReference o) => ToAliasReference (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> SqlQuery (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source #
(ToAliasReference a, ToAliasReference b, ToAliasReference c, ToAliasReference d, ToAliasReference e, ToAliasReference f, ToAliasReference g, ToAliasReference h, ToAliasReference i, ToAliasReference j, ToAliasReference k, ToAliasReference l, ToAliasReference m, ToAliasReference n, ToAliasReference o, ToAliasReference p) => ToAliasReference (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) -> SqlQuery (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) Source #

type ToAliasReferenceT a = a Source #

Deprecated: This type alias doesn't do anything. Please delete it. Will be removed in the next release.

class ToSqlSetOperation a r | a -> r where Source #

Type class to support direct use of `SqlQuery` in a set operation tree

Since: 3.5.0.0

Methods

toSqlSetOperation :: a -> SqlSetOperation r Source #

#### Instances

Instances details

ToSqlSetOperation (SqlSetOperation a) a Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.SqlSetOperation Methods toSqlSetOperation :: SqlSetOperation a -> SqlSetOperation a Source #
(SqlSelect a r, ToAlias a, ToAliasReference a) => ToSqlSetOperation (SqlQuery a) a Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.SqlSetOperation Methods toSqlSetOperation :: SqlQuery a -> SqlSetOperation a Source #
ToSqlSetOperation a a' => ToSqlSetOperation (Except a a) a' Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.SqlSetOperation Methods toSqlSetOperation :: Except a a -> SqlSetOperation a' Source #
ToSqlSetOperation a a' => ToSqlSetOperation (Intersect a a) a' Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.SqlSetOperation Methods toSqlSetOperation :: Intersect a a -> SqlSetOperation a' Source #
ToSqlSetOperation a a' => ToSqlSetOperation (Union a a) a' Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.SqlSetOperation Methods toSqlSetOperation :: Union a a -> SqlSetOperation a' Source #
ToSqlSetOperation a a' => ToSqlSetOperation (UnionAll a a) a' Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.SqlSetOperation Methods toSqlSetOperation :: UnionAll a a -> SqlSetOperation a' Source #

# The Normal Stuff

where_ :: SqlExpr (Value Bool) -> SqlQuery () Source #

`WHERE` clause: restrict the query's result.

groupBy :: ToSomeValues a => a -> SqlQuery () Source #

`GROUP BY` clause. You can enclose multiple columns in a tuple.

    select $ from \(foo `InnerJoin` bar) -> do
      on (foo ^. FooBarId ==. bar ^. BarId)
      groupBy (bar ^. BarId, bar ^. BarName)
      return (bar ^. BarId, bar ^. BarName, countRows)

With groupBy you can sort by aggregate functions, like so (we used `let` to restrict the more general `countRows` to `SqlSqlExpr (Value Int)` to avoid ambiguity---the second use of `countRows` has its type restricted by the `:: Int` below):

    r <- select $ from \(foo `InnerJoin` bar) -> do
      on (foo ^. FooBarId ==. bar ^. BarId)
      groupBy $ bar ^. BarName
      let countRows' = countRows
      orderBy [asc countRows']
      return (bar ^. BarName, countRows')
    forM_ r $ \(Value name, Value count) -> do
      print name
      print (count :: Int)

### Need more columns?

The `ToSomeValues` class is defined for `SqlExpr` and tuples of `SqlExpr`s. We only have definitions for up to 8 elements in a tuple right now, so it's possible that you may need to have more than 8 elements.

For example, consider a query with a `groupBy` call like this:

    groupBy (e0, e1, e2, e3, e4, e5, e6, e7)

This is the biggest you can get with a single tuple. However, you can easily nest the tuples to add more:

    groupBy ((e0, e1, e2, e3, e4, e5, e6, e7), e8, e9)

groupBy_ :: ToSomeValues a => a -> SqlQuery () Source #

An alias for `groupBy` that avoids conflict with the term from Data.List `groupBy`.

Since: 3.5.10.0

orderBy :: [SqlExpr OrderBy] -> SqlQuery () Source #

`ORDER BY` clause. See also `asc` and `desc`.

Multiple calls to `orderBy` get concatenated on the final query, including `distinctOnOrderBy`.

rand :: SqlExpr OrderBy Source #

Deprecated: Since 2.6.0: `rand` ordering function is not uniform across all databases! To avoid accidental partiality it will be removed in the next major version.

`ORDER BY random()` clause.

Since: 1.3.10

asc :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy Source #

Ascending order of this field or SqlExpression.

desc :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy Source #

Descending order of this field or SqlExpression.

limit :: Int64 -> SqlQuery () Source #

`LIMIT`. Limit the number of returned rows.

offset :: Int64 -> SqlQuery () Source #

`OFFSET`. Usually used with `limit`.

distinct :: SqlQuery a -> SqlQuery a Source #

`DISTINCT`. Change the current `SELECT` into `SELECT DISTINCT`. For example:

    select $ distinct $
      from \foo -> do
      ...

Note that this also has the same effect:

    select $
      from \foo -> do
      distinct (return ())
      ...

Since: 2.2.4

distinctOn :: [SqlExpr DistinctOn] -> SqlQuery a -> SqlQuery a Source #

`DISTINCT ON`. Change the current `SELECT` into `SELECT DISTINCT ON (SqlExpressions)`. For example:

    select $
      from \foo ->
      distinctOn [don (foo ^. FooName), don (foo ^. FooState)] $ do
      ...

You can also chain different calls to `distinctOn`. The above is equivalent to:

    select $
      from \foo ->
      distinctOn [don (foo ^. FooName)] $
      distinctOn [don (foo ^. FooState)] $ do
      ...

Each call to `distinctOn` adds more SqlExpressions. Calls to `distinctOn` override any calls to `distinct`.

Note that PostgreSQL requires the SqlExpressions on `DISTINCT ON` to be the first ones to appear on a `ORDER BY`. This is not managed automatically by esqueleto, keeping its spirit of trying to be close to raw SQL.

Supported by PostgreSQL only.

Since: 2.2.4

don :: SqlExpr (Value a) -> SqlExpr DistinctOn Source #

Erase an SqlExpression's type so that it's suitable to be used by `distinctOn`.

Since: 2.2.4

distinctOnOrderBy :: [SqlExpr OrderBy] -> SqlQuery a -> SqlQuery a Source #

A convenience function that calls both `distinctOn` and `orderBy`. In other words,

    distinctOnOrderBy [asc foo, desc bar, desc quux] $ do
      ...

is the same as:

    distinctOn [don foo, don  bar, don  quux] $ do
      orderBy  [asc foo, desc bar, desc quux]
      ...

Since: 2.2.4

having :: SqlExpr (Value Bool) -> SqlQuery () Source #

`HAVING`.

Since: 1.2.2

locking :: LockingKind -> SqlQuery () Source #

Add a locking clause to the query. Please read `LockingKind` documentation and your RDBMS manual. Unsafe since not all locking clauses are implemented for every RDBMS

If multiple calls to `locking` are made on the same query, the last one is used.

Since: 2.2.7

sub_select :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a) Source #

Deprecated: sub_select sub_select is an unsafe function to use. If used with a SqlQuery that returns 0 results, then it may return NULL despite not mentioning Maybe in the return type. If it returns more than 1 result, then it will throw a SQL error. Instead, consider using one of the following alternatives: - subSelect: attaches a LIMIT 1 and the Maybe return type, totally safe. - subSelectMaybe: Attaches a LIMIT 1, useful for a query that already has a Maybe in the return type. - subSelectCount: Performs a count of the query - this is always safe. - subSelectUnsafe: Performs no checks or guarantees. Safe to use with countRows and friends.

Execute a subquery `SELECT` in an SqlExpression. Returns a simple value so should be used only when the `SELECT` query is guaranteed to return just one row.

Deprecated in 3.2.0.

(^.) :: forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ) infixl 9 Source #

Project a field of an entity.

(?.) :: (PersistEntity val, PersistField typ) => SqlExpr (Maybe (Entity val)) -> EntityField val typ -> SqlExpr (Value (Maybe typ)) Source #

Project a field of an entity that may be null.

val :: PersistField typ => typ -> SqlExpr (Value typ) Source #

Lift a constant value from Haskell-land to the query.

isNothing :: PersistField typ => SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool) Source #

`IS NULL` comparison.

For `IS NOT NULL`, you can negate this with `not_`, as in `not_ (isNothing (person ^. PersonAge))`

Warning: Persistent and Esqueleto have different behavior for `!= Nothing`:

| Haskell | SQL
--- | --- | ---
Persistent | ``!=.` Nothing` | `IS NOT NULL`
Esqueleto | ``!=.` Nothing` | `!= NULL`

In SQL, `= NULL` and `!= NULL` return NULL instead of true or false. For this reason, you very likely do not want to use ``!=.` Nothing` in Esqueleto. You may find these `hlint` rules helpful to enforce this:

    - error: {lhs: v Database.Esqueleto.==. Database.Esqueleto.nothing, rhs: Database.Esqueleto.isNothing v, name: Use Esqueleto's isNothing}
    - error: {lhs: v Database.Esqueleto.==. Database.Esqueleto.val Nothing, rhs: Database.Esqueleto.isNothing v, name: Use Esqueleto's isNothing}
    - error: {lhs: v Database.Esqueleto.!=. Database.Esqueleto.nothing, rhs: not_ (Database.Esqueleto.isNothing v), name: Use Esqueleto's not isNothing}
    - error: {lhs: v Database.Esqueleto.!=. Database.Esqueleto.val Nothing, rhs: not_ (Database.Esqueleto.isNothing v), name: Use Esqueleto's not isNothing}

isNothing_ :: PersistField typ => SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool) Source #

An alias for `isNothing` that avoids clashing with the function from Data.Maybe `isNothing`.

Since: 3.5.10.0

just :: SqlExpr (Value typ) -> SqlExpr (Value (Maybe typ)) Source #

Analogous to `Just`, promotes a value of type `typ` into one of type `Maybe typ`. It should hold that ``val` . Just === just . `val``.

nothing :: SqlExpr (Value (Maybe typ)) Source #

`NULL` value.

joinV :: SqlExpr (Value (Maybe (Maybe typ))) -> SqlExpr (Value (Maybe typ)) Source #

Join nested `Maybe`s in a `Value` into one. This is useful when calling aggregate functions on nullable fields.

withNonNull :: PersistField typ => SqlExpr (Value (Maybe typ)) -> (SqlExpr (Value typ) -> SqlQuery a) -> SqlQuery a Source #

Project an SqlExpression that may be null, guarding against null cases.

countRows :: Num a => SqlExpr (Value a) Source #

`COUNT(*)` value.

count :: Num a => SqlExpr (Value typ) -> SqlExpr (Value a) Source #

`COUNT`.

countDistinct :: Num a => SqlExpr (Value typ) -> SqlExpr (Value a) Source #

`COUNT(DISTINCT x)`.

Since: 2.4.1

not_ :: SqlExpr (Value Bool) -> SqlExpr (Value Bool) Source #

(==.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) infix 4 Source #

(>=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) infix 4 Source #

(>.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) infix 4 Source #

(<=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) infix 4 Source #

(<.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) infix 4 Source #

(!=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) infix 4 Source #

(&&.) :: SqlExpr (Value Bool) -> SqlExpr (Value Bool) -> SqlExpr (Value Bool) infixr 3 Source #

(||.) :: SqlExpr (Value Bool) -> SqlExpr (Value Bool) -> SqlExpr (Value Bool) infixr 2 Source #

between :: PersistField a => SqlExpr (Value a) -> (SqlExpr (Value a), SqlExpr (Value a)) -> SqlExpr (Value Bool) Source #

`BETWEEN`.

@since: 3.1.0

(+.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a) infixl 6 Source #

(-.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a) infixl 6 Source #

(/.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a) infixl 7 Source #

(*.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a) infixl 7 Source #

random_ :: (PersistField a, Num a) => SqlExpr (Value a) Source #

Deprecated: Since 2.6.0: `random_` is not uniform across all databases! Please use a specific one such as `random_`, `random_`, or `random_`

round_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b) Source #

ceiling_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b) Source #

floor_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b) Source #

min_ :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value (Maybe a)) Source #

max_ :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value (Maybe a)) Source #

sum_ :: (PersistField a, PersistField b) => SqlExpr (Value a) -> SqlExpr (Value (Maybe b)) Source #

avg_ :: (PersistField a, PersistField b) => SqlExpr (Value a) -> SqlExpr (Value (Maybe b)) Source #

castNum :: (Num a, Num b) => SqlExpr (Value a) -> SqlExpr (Value b) Source #

Allow a number of one type to be used as one of another type via an implicit cast. An explicit cast is not made, this function changes only the types on the Haskell side.

Caveat: Trying to use `castNum` from `Double` to `Int` will not result in an integer, the original fractional number will still be used! Use `round_`, `ceiling_` or `floor_` instead.

Safety: This operation is mostly safe due to the `Num` constraint between the types and the fact that RDBMSs usually allow numbers of different types to be used interchangeably. However, there may still be issues with the query not being accepted by the RDBMS or `persistent` not being able to parse it.

Since: 2.2.9

castNumM :: (Num a, Num b) => SqlExpr (Value (Maybe a)) -> SqlExpr (Value (Maybe b)) Source #

Same as `castNum`, but for nullable values.

Since: 2.2.9

coalesce :: PersistField a => [SqlExpr (Value (Maybe a))] -> SqlExpr (Value (Maybe a)) Source #

`COALESCE` function. Evaluates the arguments in order and returns the value of the first non-NULL SqlExpression, or NULL (Nothing) otherwise. Some RDBMSs (such as SQLite) require at least two arguments; please refer to the appropriate documentation.

Since: 1.4.3

coalesceDefault :: PersistField a => [SqlExpr (Value (Maybe a))] -> SqlExpr (Value a) -> SqlExpr (Value a) Source #

Like `coalesce`, but takes a non-nullable SqlExpression placed at the end of the SqlExpression list, which guarantees a non-NULL result.

Since: 1.4.3

lower_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) Source #

`LOWER` function.

upper_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) Source #

`UPPER` function. @since 3.3.0

trim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) Source #

`TRIM` function. @since 3.3.0

ltrim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) Source #

`LTRIM` function. @since 3.3.0

rtrim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) Source #

`RTRIM` function. @since 3.3.0

length_ :: (SqlString s, Num a) => SqlExpr (Value s) -> SqlExpr (Value a) Source #

`LENGTH` function. @since 3.3.0

left_ :: (SqlString s, Num a) => (SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s) Source #

`LEFT` function. @since 3.3.0

right_ :: (SqlString s, Num a) => (SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s) Source #

`RIGHT` function. @since 3.3.0

like :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool) infixr 2 Source #

`LIKE` operator.

ilike :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool) infixr 2 Source #

`ILIKE` operator (case-insensitive `LIKE`).

Supported by PostgreSQL only.

Since: 2.2.3

(%) :: SqlString s => SqlExpr (Value s) Source #

The string ``%``. May be useful while using `like` and concatenation (`concat_` or `++.`, depending on your database). Note that you always have to type the parenthesis, for example:

    name `like` (%) ++. val "John" ++. (%)

concat_ :: SqlString s => [SqlExpr (Value s)] -> SqlExpr (Value s) Source #

The `CONCAT` function with a variable number of parameters. Supported by MySQL and PostgreSQL.

(++.) :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value s) infixr 5 Source #

The `||` string concatenation operator (named after Haskell's `++` in order to avoid naming clash with `||.`). Supported by SQLite and PostgreSQL.

castString :: (SqlString s, SqlString r) => SqlExpr (Value s) -> SqlExpr (Value r) Source #

Cast a string type into `Text`. This function is very useful if you want to use `newtype`s, or if you want to apply functions such as `like` to strings of different types.

Safety: This is a slightly unsafe function, especially if you have defined your own instances of `SqlString`. Also, since `Maybe` is an instance of `SqlString`, it's possible to turn a nullable value into a non-nullable one. Avoid using this function if possible.

subList_select :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (ValueList a) Source #

Execute a subquery `SELECT` in an SqlExpression. Returns a list of values.

valList :: PersistField typ => [typ] -> SqlExpr (ValueList typ) Source #

Lift a list of constant value from Haskell-land to the query.

justList :: SqlExpr (ValueList typ) -> SqlExpr (ValueList (Maybe typ)) Source #

Same as `just` but for `ValueList`. Most of the time you won't need it, though, because you can use `just` from inside `subList_select` or `Just` from inside `valList`.

Since: 2.2.12

in_ :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (ValueList typ) -> SqlExpr (Value Bool) Source #

`IN` operator. For example if you want to select all `Person`s by a list of IDs:

    SELECT *
    FROM Person
    WHERE Person.id IN (?)

In `esqueleto`, we may write the same query above as:

    select $
    from $ \person -> do
    where_ $ person ^. PersonId `in_` valList personIds
    return person

Where `personIds` is of type `[Key Person]`.

notIn :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (ValueList typ) -> SqlExpr (Value Bool) Source #

`NOT IN` operator.

exists :: SqlQuery () -> SqlExpr (Value Bool) Source #

`EXISTS` operator. For example:

    select $
    from $ \person -> do
    where_ $ exists $
             from $ \post -> do
             where_ (post ^. BlogPostAuthorId ==. person ^. PersonId)
    return person

notExists :: SqlQuery () -> SqlExpr (Value Bool) Source #

`NOT EXISTS` operator.

set :: PersistEntity val => SqlExpr (Entity val) -> [SqlExpr (Entity val) -> SqlExpr Update] -> SqlQuery () Source #

`SET` clause used on `UPDATE`s. Note that while it's not a type error to use this function on a `SELECT`, it will most certainly result in a runtime error.

(=.) :: (PersistEntity val, PersistField typ) => EntityField val typ -> SqlExpr (Value typ) -> SqlExpr (Entity val) -> SqlExpr Update infixr 3 Source #

(+=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Entity val) -> SqlExpr Update infixr 3 Source #

(-=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Entity val) -> SqlExpr Update infixr 3 Source #

(*=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Entity val) -> SqlExpr Update infixr 3 Source #

(/=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> SqlExpr (Entity val) -> SqlExpr Update infixr 3 Source #

case_ :: PersistField a => [(SqlExpr (Value Bool), SqlExpr (Value a))] -> SqlExpr (Value a) -> SqlExpr (Value a) Source #

`CASE` statement. For example:

    select $
    return $
    case_
       [ when_
           (exists $
           from $ \p -> do
           where_ (p ^. PersonName ==. val "Mike"))
         then_
           (sub_select $
           from $ \v -> do
           let sub =
                   from $ \c -> do
                   where_ (c ^. PersonName ==. val "Mike")
                   return (c ^. PersonFavNum)
           where_ (v ^. PersonFavNum >. sub_select sub)
           return $ count (v ^. PersonName) +. val (1 :: Int)) ]
       (else_ $ val (-1))

This query is a bit complicated, but basically it checks if a person named `"Mike"` exists, and if that person does, run the subquery to find out how many people have a ranking (by Fav Num) higher than `"Mike"`.

NOTE: There are a few things to be aware about this statement.

- This only implements the full CASE statement, it does not implement the "simple" CASE statement.
- At least one `when_` and `then_` is mandatory otherwise it will emit an error.
- The `else_` is also mandatory, unlike the SQL statement in which if the `ELSE` is omitted it will return a `NULL`. You can reproduce this via `nothing`.

Since: 2.1.2

toBaseId :: ToBaseId ent => SqlExpr (Value (Key ent)) -> SqlExpr (Value (Key (BaseEnt ent))) Source #

Convert an entity's key into another entity's.

This function is to be used when you change an entity's `Id` to be that of another entity. For example:

    Bar
      barNum Int
    Foo
      bar BarId
      fooNum Int
      Primary bar

In this example, Bar is said to be the BaseEnt(ity), and Foo the child. To model this in Esqueleto, declare:

    instance ToBaseId Foo where
      type BaseEnt Foo = Bar
      toBaseIdWitness barId = FooKey barId

Now you're able to write queries such as:

    select $
    from $ (bar `InnerJoin` foo) -> do
    on (toBaseId (foo ^. FooId) ==. bar ^. BarId)
    return (bar, foo)

Note: this function may be unsafe to use in conditions not like the one of the example above.

Since: 2.4.3

subSelect :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value (Maybe a)) Source #

Execute a subquery `SELECT` in a `SqlExpr`. The query passed to this function will only return a single result - it has a `LIMIT 1` passed in to the query to make it safe, and the return type is `Maybe` to indicate that the subquery might result in 0 rows.

If you find yourself writing ``joinV` . `subSelect``, then consider using `subSelectMaybe`.

If you're performing a `countRows`, then you can use `subSelectCount` which is safe.

If you know that the subquery will always return exactly one row (eg a foreign key constraint guarantees that you'll get exactly one row), then consider `subSelectUnsafe`, along with a comment explaining why it is safe.

Since: 3.2.0

subSelectMaybe :: PersistField a => SqlQuery (SqlExpr (Value (Maybe a))) -> SqlExpr (Value (Maybe a)) Source #

Execute a subquery `SELECT` in a `SqlExpr`. This function is a shorthand for the common ``joinV` . `subSelect`` idiom, where you are calling `subSelect` on an expression that would be `Maybe` already.

As an example, you would use this function when calling `sum_` or `max_`, which have `Maybe` in the result type (for a 0 row query).

Since: 3.2.0

subSelectCount :: (Num a, PersistField a) => SqlQuery ignored -> SqlExpr (Value a) Source #

Performs a `COUNT` of the given query in a `subSelect` manner. This is always guaranteed to return a result value, and is completely safe.

Since: 3.2.0

subSelectForeign Source #

Arguments

:: (BackendCompatible SqlBackend (PersistEntityBackend val1), PersistEntity val1, PersistEntity val2, PersistField a) |
=> SqlExpr (Entity val2) | An expression representing the table you have access to now.
-> EntityField val2 (Key val1) | The foreign key field on the table.
-> (SqlExpr (Entity val1) -> SqlExpr (Value a)) | A function to extract a value from the foreign reference table.
-> SqlExpr (Value a) |

Performs a sub-select using the given foreign key on the entity. This is useful to extract values that are known to be present by the database schema.

As an example, consider the following persistent definition:

    User
      profile ProfileId

    Profile
      name    Text

The following query will return the name of the user.

    getUserWithName =
        select $
        from $ user ->
        pure (user, subSelectForeign user UserProfile (^. ProfileName)

Since: 3.2.0

subSelectList :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (ValueList a) Source #

Execute a subquery `SELECT` in a `SqlExpr` that returns a list. This is an alias for `subList_select` and is provided for symmetry with the other safe subselect functions.

Since: 3.2.0

subSelectUnsafe :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a) Source #

Execute a subquery `SELECT` in a `SqlExpr`. This function is unsafe, because it can throw runtime exceptions in two cases:

1. If the query passed has 0 result rows, then it will return a `NULL` value. The `persistent` parsing operations will fail on an unexpected `NULL`.
2. If the query passed returns more than one row, then the SQL engine will fail with an error like "More than one row returned by a subquery used as an expression".

This function is safe if you guarantee that exactly one row will be returned, or if the result already has a `Maybe` type for some reason.

For variants with the safety encoded already, see `subSelect` and `subSelectMaybe`. For the most common safe use of this, see `subSelectCount`.

Since: 3.2.0

class ToBaseId ent where Source #

Class that enables one to use `toBaseId` to convert an entity's key on a query into another (cf. `toBaseId`).

Associated Types

type BaseEnt ent :: Type Source #

e.g. `type BaseEnt MyBase = MyChild`

Methods

toBaseIdWitness :: Key (BaseEnt ent) -> Key ent Source #

Convert from the key of the BaseEnt(ity) to the key of the child entity. This function is not actually called, but that it typechecks proves this operation is safe.

when_ :: expr (Value Bool) -> () -> expr a -> (expr (Value Bool), expr a) Source #

Syntax sugar for `case_`.

Since: 2.1.2

then_ :: () Source #

Syntax sugar for `case_`.

Since: 2.1.2

else_ :: expr a -> expr a Source #

Syntax sugar for `case_`.

Since: 2.1.2

newtype Value a Source #

A single value (as opposed to a whole entity). You may use `(`^.`)` or `(`?.`)` to get a `Value` from an `Entity`.

Constructors

Value |

Fields

- unValue :: a

#### Instances

Instances details

Applicative Value Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods pure :: a -> Value a Source # (<*>) :: Value (a -> b) -> Value a -> Value b Source # liftA2 :: (a -> b -> c) -> Value a -> Value b -> Value c Source # (*>) :: Value a -> Value b -> Value b Source # (<*) :: Value a -> Value b -> Value a Source #
Functor Value Source # | Since: 1.4.4
Instance details Defined in Database.Esqueleto.Internal.Internal Methods fmap :: (a -> b) -> Value a -> Value b Source # (<$) :: a -> Value b -> Value a Source #
Monad Value Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods (>>=) :: Value a -> (a -> Value b) -> Value b Source # (>>) :: Value a -> Value b -> Value b Source # return :: a -> Value a Source #

(PersistEntity rec, PersistField typ, SymbolToField sym rec typ) => HasField (sym :: Symbol) (SqlExpr (Entity rec)) (SqlExpr (Value typ)) Source #

This instance allows you to use `record.field` notation with GHC 9.2's `OverloadedRecordDot` extension.

Example:

    -- persistent model:
    BlogPost
        authorId     PersonId
        title        Text

    -- query:
    select $ do
        bp <- from $ table @BlogPost
        pure $ bp.title

This is exactly equivalent to the following:

    blogPost :: SqlExpr (Entity BlogPost)

    blogPost ^. BlogPostTitle
    blogPost ^. #title
    blogPost.title

There's another instance defined on ``SqlExpr` (`Entity` (`Maybe` rec))`, which allows you to project from a `LEFT JOIN`ed entity.

Since: 3.5.4.0

Instance details Defined in Database.Esqueleto.Internal.Internal Methods getField :: SqlExpr (Entity rec) -> SqlExpr (Value typ) Source #

(PersistEntity rec, PersistField typ, SymbolToField sym rec typ) => HasField (sym :: Symbol) (SqlExpr (Maybe (Entity rec))) (SqlExpr (Value (Maybe typ))) Source #

This instance allows you to use `record.field` notation with GC 9.2's `OverloadedRecordDot` extension.

Example:

    -- persistent model:
    Person
        name         Text

    BlogPost
        title        Text
        authorId     PersonId

    -- query:

    select $ do
        (p :& bp) <- from $
            table Person
            leftJoin table BlogPost
            on do
                \(p :& bp) ->
                    just p.id ==. bp.authorId
        pure (p.name, bp.title)

The following forms are all equivalent:

    blogPost :: SqlExpr (Maybe (Entity BlogPost))

    blogPost ?. BlogPostTitle
    blogPost ?. #title
    blogPost.title

Since: 3.5.4.0

Instance details Defined in Database.Esqueleto.Internal.Internal Methods getField :: SqlExpr (Maybe (Entity rec)) -> SqlExpr (Value (Maybe typ)) Source #
(ToFrom a a', SqlSelect b r, ToAlias b, ToAliasReference b, d ~ (a' :& b)) => DoInnerJoin Lateral a (a' -> SqlQuery b, d -> SqlExpr (Value Bool)) d Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods doInnerJoin :: Proxy Lateral -> a -> (a' -> SqlQuery b, d -> SqlExpr (Value Bool)) -> From d Source #
(ToFrom a a', ToMaybe b, d ~ (a' :& ToMaybeT b), SqlSelect b r, ToAlias b, ToAliasReference b) => DoLeftJoin Lateral a (a' -> SqlQuery b, d -> SqlExpr (Value Bool)) d Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods doLeftJoin :: Proxy Lateral -> a -> (a' -> SqlQuery b, d -> SqlExpr (Value Bool)) -> From d Source #
Show a => Show (Value a) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods showsPrec :: Int -> Value a -> ShowS Source # show :: Value a -> String Source # showList :: [Value a] -> ShowS Source #
ToAlias (SqlExpr (Value a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: SqlExpr (Value a) -> SqlQuery (SqlExpr (Value a)) Source #
ToAliasReference (SqlExpr (Value a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> SqlExpr (Value a) -> SqlQuery (SqlExpr (Value a)) Source #
ToMaybe (SqlExpr (Value a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToMaybe Associated Types type ToMaybeT (SqlExpr (Value a)) Source # Methods toMaybe :: SqlExpr (Value a) -> ToMaybeT (SqlExpr (Value a)) Source #
ToSomeValues (SqlExpr (Value a)) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods toSomeValues :: SqlExpr (Value a) -> [SomeValue] Source #
Eq a => Eq (Value a) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods (==) :: Value a -> Value a -> Bool Source # (/=) :: Value a -> Value a -> Bool Source #
Ord a => Ord (Value a) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods compare :: Value a -> Value a -> Ordering Source # (<) :: Value a -> Value a -> Bool Source # (<=) :: Value a -> Value a -> Bool Source # (>) :: Value a -> Value a -> Bool Source # (>=) :: Value a -> Value a -> Bool Source # max :: Value a -> Value a -> Value a Source # min :: Value a -> Value a -> Value a Source #
PersistField a => SqlSelect (SqlExpr (Value a)) (Value a) Source # | You may return any single value (i.e. a single column) from a `select` query.
Instance details Defined in Database.Esqueleto.Internal.Internal Methods sqlSelectCols :: IdentInfo -> SqlExpr (Value a) -> (Builder, [PersistValue]) Source # sqlSelectColCount :: Proxy (SqlExpr (Value a)) -> Int Source # sqlSelectProcessRow :: [PersistValue] -> Either Text (Value a) Source # sqlInsertInto :: IdentInfo -> SqlExpr (Value a) -> (Builder, [PersistValue]) Source #
type ToMaybeT (SqlExpr (Value a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToMaybe type ToMaybeT (SqlExpr (Value a)) = SqlExpr (Value (Maybe (Nullable a)))

newtype ValueList a Source #

A list of single values. There's a limited set of functions able to work with this data type (such as `subList_select`, `valList`, `in_` and `exists`).

Constructors

ValueList a |

#### Instances

Instances details

Show a => Show (ValueList a) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods showsPrec :: Int -> ValueList a -> ShowS Source # show :: ValueList a -> String Source # showList :: [ValueList a] -> ShowS Source #
Eq a => Eq (ValueList a) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods (==) :: ValueList a -> ValueList a -> Bool Source # (/=) :: ValueList a -> ValueList a -> Bool Source #
Ord a => Ord (ValueList a) Source # |

Instance details

Defined in Database.Esqueleto.Internal.Internal

Methods

compare :: ValueList a -> ValueList a -> Ordering Source #

(<) :: ValueList a -> ValueList a -> Bool Source #

(<=) :: ValueList a -> ValueList a -> Bool Source #

(>) :: ValueList a -> ValueList a -> Bool Source #

(>=) :: ValueList a -> ValueList a -> Bool Source #

max :: ValueList a -> ValueList a -> ValueList a Source #

min :: ValueList a -> ValueList a -> ValueList a Source #

data OrderBy Source #

Phantom type used by `orderBy`, `asc` and `desc`.

data DistinctOn Source #

Phantom type used by `distinctOn` and `don`.

data LockingKind Source #

Different kinds of locking clauses supported by `locking`.

Note that each RDBMS has different locking support. The constructors of this datatype specify only the syntax of the locking mechanism, not its semantics. For example, even though both MySQL and PostgreSQL support `ForUpdate`, there are no guarantees that they will behave the same.

Since: 2.2.7

Constructors

ForUpdate | `FOR UPDATE` syntax. Supported by MySQL, Oracle and PostgreSQL. Since: 2.2.7
ForUpdateSkipLocked | `FOR UPDATE SKIP LOCKED` syntax. Supported by MySQL, Oracle and PostgreSQL. Since: 2.2.7
ForShare | `FOR SHARE` syntax. Supported by PostgreSQL. Since: 2.2.7
LockInShareMode | `LOCK IN SHARE MODE` syntax. Supported by MySQL. Since: 2.2.7

class LockableEntity a where Source #

Lockable entity

Example use:

    select $ do
        (p :& bp) <- from $
            table Person
            innerJoin table BlogPost
                on do
                    (p :& bp) -> p ^. PersonId ==. b ^. BlogPostAuthorId
        forUpdateOf (p :& b) skipLocked
        return p

Methods

flattenLockableEntity :: a -> NonEmpty LockableSqlExpr Source #

#### Instances

Instances details

PersistEntity val => LockableEntity (SqlExpr (Entity val)) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods flattenLockableEntity :: SqlExpr (Entity val) -> NonEmpty LockableSqlExpr Source #
(LockableEntity a, LockableEntity b) => LockableEntity (a :& b) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods flattenLockableEntity :: (a :& b) -> NonEmpty LockableSqlExpr Source #

class PersistField a => SqlString a Source #

Phantom class of data types that are treated as strings by the RDBMS. It has no methods because it's only used to avoid type errors such as trying to concatenate integers.

If you have a custom data type or `newtype`, feel free to make it an instance of this class.

Since: 2.4.0

#### Instances

Instances details

SqlString Html Source # | Since: 2.3.0
Instance details Defined in Database.Esqueleto.Internal.Internal
SqlString ByteString Source # | Since: 2.3.0
Instance details Defined in Database.Esqueleto.Internal.Internal
SqlString Text Source # | Since: 2.3.0
Instance details Defined in Database.Esqueleto.Internal.Internal
SqlString Text Source # | Since: 2.3.0
Instance details Defined in Database.Esqueleto.Internal.Internal
SqlString a => SqlString (Maybe a) Source # | Since: 2.4.0
Instance details Defined in Database.Esqueleto.Internal.Internal
a ~ Char => SqlString [a] Source # | Since: 2.3.0
Instance details Defined in Database.Esqueleto.Internal.Internal

## Joins

data InnerJoin a b infixl 2 Source #

Data type that represents an `INNER JOIN` (see `LeftOuterJoin` for an example).

Constructors

a `InnerJoin` b infixl 2 |

#### Instances

Instances details

IsJoinKind InnerJoin Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods smartJoin :: a -> b -> InnerJoin a b Source # reifyJoinKind :: InnerJoin a b -> JoinKind Source #
FromPreprocess (InnerJoin a b) => From (InnerJoin a b) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods from_ :: SqlQuery (InnerJoin a b) Source #
(DoInnerJoin lateral lhs rhs r, lateral ~ IsLateral rhs) => ToFrom (InnerJoin lhs rhs) r Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods toFrom :: InnerJoin lhs rhs -> From r Source #

data CrossJoin a b infixl 2 Source #

Data type that represents a `CROSS JOIN` (see `LeftOuterJoin` for an example).

Constructors

a `CrossJoin` b infixl 2 |

#### Instances

Instances details

IsJoinKind CrossJoin Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods smartJoin :: a -> b -> CrossJoin a b Source # reifyJoinKind :: CrossJoin a b -> JoinKind Source #
FromPreprocess (CrossJoin a b) => From (CrossJoin a b) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods from_ :: SqlQuery (CrossJoin a b) Source #
(DoCrossJoin lateral lhs rhs r, IsLateral rhs ~ lateral) => ToFrom (CrossJoin lhs rhs) r Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods toFrom :: CrossJoin lhs rhs -> From r Source #

data LeftOuterJoin a b infixl 2 Source #

Data type that represents a `LEFT OUTER JOIN`. For example,

    select $
    from $ \(person `LeftOuterJoin` pet) ->
      ...

is translated into

    SELECT ...
    FROM Person LEFT OUTER JOIN Pet
    ...

See also: `from`.

Constructors

a `LeftOuterJoin` b infixl 2 |

#### Instances

Instances details

IsJoinKind LeftOuterJoin Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods smartJoin :: a -> b -> LeftOuterJoin a b Source # reifyJoinKind :: LeftOuterJoin a b -> JoinKind Source #
FromPreprocess (LeftOuterJoin a b) => From (LeftOuterJoin a b) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods from_ :: SqlQuery (LeftOuterJoin a b) Source #
(DoLeftJoin lateral lhs rhs r, lateral ~ IsLateral rhs) => ToFrom (LeftOuterJoin lhs rhs) r Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods toFrom :: LeftOuterJoin lhs rhs -> From r Source #

data RightOuterJoin a b infixl 2 Source #

Data type that represents a `RIGHT OUTER JOIN` (see `LeftOuterJoin` for an example).

Constructors

a `RightOuterJoin` b infixl 2 |

#### Instances

Instances details

IsJoinKind RightOuterJoin Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods smartJoin :: a -> b -> RightOuterJoin a b Source # reifyJoinKind :: RightOuterJoin a b -> JoinKind Source #
FromPreprocess (RightOuterJoin a b) => From (RightOuterJoin a b) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods from_ :: SqlQuery (RightOuterJoin a b) Source #
(ToFrom a a', ToFrom b b', ToMaybe a', ToMaybeT a' ~ ma, HasOnClause rhs (ma :& b'), ErrorOnLateral b, rhs ~ (b, (ma :& b') -> SqlExpr (Value Bool))) => ToFrom (RightOuterJoin a rhs) (ma :& b') Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods toFrom :: RightOuterJoin a rhs -> From (ma :& b') Source #

data FullOuterJoin a b infixl 2 Source #

Data type that represents a `FULL OUTER JOIN` (see `LeftOuterJoin` for an example).

Constructors

a `FullOuterJoin` b infixl 2 |

#### Instances

Instances details

IsJoinKind FullOuterJoin Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods smartJoin :: a -> b -> FullOuterJoin a b Source # reifyJoinKind :: FullOuterJoin a b -> JoinKind Source #
FromPreprocess (FullOuterJoin a b) => From (FullOuterJoin a b) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods from_ :: SqlQuery (FullOuterJoin a b) Source #
(ToFrom a a', ToFrom b b', ToMaybe a', ToMaybeT a' ~ ma, ToMaybe b', ToMaybeT b' ~ mb, HasOnClause rhs (ma :& mb), ErrorOnLateral b, rhs ~ (b, (ma :& mb) -> SqlExpr (Value Bool))) => ToFrom (FullOuterJoin a rhs) (ma :& mb) Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods toFrom :: FullOuterJoin a rhs -> From (ma :& mb) Source #

data JoinKind Source #

(Internal) A kind of `JOIN`.

Constructors

InnerJoinKind

    INNER JOIN

CrossJoinKind

    CROSS JOIN

LeftOuterJoinKind

    LEFT OUTER JOIN

RightOuterJoinKind

    RIGHT OUTER JOIN

FullOuterJoinKind

    FULL OUTER JOIN

#### Instances

Instances details

Show JoinKind Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods showsPrec :: Int -> JoinKind -> ShowS Source # show :: JoinKind -> String Source # showList :: [JoinKind] -> ShowS Source #
Eq JoinKind Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods (==) :: JoinKind -> JoinKind -> Bool Source # (/=) :: JoinKind -> JoinKind -> Bool Source #

data OnClauseWithoutMatchingJoinException Source #

Exception thrown whenever `on` is used to create an `ON` clause but no matching `JOIN` is found.

Constructors

OnClauseWithoutMatchingJoinException String |

#### Instances

Instances details

Exception OnClauseWithoutMatchingJoinException Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods toException :: OnClauseWithoutMatchingJoinException -> SomeException Source # fromException :: SomeException -> Maybe OnClauseWithoutMatchingJoinException Source # displayException :: OnClauseWithoutMatchingJoinException -> String Source #
Show OnClauseWithoutMatchingJoinException Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods showsPrec :: Int -> OnClauseWithoutMatchingJoinException -> ShowS Source # show :: OnClauseWithoutMatchingJoinException -> String Source # showList :: [OnClauseWithoutMatchingJoinException] -> ShowS Source #
Eq OnClauseWithoutMatchingJoinException Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods (==) :: OnClauseWithoutMatchingJoinException -> OnClauseWithoutMatchingJoinException -> Bool Source # (/=) :: OnClauseWithoutMatchingJoinException -> OnClauseWithoutMatchingJoinException -> Bool Source #
Ord OnClauseWithoutMatchingJoinException Source # |

Instance details

Defined in Database.Esqueleto.Internal.Internal

Methods

compare :: OnClauseWithoutMatchingJoinException -> OnClauseWithoutMatchingJoinException -> Ordering Source #

(<) :: OnClauseWithoutMatchingJoinException -> OnClauseWithoutMatchingJoinException -> Bool Source #

(<=) :: OnClauseWithoutMatchingJoinException -> OnClauseWithoutMatchingJoinException -> Bool Source #

(>) :: OnClauseWithoutMatchingJoinException -> OnClauseWithoutMatchingJoinException -> Bool Source #

(>=) :: OnClauseWithoutMatchingJoinException -> OnClauseWithoutMatchingJoinException -> Bool Source #

max :: OnClauseWithoutMatchingJoinException -> OnClauseWithoutMatchingJoinException -> OnClauseWithoutMatchingJoinException Source #

min :: OnClauseWithoutMatchingJoinException -> OnClauseWithoutMatchingJoinException -> OnClauseWithoutMatchingJoinException Source #

### Join Helpers

getTable :: forall t ts. GetFirstTable (SqlExpr (Entity t)) ts => ts -> SqlExpr (Entity t) Source #

Get the first table of a given type from a chain of tables joined with `(:&)`.

This can make it easier to write queries with a large number of join clauses:

    select $ do
    (people :& followers :& blogPosts) <-
        from $ table @Person
        `innerJoin` table @Follow
        `on` (\(person :& follow) ->
                person ^. PersonId ==. follow ^. FollowFollowed)
        `innerJoin` table @BlogPost
        `on` (\((getTable @Follow -> follow) :& blogPost) ->
                blogPost ^. BlogPostAuthorId ==. follow ^. FollowFollower)
    where_ (people1 ^. PersonName ==. val "John")
    pure (followers, people2)

This example is a bit trivial, but once you've joined five or six tables it becomes enormously helpful. The above example uses a `ViewPattern` to call the function and assign the variable directly, but you can also imagine it being written like this:

        `on` (\(prev :& blogPost) ->
                let
                    follow = getTable @Follow prev
                 in
                    blogPost ^. BlogPostAuthorId ==. follow ^. FollowFollower)

This function will pluck out the first table that matches the applied type, so if you join on the same table multiple times, it will always select the first one provided.

The `(:&)` operator associates so that the left hand side can be a wildcard for an arbitrary amount of nesting, and the "most recent" or "newest" table in a join sequence is always available on the rightmost - so `(prev :& bar)` is a pattern that matches `bar` table (the most recent table added) and `prev` tables (all prior tables in the join match).

By calling `getTable` on the `prev`, you can select exactly the table you want, allowing you to omit a large number of spurious pattern matches. Consider a query that does several `LEFT JOIN` on a first table:

    SELECT *
    FROM person
    LEFT JOIN car
      ON person.id = car.person_id
    LEFT JOIN bike
      ON person.id = bike.person_id
    LEFT JOIN food
      ON person.id = food.person_id
    LEFT JOIN address
      ON person.id = address.person_id

The final `on` clause in esqueleto would look like this:

        `on` do
            \(person :& _car :& _bike :& _food :& address) ->
                person.id ==. address.personId

First, we can change it to a `prev :& newest` match. We can do this because of the operator associativity. This is kind of like how a list `:` operator associates, but in the other direction: `a : (b : c) = a : b : c`.

        `on` do
            \(prev :& address) ->
                let (person :& _car :& _bike :& _food) = prev
                 in person.id ==. address.personId

Then, we can use `getTable` to select the `Person` table directly, instead of pattern matching manually.

        `on` do
            \(prev :& address) ->
                let person = getTable @Person prev
                 in person.id ==. address.personId

Finally, we can use a `ViewPattern` language extension to "inline" the access.

        `on` do
            \((getTable @Person -> person) :& address) ->
               person.id ==. address.personId

With this form, you do not need to be concerned about the number and wildcard status of tables that do not matter to the specific `ON` clause.

Since: 3.5.9.0

getTableMaybe :: forall t ts. GetFirstTable (SqlExpr (Maybe (Entity t))) ts => ts -> SqlExpr (Maybe (Entity t)) Source #

A variant of `getTable` that operates on possibly-null entities.

Since: 3.5.9.0

class GetFirstTable t ts where Source #

Typeclass for selecting tables using type application syntax.

If you have a long chain of tables joined with `(:&)`, like `a :& b :& c :& d`, then `getTable @c (a :& b :& c :& d)` will give you the `c` table back.

Note that this typeclass will only select the first table of the given type; it may be less useful if there's multiple tables of the same type.

Since: 3.5.9.0

Methods

getFirstTable :: ts -> t Source #

Get the first table of type `t` from the tables `ts`.

Since: 3.5.9.0

#### Instances

Instances details

GetFirstTable t (t :& ts) Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods getFirstTable :: (t :& ts) -> t Source #
GetFirstTable t ts => GetFirstTable t (ts :& x) Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods getFirstTable :: (ts :& x) -> t Source #
GetFirstTable t (x :& t) Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods getFirstTable :: (x :& t) -> t Source #

## SQL backend

data SqlQuery a Source #

SQL backend for `esqueleto` using `SqlPersistT`.

#### Instances

Instances details

Applicative SqlQuery Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods pure :: a -> SqlQuery a Source # (<*>) :: SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b Source # liftA2 :: (a -> b -> c) -> SqlQuery a -> SqlQuery b -> SqlQuery c Source # (*>) :: SqlQuery a -> SqlQuery b -> SqlQuery b Source # (<*) :: SqlQuery a -> SqlQuery b -> SqlQuery a Source #
Functor SqlQuery Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods fmap :: (a -> b) -> SqlQuery a -> SqlQuery b Source # (<$) :: a -> SqlQuery b -> SqlQuery a Source #
Monad SqlQuery Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods (>>=) :: SqlQuery a -> (a -> SqlQuery b) -> SqlQuery b Source # (>>) :: SqlQuery a -> SqlQuery b -> SqlQuery b Source # return :: a -> SqlQuery a Source #
(ToFrom a a', SqlSelect b r, ToAlias b, ToAliasReference b, d ~ (a' :& b)) => DoInnerJoin Lateral a (a' -> SqlQuery b, d -> SqlExpr (Value Bool)) d Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods doInnerJoin :: Proxy Lateral -> a -> (a' -> SqlQuery b, d -> SqlExpr (Value Bool)) -> From d Source #
(ToFrom a a', ToMaybe b, d ~ (a' :& ToMaybeT b), SqlSelect b r, ToAlias b, ToAliasReference b) => DoLeftJoin Lateral a (a' -> SqlQuery b, d -> SqlExpr (Value Bool)) d Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods doLeftJoin :: Proxy Lateral -> a -> (a' -> SqlQuery b, d -> SqlExpr (Value Bool)) -> From d Source #
(ToFrom a a', SqlSelect b r, ToAlias b, ToAliasReference b) => DoCrossJoin Lateral a (a' -> SqlQuery b) (a' :& b) Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods doCrossJoin :: Proxy Lateral -> a -> (a' -> SqlQuery b) -> From (a' :& b) Source #
(SqlSelect a r, ToAlias a, ToAliasReference a) => ToFrom (SubQuery (SqlQuery a)) a Source # |
Instance details Defined in Database.Esqueleto.Experimental.From Methods toFrom :: SubQuery (SqlQuery a) -> From a Source #
(SqlSelect a r, ToAlias a, ToAliasReference a) => ToFrom (SqlQuery a) a Source # |
Instance details Defined in Database.Esqueleto.Experimental.From Methods toFrom :: SqlQuery a -> From a Source #
(SqlSelect a r, ToAlias a, ToAliasReference a) => ToSqlSetOperation (SqlQuery a) a Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.SqlSetOperation Methods toSqlSetOperation :: SqlQuery a -> SqlSetOperation a Source #
ValidOnClause (a -> SqlQuery b) Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join

data SqlExpr a Source #

An expression on the SQL backend.

Raw expression: Contains a `SqlExprMeta` and a function for building the expr. It recieves a parameter telling it whether it is in a parenthesized context, and takes information about the SQL connection (mainly for escaping names) and returns both an string (`Builder`) and a list of values to be interpolated by the SQL backend.

#### Instances

Instances details

(TypeError SqlExprFunctorMessage :: Constraint) => Functor SqlExpr Source #

Folks often want the ability to promote a Haskell function into the `SqlExpr` expression language - and naturally reach for `fmap`. Unfortunately, this is impossible. We cannot send *functions* to the database, which is what we would need to do in order for this to make sense. Let's consider the type of `fmap` for `SqlExpr`:

    fmap :: (a -> b) -> SqlExpr a -> SqlExpr b

This type signature is making a pretty strong claim: "Give me a Haskell function from `a -> b`. I will then transform a SQL expression representing a Haskell value of type `a` and turn it into a SQL expression representing a Haskell value of type `b`."

Let's suppose we *could* do this - `fmap (+1)` would have to somehow inspect the function expression means "add one", and then translate that to the appropriate SQL.

This is why `esqueleto` defines a bunch of operators: `x `+.` (`val` 1)` can be used instead of ``fmap` (+1) x`.

If you do have a SQL function, then you can provide a safe type and introduce it with `unsafeSqlFunction` or `unsafeSqlBinOp`.

Since: 3.5.8.2

Instance details Defined in Database.Esqueleto.Internal.Internal Methods fmap :: (a -> b) -> SqlExpr a -> SqlExpr b Source # (<$) :: a -> SqlExpr b -> SqlExpr a Source #

(PersistEntity rec, PersistField typ, SymbolToField sym rec typ) => HasField (sym :: Symbol) (SqlExpr (Entity rec)) (SqlExpr (Value typ)) Source #

This instance allows you to use `record.field` notation with GHC 9.2's `OverloadedRecordDot` extension.

Example:

    -- persistent model:
    BlogPost
        authorId     PersonId
        title        Text

    -- query:
    select $ do
        bp <- from $ table @BlogPost
        pure $ bp.title

This is exactly equivalent to the following:

    blogPost :: SqlExpr (Entity BlogPost)

    blogPost ^. BlogPostTitle
    blogPost ^. #title
    blogPost.title

There's another instance defined on ``SqlExpr` (`Entity` (`Maybe` rec))`, which allows you to project from a `LEFT JOIN`ed entity.

Since: 3.5.4.0

Instance details Defined in Database.Esqueleto.Internal.Internal Methods getField :: SqlExpr (Entity rec) -> SqlExpr (Value typ) Source #

(PersistEntity rec, PersistField typ, SymbolToField sym rec typ) => HasField (sym :: Symbol) (SqlExpr (Maybe (Entity rec))) (SqlExpr (Value (Maybe typ))) Source #

This instance allows you to use `record.field` notation with GC 9.2's `OverloadedRecordDot` extension.

Example:

    -- persistent model:
    Person
        name         Text

    BlogPost
        title        Text
        authorId     PersonId

    -- query:

    select $ do
        (p :& bp) <- from $
            table Person
            leftJoin table BlogPost
            on do
                \(p :& bp) ->
                    just p.id ==. bp.authorId
        pure (p.name, bp.title)

The following forms are all equivalent:

    blogPost :: SqlExpr (Maybe (Entity BlogPost))

    blogPost ?. BlogPostTitle
    blogPost ?. #title
    blogPost.title

Since: 3.5.4.0

Instance details Defined in Database.Esqueleto.Internal.Internal Methods getField :: SqlExpr (Maybe (Entity rec)) -> SqlExpr (Value (Maybe typ)) Source #
(ToFrom a a', SqlSelect b r, ToAlias b, ToAliasReference b, d ~ (a' :& b)) => DoInnerJoin Lateral a (a' -> SqlQuery b, d -> SqlExpr (Value Bool)) d Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods doInnerJoin :: Proxy Lateral -> a -> (a' -> SqlQuery b, d -> SqlExpr (Value Bool)) -> From d Source #
(ToFrom a a', ToMaybe b, d ~ (a' :& ToMaybeT b), SqlSelect b r, ToAlias b, ToAliasReference b) => DoLeftJoin Lateral a (a' -> SqlQuery b, d -> SqlExpr (Value Bool)) d Source # |
Instance details Defined in Database.Esqueleto.Experimental.From.Join Methods doLeftJoin :: Proxy Lateral -> a -> (a' -> SqlQuery b, d -> SqlExpr (Value Bool)) -> From d Source #
ToAlias (SqlExpr (Value a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: SqlExpr (Value a) -> SqlQuery (SqlExpr (Value a)) Source #
ToAlias (SqlExpr (Entity a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: SqlExpr (Entity a) -> SqlQuery (SqlExpr (Entity a)) Source #
ToAlias (SqlExpr (Maybe (Entity a))) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: SqlExpr (Maybe (Entity a)) -> SqlQuery (SqlExpr (Maybe (Entity a))) Source #
ToAliasReference (SqlExpr (Value a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> SqlExpr (Value a) -> SqlQuery (SqlExpr (Value a)) Source #
ToAliasReference (SqlExpr (Entity a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> SqlExpr (Entity a) -> SqlQuery (SqlExpr (Entity a)) Source #
ToAliasReference (SqlExpr (Maybe (Entity a))) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> SqlExpr (Maybe (Entity a)) -> SqlQuery (SqlExpr (Maybe (Entity a))) Source #
ToMaybe (SqlExpr (Value a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToMaybe Associated Types type ToMaybeT (SqlExpr (Value a)) Source # Methods toMaybe :: SqlExpr (Value a) -> ToMaybeT (SqlExpr (Value a)) Source #
ToMaybe (SqlExpr (Entity a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToMaybe Associated Types type ToMaybeT (SqlExpr (Entity a)) Source # Methods toMaybe :: SqlExpr (Entity a) -> ToMaybeT (SqlExpr (Entity a)) Source #
ToMaybe (SqlExpr (Maybe a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToMaybe Associated Types type ToMaybeT (SqlExpr (Maybe a)) Source # Methods toMaybe :: SqlExpr (Maybe a) -> ToMaybeT (SqlExpr (Maybe a)) Source #
FromPreprocess (SqlExpr (Entity val)) => From (SqlExpr (Entity val)) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods from_ :: SqlQuery (SqlExpr (Entity val)) Source #
FromPreprocess (SqlExpr (Maybe (Entity val))) => From (SqlExpr (Maybe (Entity val))) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods from_ :: SqlQuery (SqlExpr (Maybe (Entity val))) Source #
(PersistEntity val, BackendCompatible SqlBackend (PersistEntityBackend val)) => FromPreprocess (SqlExpr (Entity val)) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods fromPreprocess :: SqlQuery (PreprocessedFrom (SqlExpr (Entity val))) Source #
(PersistEntity val, BackendCompatible SqlBackend (PersistEntityBackend val)) => FromPreprocess (SqlExpr (Maybe (Entity val))) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods fromPreprocess :: SqlQuery (PreprocessedFrom (SqlExpr (Maybe (Entity val)))) Source #
PersistEntity val => LockableEntity (SqlExpr (Entity val)) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods flattenLockableEntity :: SqlExpr (Entity val) -> NonEmpty LockableSqlExpr Source #
ToSomeValues (SqlExpr (Value a)) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods toSomeValues :: SqlExpr (Value a) -> [SomeValue] Source #
a ~ Value b => UnsafeSqlFunctionArgument (SqlExpr a) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods toArgList :: SqlExpr a -> [SqlExpr (Value ())] Source #
PersistEntity ent => ToFrom (Table ent) (SqlExpr (Entity ent)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.From Methods toFrom :: Table ent -> From (SqlExpr (Entity ent)) Source #
PersistEntity e => SqlSelect (SqlExpr (Insertion e)) (Insertion e) Source # | `INSERT INTO` hack.
Instance details Defined in Database.Esqueleto.Internal.Internal Methods sqlSelectCols :: IdentInfo -> SqlExpr (Insertion e) -> (Builder, [PersistValue]) Source # sqlSelectColCount :: Proxy (SqlExpr (Insertion e)) -> Int Source # sqlSelectProcessRow :: [PersistValue] -> Either Text (Insertion e) Source # sqlInsertInto :: IdentInfo -> SqlExpr (Insertion e) -> (Builder, [PersistValue]) Source #
PersistField a => SqlSelect (SqlExpr (Value a)) (Value a) Source # | You may return any single value (i.e. a single column) from a `select` query.
Instance details Defined in Database.Esqueleto.Internal.Internal Methods sqlSelectCols :: IdentInfo -> SqlExpr (Value a) -> (Builder, [PersistValue]) Source # sqlSelectColCount :: Proxy (SqlExpr (Value a)) -> Int Source # sqlSelectProcessRow :: [PersistValue] -> Either Text (Value a) Source # sqlInsertInto :: IdentInfo -> SqlExpr (Value a) -> (Builder, [PersistValue]) Source #
PersistEntity a => SqlSelect (SqlExpr (Entity a)) (Entity a) Source # | You may return an `Entity` from a `select` query.
Instance details Defined in Database.Esqueleto.Internal.Internal Methods sqlSelectCols :: IdentInfo -> SqlExpr (Entity a) -> (Builder, [PersistValue]) Source # sqlSelectColCount :: Proxy (SqlExpr (Entity a)) -> Int Source # sqlSelectProcessRow :: [PersistValue] -> Either Text (Entity a) Source # sqlInsertInto :: IdentInfo -> SqlExpr (Entity a) -> (Builder, [PersistValue]) Source #
PersistEntity a => SqlSelect (SqlExpr (Maybe (Entity a))) (Maybe (Entity a)) Source # | You may return a possibly-`NULL` `Entity` from a `select` query.

Instance details

Defined in Database.Esqueleto.Internal.Internal

Methods

sqlSelectCols :: IdentInfo -> SqlExpr (Maybe (Entity a)) -> (Builder, [PersistValue]) Source #

sqlSelectColCount :: Proxy (SqlExpr (Maybe (Entity a))) -> Int Source #

sqlSelectProcessRow :: [PersistValue] -> Either Text (Maybe (Entity a)) Source #

sqlInsertInto :: IdentInfo -> SqlExpr (Maybe (Entity a)) -> (Builder, [PersistValue]) Source #

type ToMaybeT (SqlExpr (Value a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToMaybe type ToMaybeT (SqlExpr (Value a)) = SqlExpr (Value (Maybe (Nullable a)))
type ToMaybeT (SqlExpr (Entity a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToMaybe type ToMaybeT (SqlExpr (Entity a)) = SqlExpr (Maybe (Entity a))
type ToMaybeT (SqlExpr (Maybe a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToMaybe type ToMaybeT (SqlExpr (Maybe a)) = SqlExpr (Maybe a)

type SqlEntity ent = (PersistEntity ent, PersistEntityBackend ent ~ SqlBackend) Source #

Constraint synonym for `persistent` entities whose backend is `SqlBackend`.

select :: (SqlSelect a r, MonadIO m, SqlBackendCanRead backend) => SqlQuery a -> ReaderT backend m [r] Source #

Execute an `esqueleto` `SELECT` query inside `persistent`'s `SqlPersistT` monad and return a list of rows.

We've seen that `from` has some magic about which kinds of things you may bring into scope. This `select` function also has some magic for which kinds of things you may bring back to Haskell-land by using `SqlQuery`'s `return`:

- You may return a `SqlExpr (`Entity` v)` for an entity `v` (i.e., like the `*` in SQL), which is then returned to Haskell-land as just `Entity v`.
- You may return a `SqlExpr (Maybe (Entity v))` for an entity `v` that may be `NULL`, which is then returned to Haskell-land as `Maybe (Entity v)`. Used for `OUTER JOIN`s.
- You may return a `SqlExpr (`Value` t)` for a value `t` (i.e., a single column), where `t` is any instance of `PersistField`, which is then returned to Haskell-land as `Value t`. You may use `Value` to return projections of an `Entity` (see `(`^.`)` and `(`?.`)`) or to return any other value calculated on the query (e.g., `countRows` or `subSelect`).

The `SqlSelect a r` class has functional dependencies that allow type information to flow both from `a` to `r` and vice-versa. This means that you'll almost never have to give any type signatures for `esqueleto` queries. For example, the query ``select` $ from $ \p -> return p` alone is ambiguous, but in the context of

    do ps <- select $
             from $ \p ->
             return p
       liftIO $ mapM_ (putStrLn . personName . entityVal) ps

we are able to infer from that single `personName . entityVal` function composition that the `p` inside the query is of type `SqlExpr (Entity Person)`.

selectOne :: (SqlSelect a r, MonadIO m, SqlBackendCanRead backend) => SqlQuery a -> ReaderT backend m (Maybe r) Source #

Execute an `esqueleto` `SELECT` query inside `persistent`'s `SqlPersistT` monad and return the first entry wrapped in a `Maybe`. @since 3.5.1.0

### Example usage

Expand

    firstPerson :: MonadIO m => SqlPersistT m (Maybe (Entity Person))
    firstPerson =
     selectOne $ do
         person <- from $ table @Person
         return person

The above query is equivalent to a `select` combined with `limit` but you would still have to transform the results from a list:

    firstPerson :: MonadIO m => SqlPersistT m [Entity Person]
    firstPerson =
     select $ do
         person <- from $ table @Person
         limit 1
         return person

selectSource :: (SqlSelect a r, BackendCompatible SqlBackend backend, IsPersistBackend backend, PersistQueryRead backend, PersistStoreRead backend, PersistUniqueRead backend, MonadResource m) => SqlQuery a -> ConduitT () r (ReaderT backend m) () Source #

Execute an `esqueleto` `SELECT` query inside `persistent`'s `SqlPersistT` monad and return a `Source` of rows.

delete :: (MonadIO m, SqlBackendCanWrite backend) => SqlQuery () -> ReaderT backend m () Source #

Execute an `esqueleto` `DELETE` query inside `persistent`'s `SqlPersistT` monad. Note that currently there are no type checks for statements that should not appear on a `DELETE` query.

Example of usage:

    delete $
    from $ \appointment ->
    where_ (appointment ^. AppointmentDate <. val now)

Unlike `select`, there is a useful way of using `delete` that will lead to type ambiguities. If you want to delete all rows (i.e., no `where_` clause), you'll have to use a type signature:

    delete $
    from $ \(appointment :: SqlExpr (Entity Appointment)) ->
    return ()

#### Database.Esqueleto.Experimental:

     delete $ do
       userFeature <- from $ table @UserFeature
       where_ ((userFeature ^. UserFeatureFeature) notIn valList allKnownFeatureFlags)

deleteCount :: (MonadIO m, SqlBackendCanWrite backend) => SqlQuery () -> ReaderT backend m Int64 Source #

Same as `delete`, but returns the number of rows affected.

update :: (MonadIO m, PersistEntity val, BackendCompatible SqlBackend (PersistEntityBackend val), SqlBackendCanWrite backend) => (SqlExpr (Entity val) -> SqlQuery ()) -> ReaderT backend m () Source #

Execute an `esqueleto` `UPDATE` query inside `persistent`'s `SqlPersistT` monad. Note that currently there are no type checks for statements that should not appear on a `UPDATE` query.

Example of usage:

    update $ \p -> do
    set p [ PersonAge =. just (val thisYear) -. p ^. PersonBorn ]
    where_ $ isNothing (p ^. PersonAge)

updateCount :: (MonadIO m, PersistEntity val, BackendCompatible SqlBackend (PersistEntityBackend val), SqlBackendCanWrite backend) => (SqlExpr (Entity val) -> SqlQuery ()) -> ReaderT backend m Int64 Source #

Same as `update`, but returns the number of rows affected.

insertSelect :: (MonadIO m, PersistEntity a, SqlBackendCanWrite backend) => SqlQuery (SqlExpr (Insertion a)) -> ReaderT backend m () Source #

Insert a `PersistField` for every selected value.

Since: 2.4.2

insertSelectCount :: (MonadIO m, PersistEntity a, SqlBackendCanWrite backend) => SqlQuery (SqlExpr (Insertion a)) -> ReaderT backend m Int64 Source #

Insert a `PersistField` for every selected value, return the count afterward

(<#) :: (a -> b) -> SqlExpr (Value a) -> SqlExpr (Insertion b) Source #

Apply a `PersistField` constructor to `SqlExpr Value` arguments.

(<&>) :: SqlExpr (Insertion (a -> b)) -> SqlExpr (Value a) -> SqlExpr (Insertion b) Source #

Apply extra `SqlExpr Value` arguments to a `PersistField` constructor

## Rendering Queries

renderQueryToText Source #

Arguments

:: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) |
=> Mode | Whether to render as an `SELECT`, `DELETE`, etc.
-> SqlQuery a | The SQL query you want to render.
-> ReaderT backend m (Text, [PersistValue]) |

Renders a `SqlQuery` into a `Text` value along with the list of `PersistValue`s that would be supplied to the database for `?` placeholders.

You must ensure that the `Mode` you pass to this function corresponds with the actual `SqlQuery`. If you pass a query that uses incompatible features (like an `INSERT` statement with a `SELECT` mode) then you'll get a weird result.

Since: 3.1.1

renderQuerySelect Source #

Arguments

:: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) |
=> SqlQuery a | The SQL query you want to render.
-> ReaderT backend m (Text, [PersistValue]) |

Renders a `SqlQuery` into a `Text` value along with the list of `PersistValue`s that would be supplied to the database for `?` placeholders.

Since: 3.1.1

renderQueryUpdate Source #

Arguments

:: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) |
=> SqlQuery a | The SQL query you want to render.
-> ReaderT backend m (Text, [PersistValue]) |

Renders a `SqlQuery` into a `Text` value along with the list of `PersistValue`s that would be supplied to the database for `?` placeholders.

Since: 3.1.1

renderQueryDelete Source #

Arguments

:: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) |
=> SqlQuery a | The SQL query you want to render.
-> ReaderT backend m (Text, [PersistValue]) |

Renders a `SqlQuery` into a `Text` value along with the list of `PersistValue`s that would be supplied to the database for `?` placeholders.

Since: 3.1.1

renderQueryInsertInto Source #

Arguments

:: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) |
=> SqlQuery a | The SQL query you want to render.
-> ReaderT backend m (Text, [PersistValue]) |

Renders a `SqlQuery` into a `Text` value along with the list of `PersistValue`s that would be supplied to the database for `?` placeholders.

Since: 3.1.1

## Helpers

valkey :: (ToBackendKey SqlBackend entity, PersistField (Key entity)) => Int64 -> SqlExpr (Value (Key entity)) Source #

`valkey i = `val` . `toSqlKey`` (https://github.com/prowdsponsor/esqueleto/issues/9).

valJ :: PersistField (Key entity) => Value (Key entity) -> SqlExpr (Value (Key entity)) Source #

`valJ` is like `val` but for something that is already a `Value`. The use case it was written for was, given a `Value` lift the `Key` for that `Value` into the query expression in a type safe way. However, the implementation is more generic than that so we call it `valJ`.

Its important to note that the input entity and the output entity are constrained to be the same by the type signature on the function (https://github.com/prowdsponsor/esqueleto/pull/69).

Since: 1.4.2

associateJoin :: forall e1 e0. Ord (Key e0) => [(Entity e0, e1)] -> Map (Key e0) (e0, [e1]) Source #

Avoid N+1 queries and join entities into a map structure.

This function is useful to call on the result of a single `JOIN`. For example, suppose you have this query:

    getFoosAndNestedBarsFromParent
        :: ParentId
        -> SqlPersistT IO [(Entity Foo, Maybe (Entity Bar))]
    getFoosAndNestedBarsFromParent parentId =
        select $ do
            (foo :& bar) <- from $
                table Foo
                `LeftOuterJoin`
                table Bar
                    `on` do
                        \(foo :& bar) ->
                            foo ^. FooId ==. bar ?. BarFooId
            where_ $
                foo ^. FooParentId ==. val parentId
            pure (foo, bar)

This is a natural result type for SQL - a list of tuples. However, it's not what we usually want in Haskell - each `Foo` in the list will be represented multiple times, once for each `Bar`.

We can write ``fmap` `associateJoin`` and it will translate it into a `Map` that is keyed on the `Key` of the left `Entity`, and the value is a tuple of the entity's value as well as the list of each coresponding entity.

    getFoosAndNestedBarsFromParentHaskellese
        :: ParentId
        -> SqlPersistT (Map (Key Foo) (Foo, [Maybe (Entity Bar)]))
    getFoosAndNestedBarsFromParentHaskellese parentId =
        fmap associateJoin $ getFoosdAndNestedBarsFromParent parentId

What if you have multiple joins?

Let's use `associateJoin` with a *two* join query.

    userPostComments
        :: SqlQuery (SqlExpr (Entity User, Entity Post, Entity Comment))
    userPostsComment = do
        (u :& p :& c) <- from $
            table User
            `InnerJoin`
            table Post
                on do
                    \(u :& p) ->
                        u ^. UserId ==. p ^. PostUserId
            `InnerJoin`
            table @Comment
                `on` do
                    \(_ :& p :& c) ->
                        p ^. PostId ==. c ^. CommentPostId
        pure (u, p, c)

This query returns a User, with all of the users Posts, and then all of the Comments on that post.

First, we *nest* the tuple.

    nest :: (a, b, c) -> (a, (b, c))
    nest (a, b, c) = (a, (b, c))

This makes the return of the query conform to the input expected from `associateJoin`.

    nestedUserPostComments
        :: SqlPersistT IO [(Entity User, (Entity Post, Entity Comment))]
    nestedUserPostComments =
        fmap nest $ select userPostsComments

Now, we can call `associateJoin` on it.

    associateUsers
        :: [(Entity User, (Entity Post, Entity Comment))]
        -> Map UserId (User, [(Entity Post, Entity Comment)])
    associateUsers =
        associateJoin

Next, we'll use the `Functor` instances for `Map` and tuple to call `associateJoin` on the `[(Entity Post, Entity Comment)]`.

    associatePostsAndComments
        :: Map UserId (User, [(Entity Post, Entity Comment)])
        -> Map UserId (User, Map PostId (Post, [Entity Comment]))
    associatePostsAndComments =
        fmap (fmap associateJoin)

For more reading on this topic, see this Foxhound Systems blog post.

Since: 3.1.2

## Re-exports

deleteKey :: (PersistStore backend, BaseBackend backend ~ PersistEntityBackend val, MonadIO m, PersistEntity val) => Key val -> ReaderT backend m () Source #

Synonym for `delete` that does not clash with `esqueleto`'s `delete`.

class (PersistField (Key record), ToJSON (Key record), FromJSON (Key record), Show (Key record), Read (Key record), Eq (Key record), Ord (Key record)) => PersistEntity record where Source #

Persistent serialized Haskell records to the database. A Database `Entity` (A row in SQL, a document in MongoDB, etc) corresponds to a `Key` plus a Haskell record.

For every Haskell record type stored in the database there is a corresponding `PersistEntity` instance. An instance of PersistEntity contains meta-data for the record. PersistEntity also helps abstract over different record types. That way the same query interface can return a `PersistEntity`, with each query returning different types of Haskell records.

Some advanced type system capabilities are used to make this process type-safe. Persistent users usually don't need to understand the class associated data and functions.

Minimal complete definition

keyToValues, keyFromValues, persistIdField, entityDef, persistFieldDef, toPersistFields, fromPersistValues, tabulateEntityA, persistUniqueKeys, persistUniqueToFieldNames, persistUniqueToValues, fieldLens

Associated Types

type PersistEntityBackend record Source #

Persistent allows multiple different backends (databases).

data Key record Source #

By default, a backend will automatically generate the key Instead you can specify a Primary key made up of unique values.

data EntityField record :: Type -> Type Source #

An `EntityField` is parameterised by the Haskell record it belongs to and the additional type of that field.

As of `persistent-2.11.0.0`, it's possible to use the `OverloadedLabels` language extension to refer to `EntityField` values polymorphically. See the documentation on `SymbolToField` for more information.

data Unique record Source #

Unique keys besides the `Key`.

Methods

keyToValues :: Key record -> [PersistValue] Source #

A lower-level key operation.

keyFromValues :: [PersistValue] -> Either Text (Key record) Source #

A lower-level key operation.

persistIdField :: EntityField record (Key record) Source #

A meta-operation to retrieve the `Key` `EntityField`.

entityDef :: proxy record -> EntityDef Source #

Retrieve the `EntityDef` meta-data for the record.

persistFieldDef :: EntityField record typ -> FieldDef Source #

Return meta-data for a given `EntityField`.

toPersistFields :: record -> [PersistValue] Source #

A meta-operation to get the database fields of a record.

fromPersistValues :: [PersistValue] -> Either Text record Source #

A lower-level operation to convert from database values to a Haskell record.

tabulateEntityA Source #

Arguments

:: Applicative f |
=> (forall a. EntityField record a -> f a) | A function that builds a fragment of a record in an `Applicative` context.
-> f (Entity record) |

This function allows you to build an ``Entity` a` by specifying an action that returns a value for the field in the callback function. Let's look at an example.

    parseFromEnvironmentVariables :: IO (Entity User)
    parseFromEnvironmentVariables =
        tabulateEntityA $ \userField ->
            case userField of
                UserName ->
                    getEnv USER_NAME
                UserAge -> do
                    ageVar <- getEnv USER_AGE
                    case readMaybe ageVar of
                        Just age ->
                            pure age
                        Nothing ->
                            error $ "Failed to parse Age from: " <> ageVar
                UserAddressId -> do
                    addressVar <- getEnv USER_ADDRESS_ID
                    pure $ AddressKey addressVar

Since: persistent-2.14.0.0

persistUniqueKeys :: record -> [Unique record] Source #

A meta operation to retrieve all the `Unique` keys.

persistUniqueToFieldNames :: Unique record -> NonEmpty (FieldNameHS, FieldNameDB) Source #

A lower level operation.

persistUniqueToValues :: Unique record -> [PersistValue] Source #

A lower level operation.

fieldLens :: EntityField record field -> forall (f :: Type -> Type). Functor f => (field -> f field) -> Entity record -> f (Entity record) Source #

Use a `PersistField` as a lens.

keyFromRecordM :: Maybe (record -> Key record) Source #

Extract a ``Key` record` from a `record` value. Currently, this is only defined for entities using the `Primary` syntax for natural/composite keys. In a future version of `persistent` which incorporates the ID directly into the entity, this will always be Just.

Since: persistent-2.11.0.0

data family Key record Source #

By default, a backend will automatically generate the key Instead you can specify a Primary key made up of unique values.

#### Instances

Instances details

(PersistEntity a, PersistEntityBackend a ~ backend, IsPersistBackend backend) => RawSql (Key a) |
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> Key a -> (Int, [Text]) Source # rawSqlColCountReason :: Key a -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (Key a) Source #

data family Unique record Source #

Unique keys besides the `Key`.

#### Instances

Instances details

FinalResult (Unique val) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods finalR :: Unique val -> KnowResult (Unique val) Source #

newtype Single a Source #

A single column (see `rawSql`). Any `PersistField` may be used here, including `PersistValue` (which does not do any processing).

Constructors

Single |

Fields

- unSingle :: a

#### Instances

Instances details

Read a => Read (Single a) |
Instance details Defined in Database.Persist.Sql.Types Methods readsPrec :: Int -> ReadS (Single a) Source # readList :: ReadS [Single a] Source # readPrec :: ReadPrec (Single a) Source # readListPrec :: ReadPrec [Single a] Source #
Show a => Show (Single a) |
Instance details Defined in Database.Persist.Sql.Types Methods showsPrec :: Int -> Single a -> ShowS Source # show :: Single a -> String Source # showList :: [Single a] -> ShowS Source #
Eq a => Eq (Single a) |
Instance details Defined in Database.Persist.Sql.Types Methods (==) :: Single a -> Single a -> Bool Source # (/=) :: Single a -> Single a -> Bool Source #
Ord a => Ord (Single a) |
Instance details Defined in Database.Persist.Sql.Types Methods compare :: Single a -> Single a -> Ordering Source # (<) :: Single a -> Single a -> Bool Source # (<=) :: Single a -> Single a -> Bool Source # (>) :: Single a -> Single a -> Bool Source # (>=) :: Single a -> Single a -> Bool Source # max :: Single a -> Single a -> Single a Source # min :: Single a -> Single a -> Single a Source #
PersistField a => RawSql (Single a) |
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> Single a -> (Int, [Text]) Source # rawSqlColCountReason :: Single a -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (Single a) Source #

class PersistConfig c where Source #

Represents a value containing all the configuration options for a specific backend. This abstraction makes it easier to write code that can easily swap backends.

Minimal complete definition

loadConfig, createPoolConfig, runPool

Associated Types

type PersistConfigBackend c :: (Type -> Type) -> Type -> Type Source #

type PersistConfigPool c Source #

Methods

loadConfig :: Value -> Parser c Source #

Load the config settings from a `Value`, most likely taken from a YAML config file.

applyEnv :: c -> IO c Source #

Modify the config settings based on environment variables.

createPoolConfig :: c -> IO (PersistConfigPool c) Source #

Create a new connection pool based on the given config settings.

runPool :: MonadUnliftIO m => c -> PersistConfigBackend c m a -> PersistConfigPool c -> m a Source #

Run a database action by taking a connection from the pool.

#### Instances

Instances details

(PersistConfig c1, PersistConfig c2, PersistConfigPool c1 ~ PersistConfigPool c2, PersistConfigBackend c1 ~ PersistConfigBackend c2) => PersistConfig (Either c1 c2) |

Instance details

Defined in Database.Persist.Class.PersistConfig

Associated Types

type PersistConfigBackend (Either c1 c2) :: (Type -> Type) -> Type -> Type Source #

type PersistConfigPool (Either c1 c2) Source #

Methods

loadConfig :: Value -> Parser (Either c1 c2) Source #

applyEnv :: Either c1 c2 -> IO (Either c1 c2) Source #

createPoolConfig :: Either c1 c2 -> IO (PersistConfigPool (Either c1 c2)) Source #

runPool :: MonadUnliftIO m => Either c1 c2 -> PersistConfigBackend (Either c1 c2) m a -> PersistConfigPool (Either c1 c2) -> m a Source #

type family PersistConfigBackend c :: (Type -> Type) -> Type -> Type Source #

#### Instances

Instances details

type PersistConfigBackend (Either c1 c2) |
Instance details Defined in Database.Persist.Class.PersistConfig type PersistConfigBackend (Either c1 c2) = PersistConfigBackend c1

type family PersistConfigPool c Source #

#### Instances

Instances details

type PersistConfigPool (Either c1 c2) |
Instance details Defined in Database.Persist.Class.PersistConfig type PersistConfigPool (Either c1 c2) = PersistConfigPool c1

newtype ConstraintNameHS Source #

An `ConstraintNameHS` represents the Haskell-side name that `persistent` will use for a constraint.

Since: persistent-2.12.0.0

Constructors

ConstraintNameHS |

Fields

- unConstraintNameHS :: Text

#### Instances

Instances details

Read ConstraintNameHS |
Instance details Defined in Database.Persist.Names Methods readsPrec :: Int -> ReadS ConstraintNameHS Source # readList :: ReadS [ConstraintNameHS] Source # readPrec :: ReadPrec ConstraintNameHS Source # readListPrec :: ReadPrec [ConstraintNameHS] Source #
Show ConstraintNameHS |
Instance details Defined in Database.Persist.Names Methods showsPrec :: Int -> ConstraintNameHS -> ShowS Source # show :: ConstraintNameHS -> String Source # showList :: [ConstraintNameHS] -> ShowS Source #
Eq ConstraintNameHS |
Instance details Defined in Database.Persist.Names Methods (==) :: ConstraintNameHS -> ConstraintNameHS -> Bool Source # (/=) :: ConstraintNameHS -> ConstraintNameHS -> Bool Source #
Ord ConstraintNameHS |

Instance details

Defined in Database.Persist.Names

Methods

compare :: ConstraintNameHS -> ConstraintNameHS -> Ordering Source #

(<) :: ConstraintNameHS -> ConstraintNameHS -> Bool Source #

(<=) :: ConstraintNameHS -> ConstraintNameHS -> Bool Source #

(>) :: ConstraintNameHS -> ConstraintNameHS -> Bool Source #

(>=) :: ConstraintNameHS -> ConstraintNameHS -> Bool Source #

max :: ConstraintNameHS -> ConstraintNameHS -> ConstraintNameHS Source #

min :: ConstraintNameHS -> ConstraintNameHS -> ConstraintNameHS Source #

Lift ConstraintNameHS |
Instance details Defined in Database.Persist.Names Methods lift :: Quote m => ConstraintNameHS -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => ConstraintNameHS -> Code m ConstraintNameHS Source #

newtype ConstraintNameDB Source #

A `ConstraintNameDB` represents the datastore-side name that `persistent` will use for a constraint.

Since: persistent-2.12.0.0

Constructors

ConstraintNameDB |

Fields

- unConstraintNameDB :: Text

#### Instances

Instances details

Read ConstraintNameDB |
Instance details Defined in Database.Persist.Names Methods readsPrec :: Int -> ReadS ConstraintNameDB Source # readList :: ReadS [ConstraintNameDB] Source # readPrec :: ReadPrec ConstraintNameDB Source # readListPrec :: ReadPrec [ConstraintNameDB] Source #
Show ConstraintNameDB |
Instance details Defined in Database.Persist.Names Methods showsPrec :: Int -> ConstraintNameDB -> ShowS Source # show :: ConstraintNameDB -> String Source # showList :: [ConstraintNameDB] -> ShowS Source #
Eq ConstraintNameDB |
Instance details Defined in Database.Persist.Names Methods (==) :: ConstraintNameDB -> ConstraintNameDB -> Bool Source # (/=) :: ConstraintNameDB -> ConstraintNameDB -> Bool Source #
Ord ConstraintNameDB |

Instance details

Defined in Database.Persist.Names

Methods

compare :: ConstraintNameDB -> ConstraintNameDB -> Ordering Source #

(<) :: ConstraintNameDB -> ConstraintNameDB -> Bool Source #

(<=) :: ConstraintNameDB -> ConstraintNameDB -> Bool Source #

(>) :: ConstraintNameDB -> ConstraintNameDB -> Bool Source #

(>=) :: ConstraintNameDB -> ConstraintNameDB -> Bool Source #

max :: ConstraintNameDB -> ConstraintNameDB -> ConstraintNameDB Source #

min :: ConstraintNameDB -> ConstraintNameDB -> ConstraintNameDB Source #

DatabaseName ConstraintNameDB | Since: persistent-2.12.0.0
Instance details Defined in Database.Persist.Names Methods escapeWith :: (Text -> str) -> ConstraintNameDB -> str Source #
Lift ConstraintNameDB |
Instance details Defined in Database.Persist.Names Methods lift :: Quote m => ConstraintNameDB -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => ConstraintNameDB -> Code m ConstraintNameDB Source #

newtype EntityNameDB Source #

An `EntityNameDB` represents the datastore-side name that `persistent` will use for an entity.

Since: persistent-2.12.0.0

Constructors

EntityNameDB |

Fields

- unEntityNameDB :: Text

#### Instances

Instances details

Read EntityNameDB |
Instance details Defined in Database.Persist.Names Methods readsPrec :: Int -> ReadS EntityNameDB Source # readList :: ReadS [EntityNameDB] Source # readPrec :: ReadPrec EntityNameDB Source # readListPrec :: ReadPrec [EntityNameDB] Source #
Show EntityNameDB |
Instance details Defined in Database.Persist.Names Methods showsPrec :: Int -> EntityNameDB -> ShowS Source # show :: EntityNameDB -> String Source # showList :: [EntityNameDB] -> ShowS Source #
Eq EntityNameDB |
Instance details Defined in Database.Persist.Names Methods (==) :: EntityNameDB -> EntityNameDB -> Bool Source # (/=) :: EntityNameDB -> EntityNameDB -> Bool Source #
Ord EntityNameDB |

Instance details

Defined in Database.Persist.Names

Methods

compare :: EntityNameDB -> EntityNameDB -> Ordering Source #

(<) :: EntityNameDB -> EntityNameDB -> Bool Source #

(<=) :: EntityNameDB -> EntityNameDB -> Bool Source #

(>) :: EntityNameDB -> EntityNameDB -> Bool Source #

(>=) :: EntityNameDB -> EntityNameDB -> Bool Source #

max :: EntityNameDB -> EntityNameDB -> EntityNameDB Source #

min :: EntityNameDB -> EntityNameDB -> EntityNameDB Source #

DatabaseName EntityNameDB |
Instance details Defined in Database.Persist.Names Methods escapeWith :: (Text -> str) -> EntityNameDB -> str Source #
Lift EntityNameDB |
Instance details Defined in Database.Persist.Names Methods lift :: Quote m => EntityNameDB -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => EntityNameDB -> Code m EntityNameDB Source #

newtype EntityNameHS Source #

An `EntityNameHS` represents the Haskell-side name that `persistent` will use for an entity.

Since: persistent-2.12.0.0

Constructors

EntityNameHS |

Fields

- unEntityNameHS :: Text

#### Instances

Instances details

Read EntityNameHS |
Instance details Defined in Database.Persist.Names Methods readsPrec :: Int -> ReadS EntityNameHS Source # readList :: ReadS [EntityNameHS] Source # readPrec :: ReadPrec EntityNameHS Source # readListPrec :: ReadPrec [EntityNameHS] Source #
Show EntityNameHS |
Instance details Defined in Database.Persist.Names Methods showsPrec :: Int -> EntityNameHS -> ShowS Source # show :: EntityNameHS -> String Source # showList :: [EntityNameHS] -> ShowS Source #
Eq EntityNameHS |
Instance details Defined in Database.Persist.Names Methods (==) :: EntityNameHS -> EntityNameHS -> Bool Source # (/=) :: EntityNameHS -> EntityNameHS -> Bool Source #
Ord EntityNameHS |

Instance details

Defined in Database.Persist.Names

Methods

compare :: EntityNameHS -> EntityNameHS -> Ordering Source #

(<) :: EntityNameHS -> EntityNameHS -> Bool Source #

(<=) :: EntityNameHS -> EntityNameHS -> Bool Source #

(>) :: EntityNameHS -> EntityNameHS -> Bool Source #

(>=) :: EntityNameHS -> EntityNameHS -> Bool Source #

max :: EntityNameHS -> EntityNameHS -> EntityNameHS Source #

min :: EntityNameHS -> EntityNameHS -> EntityNameHS Source #

Lift EntityNameHS |
Instance details Defined in Database.Persist.Names Methods lift :: Quote m => EntityNameHS -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => EntityNameHS -> Code m EntityNameHS Source #

newtype FieldNameHS Source #

A `FieldNameHS` represents the Haskell-side name that `persistent` will use for a field.

Since: persistent-2.12.0.0

Constructors

FieldNameHS |

Fields

- unFieldNameHS :: Text

#### Instances

Instances details

Read FieldNameHS |
Instance details Defined in Database.Persist.Names Methods readsPrec :: Int -> ReadS FieldNameHS Source # readList :: ReadS [FieldNameHS] Source # readPrec :: ReadPrec FieldNameHS Source # readListPrec :: ReadPrec [FieldNameHS] Source #
Show FieldNameHS |
Instance details Defined in Database.Persist.Names Methods showsPrec :: Int -> FieldNameHS -> ShowS Source # show :: FieldNameHS -> String Source # showList :: [FieldNameHS] -> ShowS Source #
Eq FieldNameHS |
Instance details Defined in Database.Persist.Names Methods (==) :: FieldNameHS -> FieldNameHS -> Bool Source # (/=) :: FieldNameHS -> FieldNameHS -> Bool Source #
Ord FieldNameHS |

Instance details

Defined in Database.Persist.Names

Methods

compare :: FieldNameHS -> FieldNameHS -> Ordering Source #

(<) :: FieldNameHS -> FieldNameHS -> Bool Source #

(<=) :: FieldNameHS -> FieldNameHS -> Bool Source #

(>) :: FieldNameHS -> FieldNameHS -> Bool Source #

(>=) :: FieldNameHS -> FieldNameHS -> Bool Source #

max :: FieldNameHS -> FieldNameHS -> FieldNameHS Source #

min :: FieldNameHS -> FieldNameHS -> FieldNameHS Source #

Lift FieldNameHS |
Instance details Defined in Database.Persist.Names Methods lift :: Quote m => FieldNameHS -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => FieldNameHS -> Code m FieldNameHS Source #

newtype FieldNameDB Source #

A `FieldNameDB` represents the datastore-side name that `persistent` will use for a field.

Since: persistent-2.12.0.0

Constructors

FieldNameDB |

Fields

- unFieldNameDB :: Text

#### Instances

Instances details

Read FieldNameDB |
Instance details Defined in Database.Persist.Names Methods readsPrec :: Int -> ReadS FieldNameDB Source # readList :: ReadS [FieldNameDB] Source # readPrec :: ReadPrec FieldNameDB Source # readListPrec :: ReadPrec [FieldNameDB] Source #
Show FieldNameDB |
Instance details Defined in Database.Persist.Names Methods showsPrec :: Int -> FieldNameDB -> ShowS Source # show :: FieldNameDB -> String Source # showList :: [FieldNameDB] -> ShowS Source #
Eq FieldNameDB |
Instance details Defined in Database.Persist.Names Methods (==) :: FieldNameDB -> FieldNameDB -> Bool Source # (/=) :: FieldNameDB -> FieldNameDB -> Bool Source #
Ord FieldNameDB |

Instance details

Defined in Database.Persist.Names

Methods

compare :: FieldNameDB -> FieldNameDB -> Ordering Source #

(<) :: FieldNameDB -> FieldNameDB -> Bool Source #

(<=) :: FieldNameDB -> FieldNameDB -> Bool Source #

(>) :: FieldNameDB -> FieldNameDB -> Bool Source #

(>=) :: FieldNameDB -> FieldNameDB -> Bool Source #

max :: FieldNameDB -> FieldNameDB -> FieldNameDB Source #

min :: FieldNameDB -> FieldNameDB -> FieldNameDB Source #

DatabaseName FieldNameDB | Since: persistent-2.12.0.0
Instance details Defined in Database.Persist.Names Methods escapeWith :: (Text -> str) -> FieldNameDB -> str Source #
Lift FieldNameDB |
Instance details Defined in Database.Persist.Names Methods lift :: Quote m => FieldNameDB -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => FieldNameDB -> Code m FieldNameDB Source #

class DatabaseName a where Source #

Convenience operations for working with '-NameDB' types.

Since: persistent-2.12.0.0

Methods

escapeWith :: (Text -> str) -> a -> str Source #

#### Instances

Instances details

DatabaseName ConstraintNameDB | Since: persistent-2.12.0.0
Instance details Defined in Database.Persist.Names Methods escapeWith :: (Text -> str) -> ConstraintNameDB -> str Source #
DatabaseName EntityNameDB |
Instance details Defined in Database.Persist.Names Methods escapeWith :: (Text -> str) -> EntityNameDB -> str Source #
DatabaseName FieldNameDB | Since: persistent-2.12.0.0
Instance details Defined in Database.Persist.Names Methods escapeWith :: (Text -> str) -> FieldNameDB -> str Source #

data LiteralType Source #

A type that determines how a backend should handle the literal.

Since: persistent-2.12.0.0

Constructors

Escaped | The accompanying value will be escaped before inserting into the database. This is the correct default choice to use. Since: persistent-2.12.0.0
Unescaped | The accompanying value will not be escaped when inserting into the database. This is potentially dangerous - use this with care. Since: persistent-2.12.0.0
DbSpecific | The `DbSpecific` constructor corresponds to the legacy `PersistDbSpecific` constructor. We need to keep this around because old databases may have serialized JSON representations that reference this. We don't want to break the ability of a database to load rows. Since: persistent-2.12.0.0

#### Instances

Instances details

Read LiteralType |
Instance details Defined in Database.Persist.PersistValue Methods readsPrec :: Int -> ReadS LiteralType Source # readList :: ReadS [LiteralType] Source # readPrec :: ReadPrec LiteralType Source # readListPrec :: ReadPrec [LiteralType] Source #
Show LiteralType |
Instance details Defined in Database.Persist.PersistValue Methods showsPrec :: Int -> LiteralType -> ShowS Source # show :: LiteralType -> String Source # showList :: [LiteralType] -> ShowS Source #
Eq LiteralType |
Instance details Defined in Database.Persist.PersistValue Methods (==) :: LiteralType -> LiteralType -> Bool Source # (/=) :: LiteralType -> LiteralType -> Bool Source #
Ord LiteralType |

Instance details

Defined in Database.Persist.PersistValue

Methods

compare :: LiteralType -> LiteralType -> Ordering Source #

(<) :: LiteralType -> LiteralType -> Bool Source #

(<=) :: LiteralType -> LiteralType -> Bool Source #

(>) :: LiteralType -> LiteralType -> Bool Source #

(>=) :: LiteralType -> LiteralType -> Bool Source #

max :: LiteralType -> LiteralType -> LiteralType Source #

min :: LiteralType -> LiteralType -> LiteralType Source #

data PersistValue Source #

A raw value which can be stored in any backend and can be marshalled to and from a `PersistField`.

Constructors

PersistText Text |
PersistByteString ByteString |
PersistInt64 Int64 |
PersistDouble Double |
PersistRational Rational |
PersistBool Bool |
PersistDay Day |
PersistTimeOfDay TimeOfDay |
PersistUTCTime UTCTime |
PersistNull |
PersistList [PersistValue] |
PersistMap [(Text, PersistValue)] |
PersistObjectId ByteString | Intended especially for MongoDB backend
PersistArray [PersistValue] | Intended especially for PostgreSQL backend for text arrays
PersistLiteral_ LiteralType ByteString | This constructor is used to specify some raw literal value for the backend. The `LiteralType` value specifies how the value should be escaped. This can be used to make special, custom types avaialable in the back end. Since: persistent-2.12.0.0

Bundled Patterns

pattern PersistDbSpecific :: ByteString -> PersistValue

This pattern synonym used to be a data constructor for the `PersistValue` type. It was changed to be a pattern so that JSON-encoded database values could be parsed into their corresponding values. You should not use this, and instead prefer to pattern match on `PersistLiteral_` directly.

If you use this, it will overlap a patern match on the 'PersistLiteral_, `PersistLiteral`, and `PersistLiteralEscaped` patterns. If you need to disambiguate between these constructors, pattern match on `PersistLiteral_` directly.

Since: persistent-2.12.0.0

pattern PersistLiteralEscaped :: ByteString -> PersistValue | This pattern synonym used to be a data constructor on `PersistValue`, but was changed into a catch-all pattern synonym to allow backwards compatiblity with database types. See the documentation on `PersistDbSpecific` for more details. Since: persistent-2.12.0.0
pattern PersistLiteral :: ByteString -> PersistValue | This pattern synonym used to be a data constructor on `PersistValue`, but was changed into a catch-all pattern synonym to allow backwards compatiblity with database types. See the documentation on `PersistDbSpecific` for more details. Since: persistent-2.12.0.0

#### Instances

Instances details

FromJSON PersistValue |
Instance details Defined in Database.Persist.PersistValue Methods parseJSON :: Value -> Parser PersistValue Source # parseJSONList :: Value -> Parser [PersistValue] Source #
ToJSON PersistValue |
Instance details Defined in Database.Persist.PersistValue Methods toJSON :: PersistValue -> Value Source # toEncoding :: PersistValue -> Encoding Source # toJSONList :: [PersistValue] -> Value Source # toEncodingList :: [PersistValue] -> Encoding Source #
Read PersistValue |
Instance details Defined in Database.Persist.PersistValue Methods readsPrec :: Int -> ReadS PersistValue Source # readList :: ReadS [PersistValue] Source # readPrec :: ReadPrec PersistValue Source # readListPrec :: ReadPrec [PersistValue] Source #
Show PersistValue |
Instance details Defined in Database.Persist.PersistValue Methods showsPrec :: Int -> PersistValue -> ShowS Source # show :: PersistValue -> String Source # showList :: [PersistValue] -> ShowS Source #
NFData PersistValue | Since: persistent-2.14.4.0
Instance details Defined in Database.Persist.PersistValue Methods rnf :: PersistValue -> () Source #
Eq PersistValue |
Instance details Defined in Database.Persist.PersistValue Methods (==) :: PersistValue -> PersistValue -> Bool Source # (/=) :: PersistValue -> PersistValue -> Bool Source #
Ord PersistValue |

Instance details

Defined in Database.Persist.PersistValue

Methods

compare :: PersistValue -> PersistValue -> Ordering Source #

(<) :: PersistValue -> PersistValue -> Bool Source #

(<=) :: PersistValue -> PersistValue -> Bool Source #

(>) :: PersistValue -> PersistValue -> Bool Source #

(>=) :: PersistValue -> PersistValue -> Bool Source #

max :: PersistValue -> PersistValue -> PersistValue Source #

min :: PersistValue -> PersistValue -> PersistValue Source #

FromHttpApiData PersistValue |
Instance details Defined in Database.Persist.PersistValue Methods parseUrlPiece :: Text -> Either Text PersistValue parseHeader :: ByteString -> Either Text PersistValue parseQueryParam :: Text -> Either Text PersistValue
ToHttpApiData PersistValue |
Instance details Defined in Database.Persist.PersistValue Methods toUrlPiece :: PersistValue -> Text toEncodedUrlPiece :: PersistValue -> Builder toHeader :: PersistValue -> ByteString toQueryParam :: PersistValue -> Text
PathPiece PersistValue |
Instance details Defined in Database.Persist.PersistValue Methods fromPathPiece :: Text -> Maybe PersistValue toPathPiece :: PersistValue -> Text
PersistField PersistValue |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: PersistValue -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text PersistValue Source #
PersistFieldSql PersistValue |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy PersistValue -> SqlType Source #

data IsolationLevel Source #

Please refer to the documentation for the database in question for a full overview of the semantics of the varying isloation levels

Constructors

ReadUncommitted |
ReadCommitted |
RepeatableRead |
Serializable |

#### Instances

Instances details

Bounded IsolationLevel |
Instance details Defined in Database.Persist.SqlBackend.Internal.IsolationLevel Methods minBound :: IsolationLevel Source # maxBound :: IsolationLevel Source #
Enum IsolationLevel |

Instance details

Defined in Database.Persist.SqlBackend.Internal.IsolationLevel

Methods

succ :: IsolationLevel -> IsolationLevel Source #

pred :: IsolationLevel -> IsolationLevel Source #

toEnum :: Int -> IsolationLevel Source #

fromEnum :: IsolationLevel -> Int Source #

enumFrom :: IsolationLevel -> [IsolationLevel] Source #

enumFromThen :: IsolationLevel -> IsolationLevel -> [IsolationLevel] Source #

enumFromTo :: IsolationLevel -> IsolationLevel -> [IsolationLevel] Source #

enumFromThenTo :: IsolationLevel -> IsolationLevel -> IsolationLevel -> [IsolationLevel] Source #

Show IsolationLevel |
Instance details Defined in Database.Persist.SqlBackend.Internal.IsolationLevel Methods showsPrec :: Int -> IsolationLevel -> ShowS Source # show :: IsolationLevel -> String Source # showList :: [IsolationLevel] -> ShowS Source #
Eq IsolationLevel |
Instance details Defined in Database.Persist.SqlBackend.Internal.IsolationLevel Methods (==) :: IsolationLevel -> IsolationLevel -> Bool Source # (/=) :: IsolationLevel -> IsolationLevel -> Bool Source #
Ord IsolationLevel |

Instance details

Defined in Database.Persist.SqlBackend.Internal.IsolationLevel

Methods

compare :: IsolationLevel -> IsolationLevel -> Ordering Source #

(<) :: IsolationLevel -> IsolationLevel -> Bool Source #

(<=) :: IsolationLevel -> IsolationLevel -> Bool Source #

(>) :: IsolationLevel -> IsolationLevel -> Bool Source #

(>=) :: IsolationLevel -> IsolationLevel -> Bool Source #

max :: IsolationLevel -> IsolationLevel -> IsolationLevel Source #

min :: IsolationLevel -> IsolationLevel -> IsolationLevel Source #

data FieldDef Source #

A `FieldDef` represents the inormation that `persistent` knows about a field of a datatype. This includes information used to parse the field out of the database and what the field corresponds to.

Constructors

FieldDef |

Fields

- fieldHaskell :: !FieldNameHS

  The name of the field. Note that this does not corresponds to the record labels generated for the particular entity - record labels are generated with the type name prefixed to the field, so a `FieldDef` that contains a ``FieldNameHS` "name"` for a type `User` will have a record field `userName`.

- fieldDB :: !FieldNameDB

  The name of the field in the database. For SQL databases, this corresponds to the column name.

- fieldType :: !FieldType

  The type of the field in Haskell.

- fieldSqlType :: !SqlType

  The type of the field in a SQL database.

- fieldAttrs :: ![FieldAttr]

  User annotations for a field. These are provided with the `!` operator.

- fieldStrict :: !Bool

  If this is `True`, then the Haskell datatype will have a strict record field. The default value for this is `True`.

- fieldReference :: !ReferenceDef
- fieldCascade :: !FieldCascade

  Defines how operations on the field cascade on to the referenced tables. This doesn't have any meaning if the `fieldReference` is set to `NoReference` or `SelfReference`. The cascade option here should be the same as the one obtained in the `fieldReference`.

  Since: persistent-2.11.0

- fieldComments :: !(Maybe Text)

  Optional comments for a `Field`.

  Since: persistent-2.10.0

- fieldGenerated :: !(Maybe Text)

  Whether or not the field is a `GENERATED` column, and additionally the expression to use for generation.

  Since: persistent-2.11.0.0

- fieldIsImplicitIdColumn :: !Bool

  `True` if the field is an implicit ID column. `False` otherwise.

  Since: persistent-2.13.0.0

#### Instances

Instances details

Read FieldDef |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS FieldDef Source # readList :: ReadS [FieldDef] Source # readPrec :: ReadPrec FieldDef Source # readListPrec :: ReadPrec [FieldDef] Source #
Show FieldDef |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> FieldDef -> ShowS Source # show :: FieldDef -> String Source # showList :: [FieldDef] -> ShowS Source #
Eq FieldDef |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: FieldDef -> FieldDef -> Bool Source # (/=) :: FieldDef -> FieldDef -> Bool Source #
Ord FieldDef |
Instance details Defined in Database.Persist.Types.Base Methods compare :: FieldDef -> FieldDef -> Ordering Source # (<) :: FieldDef -> FieldDef -> Bool Source # (<=) :: FieldDef -> FieldDef -> Bool Source # (>) :: FieldDef -> FieldDef -> Bool Source # (>=) :: FieldDef -> FieldDef -> Bool Source # max :: FieldDef -> FieldDef -> FieldDef Source # min :: FieldDef -> FieldDef -> FieldDef Source #
Lift FieldDef |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => FieldDef -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => FieldDef -> Code m FieldDef Source #

data PersistUpdate Source #

Constructors

Assign |
Add |
Subtract |
Multiply |
Divide |
BackendSpecificUpdate Text |

#### Instances

Instances details

Read PersistUpdate |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS PersistUpdate Source # readList :: ReadS [PersistUpdate] Source # readPrec :: ReadPrec PersistUpdate Source # readListPrec :: ReadPrec [PersistUpdate] Source #
Show PersistUpdate |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> PersistUpdate -> ShowS Source # show :: PersistUpdate -> String Source # showList :: [PersistUpdate] -> ShowS Source #
Lift PersistUpdate |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => PersistUpdate -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => PersistUpdate -> Code m PersistUpdate Source #

type family BackendSpecificUpdate backend record Source #

data UpdateException Source #

Constructors

KeyNotFound String |
UpsertError String |

#### Instances

Instances details

Exception UpdateException |
Instance details Defined in Database.Persist.Types.Base Methods toException :: UpdateException -> SomeException Source # fromException :: SomeException -> Maybe UpdateException Source # displayException :: UpdateException -> String Source #
Show UpdateException |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> UpdateException -> ShowS Source # show :: UpdateException -> String Source # showList :: [UpdateException] -> ShowS Source #

data PersistFilter Source #

Constructors

Eq |
Ne |
Gt |
Lt |
Ge |
Le |
In |
NotIn |

#### Instances

Instances details

Read PersistFilter |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS PersistFilter Source # readList :: ReadS [PersistFilter] Source # readPrec :: ReadPrec PersistFilter Source # readListPrec :: ReadPrec [PersistFilter] Source #
Show PersistFilter |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> PersistFilter -> ShowS Source # show :: PersistFilter -> String Source # showList :: [PersistFilter] -> ShowS Source #
Lift PersistFilter |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => PersistFilter -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => PersistFilter -> Code m PersistFilter Source #

data SqlType Source #

A SQL data type. Naming attempts to reflect the underlying Haskell datatypes, eg SqlString instead of SqlVarchar. Different SQL databases may have different translations for these types.

Constructors

SqlString |
SqlInt32 |
SqlInt64 |
SqlReal |
SqlNumeric Word32 Word32 |
SqlBool |
SqlDay |
SqlTime |
SqlDayTime | Always uses UTC timezone
SqlBlob |
SqlOther Text | a backend-specific name

#### Instances

Instances details

Read SqlType |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS SqlType Source # readList :: ReadS [SqlType] Source # readPrec :: ReadPrec SqlType Source # readListPrec :: ReadPrec [SqlType] Source #
Show SqlType |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> SqlType -> ShowS Source # show :: SqlType -> String Source # showList :: [SqlType] -> ShowS Source #
Eq SqlType |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: SqlType -> SqlType -> Bool Source # (/=) :: SqlType -> SqlType -> Bool Source #
Ord SqlType |
Instance details Defined in Database.Persist.Types.Base Methods compare :: SqlType -> SqlType -> Ordering Source # (<) :: SqlType -> SqlType -> Bool Source # (<=) :: SqlType -> SqlType -> Bool Source # (>) :: SqlType -> SqlType -> Bool Source # (>=) :: SqlType -> SqlType -> Bool Source # max :: SqlType -> SqlType -> SqlType Source # min :: SqlType -> SqlType -> SqlType Source #
Lift SqlType |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => SqlType -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => SqlType -> Code m SqlType Source #

data PersistException Source #

Constructors

PersistError Text | Generic Exception
PersistMarshalError Text |
PersistInvalidField Text |
PersistForeignConstraintUnmet Text |
PersistMongoDBError Text |
PersistMongoDBUnsupported Text |

#### Instances

Instances details

Exception PersistException |
Instance details Defined in Database.Persist.Types.Base Methods toException :: PersistException -> SomeException Source # fromException :: SomeException -> Maybe PersistException Source # displayException :: PersistException -> String Source #
Show PersistException |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> PersistException -> ShowS Source # show :: PersistException -> String Source # showList :: [PersistException] -> ShowS Source #

data CascadeAction Source #

An action that might happen on a deletion or update on a foreign key change.

Since: persistent-2.11.0

Constructors

Cascade |
Restrict |
SetNull |
SetDefault |

#### Instances

Instances details

Read CascadeAction |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS CascadeAction Source # readList :: ReadS [CascadeAction] Source # readPrec :: ReadPrec CascadeAction Source # readListPrec :: ReadPrec [CascadeAction] Source #
Show CascadeAction |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> CascadeAction -> ShowS Source # show :: CascadeAction -> String Source # showList :: [CascadeAction] -> ShowS Source #
Eq CascadeAction |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: CascadeAction -> CascadeAction -> Bool Source # (/=) :: CascadeAction -> CascadeAction -> Bool Source #
Ord CascadeAction |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: CascadeAction -> CascadeAction -> Ordering Source #

(<) :: CascadeAction -> CascadeAction -> Bool Source #

(<=) :: CascadeAction -> CascadeAction -> Bool Source #

(>) :: CascadeAction -> CascadeAction -> Bool Source #

(>=) :: CascadeAction -> CascadeAction -> Bool Source #

max :: CascadeAction -> CascadeAction -> CascadeAction Source #

min :: CascadeAction -> CascadeAction -> CascadeAction Source #

Lift CascadeAction |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => CascadeAction -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => CascadeAction -> Code m CascadeAction Source #

data FieldCascade Source #

This datatype describes how a foreign reference field cascades deletes or updates.

This type is used in both parsing the model definitions and performing migrations. A `Nothing` in either of the field values means that the user has not specified a `CascadeAction`. An unspecified `CascadeAction` is defaulted to `Restrict` when doing migrations.

Since: persistent-2.11.0

Constructors

FieldCascade |

Fields

- fcOnUpdate :: !(Maybe CascadeAction)
- fcOnDelete :: !(Maybe CascadeAction)

#### Instances

Instances details

Read FieldCascade |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS FieldCascade Source # readList :: ReadS [FieldCascade] Source # readPrec :: ReadPrec FieldCascade Source # readListPrec :: ReadPrec [FieldCascade] Source #
Show FieldCascade |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> FieldCascade -> ShowS Source # show :: FieldCascade -> String Source # showList :: [FieldCascade] -> ShowS Source #
Eq FieldCascade |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: FieldCascade -> FieldCascade -> Bool Source # (/=) :: FieldCascade -> FieldCascade -> Bool Source #
Ord FieldCascade |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: FieldCascade -> FieldCascade -> Ordering Source #

(<) :: FieldCascade -> FieldCascade -> Bool Source #

(<=) :: FieldCascade -> FieldCascade -> Bool Source #

(>) :: FieldCascade -> FieldCascade -> Bool Source #

(>=) :: FieldCascade -> FieldCascade -> Bool Source #

max :: FieldCascade -> FieldCascade -> FieldCascade Source #

min :: FieldCascade -> FieldCascade -> FieldCascade Source #

Lift FieldCascade |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => FieldCascade -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => FieldCascade -> Code m FieldCascade Source #

data ForeignDef Source #

Constructors

ForeignDef |

Fields

- foreignRefTableHaskell :: !EntityNameHS
- foreignRefTableDBName :: !EntityNameDB
- foreignConstraintNameHaskell :: !ConstraintNameHS
- foreignConstraintNameDBName :: !ConstraintNameDB
- foreignFieldCascade :: !FieldCascade

  Determine how the field will cascade on updates and deletions.

  Since: persistent-2.11.0

- foreignFields :: ![(ForeignFieldDef, ForeignFieldDef)]
- foreignAttrs :: ![Attr]
- foreignNullable :: Bool
- foreignToPrimary :: Bool

  Determines if the reference is towards a Primary Key or not.

  Since: persistent-2.11.0

#### Instances

Instances details

Read ForeignDef |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS ForeignDef Source # readList :: ReadS [ForeignDef] Source # readPrec :: ReadPrec ForeignDef Source # readListPrec :: ReadPrec [ForeignDef] Source #
Show ForeignDef |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> ForeignDef -> ShowS Source # show :: ForeignDef -> String Source # showList :: [ForeignDef] -> ShowS Source #
Eq ForeignDef |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: ForeignDef -> ForeignDef -> Bool Source # (/=) :: ForeignDef -> ForeignDef -> Bool Source #
Ord ForeignDef |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: ForeignDef -> ForeignDef -> Ordering Source #

(<) :: ForeignDef -> ForeignDef -> Bool Source #

(<=) :: ForeignDef -> ForeignDef -> Bool Source #

(>) :: ForeignDef -> ForeignDef -> Bool Source #

(>=) :: ForeignDef -> ForeignDef -> Bool Source #

max :: ForeignDef -> ForeignDef -> ForeignDef Source #

min :: ForeignDef -> ForeignDef -> ForeignDef Source #

Lift ForeignDef |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => ForeignDef -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => ForeignDef -> Code m ForeignDef Source #

type ForeignFieldDef = (FieldNameHS, FieldNameDB) Source #

Used instead of FieldDef to generate a smaller amount of code

data CompositeDef Source #

Constructors

CompositeDef |

Fields

- compositeFields :: !(NonEmpty FieldDef)
- compositeAttrs :: ![Attr]

#### Instances

Instances details

Read CompositeDef |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS CompositeDef Source # readList :: ReadS [CompositeDef] Source # readPrec :: ReadPrec CompositeDef Source # readListPrec :: ReadPrec [CompositeDef] Source #
Show CompositeDef |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> CompositeDef -> ShowS Source # show :: CompositeDef -> String Source # showList :: [CompositeDef] -> ShowS Source #
Eq CompositeDef |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: CompositeDef -> CompositeDef -> Bool Source # (/=) :: CompositeDef -> CompositeDef -> Bool Source #
Ord CompositeDef |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: CompositeDef -> CompositeDef -> Ordering Source #

(<) :: CompositeDef -> CompositeDef -> Bool Source #

(<=) :: CompositeDef -> CompositeDef -> Bool Source #

(>) :: CompositeDef -> CompositeDef -> Bool Source #

(>=) :: CompositeDef -> CompositeDef -> Bool Source #

max :: CompositeDef -> CompositeDef -> CompositeDef Source #

min :: CompositeDef -> CompositeDef -> CompositeDef Source #

Lift CompositeDef |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => CompositeDef -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => CompositeDef -> Code m CompositeDef Source #

data UniqueDef Source #

Type for storing the Uniqueness constraint in the Schema. Assume you have the following schema with a uniqueness constraint:

    Person
      name String
      age Int
      UniqueAge age

This will be represented as:

    UniqueDef
        { uniqueHaskell = ConstraintNameHS (packPTH UniqueAge)
        , uniqueDBName = ConstraintNameDB (packPTH "unique_age")
        , uniqueFields = [(FieldNameHS (packPTH "age"), FieldNameDB (packPTH "age"))]
        , uniqueAttrs = []
        }

Constructors

UniqueDef |

Fields

- uniqueHaskell :: !ConstraintNameHS
- uniqueDBName :: !ConstraintNameDB
- uniqueFields :: !(NonEmpty (FieldNameHS, FieldNameDB))
- uniqueAttrs :: ![Attr]

#### Instances

Instances details

Read UniqueDef |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS UniqueDef Source # readList :: ReadS [UniqueDef] Source # readPrec :: ReadPrec UniqueDef Source # readListPrec :: ReadPrec [UniqueDef] Source #
Show UniqueDef |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> UniqueDef -> ShowS Source # show :: UniqueDef -> String Source # showList :: [UniqueDef] -> ShowS Source #
Eq UniqueDef |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: UniqueDef -> UniqueDef -> Bool Source # (/=) :: UniqueDef -> UniqueDef -> Bool Source #
Ord UniqueDef |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: UniqueDef -> UniqueDef -> Ordering Source #

(<) :: UniqueDef -> UniqueDef -> Bool Source #

(<=) :: UniqueDef -> UniqueDef -> Bool Source #

(>) :: UniqueDef -> UniqueDef -> Bool Source #

(>=) :: UniqueDef -> UniqueDef -> Bool Source #

max :: UniqueDef -> UniqueDef -> UniqueDef Source #

min :: UniqueDef -> UniqueDef -> UniqueDef Source #

Lift UniqueDef |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => UniqueDef -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => UniqueDef -> Code m UniqueDef Source #

data EmbedFieldDef Source #

An EmbedFieldDef is the same as a FieldDef But it is only used for embeddedFields so it only has data needed for embedding

Constructors

EmbedFieldDef |

Fields

- emFieldDB :: FieldNameDB
- emFieldEmbed :: Maybe (Either SelfEmbed EntityNameHS)

#### Instances

Instances details

Read EmbedFieldDef |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS EmbedFieldDef Source # readList :: ReadS [EmbedFieldDef] Source # readPrec :: ReadPrec EmbedFieldDef Source # readListPrec :: ReadPrec [EmbedFieldDef] Source #
Show EmbedFieldDef |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> EmbedFieldDef -> ShowS Source # show :: EmbedFieldDef -> String Source # showList :: [EmbedFieldDef] -> ShowS Source #
Eq EmbedFieldDef |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: EmbedFieldDef -> EmbedFieldDef -> Bool Source # (/=) :: EmbedFieldDef -> EmbedFieldDef -> Bool Source #
Ord EmbedFieldDef |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: EmbedFieldDef -> EmbedFieldDef -> Ordering Source #

(<) :: EmbedFieldDef -> EmbedFieldDef -> Bool Source #

(<=) :: EmbedFieldDef -> EmbedFieldDef -> Bool Source #

(>) :: EmbedFieldDef -> EmbedFieldDef -> Bool Source #

(>=) :: EmbedFieldDef -> EmbedFieldDef -> Bool Source #

max :: EmbedFieldDef -> EmbedFieldDef -> EmbedFieldDef Source #

min :: EmbedFieldDef -> EmbedFieldDef -> EmbedFieldDef Source #

Lift EmbedFieldDef |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => EmbedFieldDef -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => EmbedFieldDef -> Code m EmbedFieldDef Source #

data EmbedEntityDef Source #

An EmbedEntityDef is the same as an EntityDef But it is only used for fieldReference so it only has data needed for embedding

Constructors

EmbedEntityDef |

Fields

- embeddedHaskell :: EntityNameHS
- embeddedFields :: [EmbedFieldDef]

#### Instances

Instances details

Read EmbedEntityDef |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS EmbedEntityDef Source # readList :: ReadS [EmbedEntityDef] Source # readPrec :: ReadPrec EmbedEntityDef Source # readListPrec :: ReadPrec [EmbedEntityDef] Source #
Show EmbedEntityDef |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> EmbedEntityDef -> ShowS Source # show :: EmbedEntityDef -> String Source # showList :: [EmbedEntityDef] -> ShowS Source #
Eq EmbedEntityDef |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: EmbedEntityDef -> EmbedEntityDef -> Bool Source # (/=) :: EmbedEntityDef -> EmbedEntityDef -> Bool Source #
Ord EmbedEntityDef |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: EmbedEntityDef -> EmbedEntityDef -> Ordering Source #

(<) :: EmbedEntityDef -> EmbedEntityDef -> Bool Source #

(<=) :: EmbedEntityDef -> EmbedEntityDef -> Bool Source #

(>) :: EmbedEntityDef -> EmbedEntityDef -> Bool Source #

(>=) :: EmbedEntityDef -> EmbedEntityDef -> Bool Source #

max :: EmbedEntityDef -> EmbedEntityDef -> EmbedEntityDef Source #

min :: EmbedEntityDef -> EmbedEntityDef -> EmbedEntityDef Source #

Lift EmbedEntityDef |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => EmbedEntityDef -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => EmbedEntityDef -> Code m EmbedEntityDef Source #

data ReferenceDef Source #

There are 3 kinds of references 1) composite (to fields that exist in the record) 2) single field 3) embedded

Constructors

NoReference |
ForeignRef !EntityNameHS | A ForeignRef has a late binding to the EntityDef it references via name and has the Haskell type of the foreign key in the form of FieldType
EmbedRef EntityNameHS |
SelfReference | A SelfReference stops an immediate cycle which causes non-termination at compile-time (issue #311).

#### Instances

Instances details

Read ReferenceDef |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS ReferenceDef Source # readList :: ReadS [ReferenceDef] Source # readPrec :: ReadPrec ReferenceDef Source # readListPrec :: ReadPrec [ReferenceDef] Source #
Show ReferenceDef |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> ReferenceDef -> ShowS Source # show :: ReferenceDef -> String Source # showList :: [ReferenceDef] -> ShowS Source #
Eq ReferenceDef |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: ReferenceDef -> ReferenceDef -> Bool Source # (/=) :: ReferenceDef -> ReferenceDef -> Bool Source #
Ord ReferenceDef |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: ReferenceDef -> ReferenceDef -> Ordering Source #

(<) :: ReferenceDef -> ReferenceDef -> Bool Source #

(<=) :: ReferenceDef -> ReferenceDef -> Bool Source #

(>) :: ReferenceDef -> ReferenceDef -> Bool Source #

(>=) :: ReferenceDef -> ReferenceDef -> Bool Source #

max :: ReferenceDef -> ReferenceDef -> ReferenceDef Source #

min :: ReferenceDef -> ReferenceDef -> ReferenceDef Source #

Lift ReferenceDef |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => ReferenceDef -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => ReferenceDef -> Code m ReferenceDef Source #

data FieldType Source #

A `FieldType` describes a field parsed from the QuasiQuoter and is used to determine the Haskell type in the generated code.

`name Text` parses into `FTTypeCon Nothing Text`

`name T.Text` parses into `FTTypeCon (Just T Text)`

`name (Jsonb User)` parses into:

    FTApp (FTTypeCon Nothing Jsonb) (FTTypeCon Nothing User)

Constructors

FTTypeCon (Maybe Text) Text | Optional module and name.
FTLit FieldTypeLit |
FTTypePromoted Text |
FTApp FieldType FieldType |
FTList FieldType |

#### Instances

Instances details

Read FieldType |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS FieldType Source # readList :: ReadS [FieldType] Source # readPrec :: ReadPrec FieldType Source # readListPrec :: ReadPrec [FieldType] Source #
Show FieldType |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> FieldType -> ShowS Source # show :: FieldType -> String Source # showList :: [FieldType] -> ShowS Source #
Eq FieldType |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: FieldType -> FieldType -> Bool Source # (/=) :: FieldType -> FieldType -> Bool Source #
Ord FieldType |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: FieldType -> FieldType -> Ordering Source #

(<) :: FieldType -> FieldType -> Bool Source #

(<=) :: FieldType -> FieldType -> Bool Source #

(>) :: FieldType -> FieldType -> Bool Source #

(>=) :: FieldType -> FieldType -> Bool Source #

max :: FieldType -> FieldType -> FieldType Source #

min :: FieldType -> FieldType -> FieldType Source #

Lift FieldType |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => FieldType -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => FieldType -> Code m FieldType Source #

data FieldAttr Source #

Attributes that may be attached to fields that can affect migrations and serialization in backend-specific ways.

While we endeavor to, we can't forsee all use cases for all backends, and so `FieldAttr` is extensible through its constructor `FieldAttrOther`.

Since: persistent-2.11.0.0

Constructors

FieldAttrMaybe

The `Maybe` keyword goes after the type. This indicates that the column is nullable, and the generated Haskell code will have a ``Maybe`` type for it.

Example:

    User
        name Text Maybe

FieldAttrNullable

This indicates that the column is nullable, but should not have a `Maybe` type. For this to work out, you need to ensure that the `PersistField` instance for the type in question can support a `PersistNull` value.

    data What = NoWhat | Hello Text

    instance PersistField What where
        fromPersistValue PersistNull =
            pure NoWhat
        fromPersistValue pv =
            Hello $ fromPersistValue pv

    instance PersistFieldSql What where
        sqlType _ = SqlString

    User
        what What nullable

FieldAttrMigrationOnly

This tag means that the column will not be present on the Haskell code, but will not be removed from the database. Useful to deprecate fields in phases.

You should set the column to be nullable in the database. Otherwise, inserts won't have values.

    User
        oldName Text MigrationOnly
        newName Text

FieldAttrSafeToRemove

A `SafeToRemove` attribute is not present on the Haskell datatype, and the backend migrations should attempt to drop the column without triggering any unsafe migration warnings.

Useful after you've used `MigrationOnly` to remove a column from the database in phases.

    User
        oldName Text SafeToRemove
        newName Text

FieldAttrNoreference

This attribute indicates that we should not create a foreign key reference from a column. By default, `persistent` will try and create a foreign key reference for a column if it can determine that the type of the column is a ``Key` entity` or an `EntityId` and the `Entity`'s name was present in `mkPersist`.

This is useful if you want to use the explicit foreign key syntax.

    Post
        title    Text

    Comment
        postId   PostId      noreference
        Foreign Post fk_comment_post postId

FieldAttrReference Text

This is set to specify precisely the database table the column refers to.

    Post
        title    Text

    Comment
        postId   PostId references="post"

You should not need this - `persistent` should be capable of correctly determining the target table's name. If you do need this, please file an issue describing why.

FieldAttrConstraint Text

Specify a name for the constraint on the foreign key reference for this table.

    Post
        title    Text

    Comment
        postId   PostId constraint="my_cool_constraint_name"

FieldAttrDefault Text

Specify the default value for a column.

    User
        createdAt    UTCTime     default="NOW()"

Note that a `default=` attribute does not mean you can omit the value while inserting.

FieldAttrSqltype Text

Specify a custom SQL type for the column. Generally, you should define a custom datatype with a custom `PersistFieldSql` instance instead of using this.

    User
        uuid     Text    sqltype=UUID

FieldAttrMaxlen Integer

Set a maximum length for a column. Useful for VARCHAR and indexes.

    User
        name     Text    maxlen=200

        UniqueName name

FieldAttrSql Text

Specify the database name of the column.

    User
        blarghle     Int     sql="b_l_a_r_g_h_l_e"

Useful for performing phased migrations, where one column is renamed to another column over time.

FieldAttrOther Text | A grab bag of random attributes that were unrecognized by the parser.

#### Instances

Instances details

Read FieldAttr |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS FieldAttr Source # readList :: ReadS [FieldAttr] Source # readPrec :: ReadPrec FieldAttr Source # readListPrec :: ReadPrec [FieldAttr] Source #
Show FieldAttr |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> FieldAttr -> ShowS Source # show :: FieldAttr -> String Source # showList :: [FieldAttr] -> ShowS Source #
Eq FieldAttr |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: FieldAttr -> FieldAttr -> Bool Source # (/=) :: FieldAttr -> FieldAttr -> Bool Source #
Ord FieldAttr |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: FieldAttr -> FieldAttr -> Ordering Source #

(<) :: FieldAttr -> FieldAttr -> Bool Source #

(<=) :: FieldAttr -> FieldAttr -> Bool Source #

(>) :: FieldAttr -> FieldAttr -> Bool Source #

(>=) :: FieldAttr -> FieldAttr -> Bool Source #

max :: FieldAttr -> FieldAttr -> FieldAttr Source #

min :: FieldAttr -> FieldAttr -> FieldAttr Source #

Lift FieldAttr |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => FieldAttr -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => FieldAttr -> Code m FieldAttr Source #

type Attr = Text Source #

type ExtraLine = [Text] Source #

data EntityIdDef Source #

The definition for the entity's primary key ID.

Since: persistent-2.13.0.0

Constructors

EntityIdField !FieldDef | The entity has a single key column, and it is a surrogate key - that is, you can't go from `rec -> Key rec`. Since: persistent-2.13.0.0
EntityIdNaturalKey !CompositeDef | The entity has a natural key. This means you can write `rec -> Key rec` because all the key fields are present on the datatype. A natural key can have one or more columns. Since: persistent-2.13.0.0

#### Instances

Instances details

Read EntityIdDef |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS EntityIdDef Source # readList :: ReadS [EntityIdDef] Source # readPrec :: ReadPrec EntityIdDef Source # readListPrec :: ReadPrec [EntityIdDef] Source #
Show EntityIdDef |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> EntityIdDef -> ShowS Source # show :: EntityIdDef -> String Source # showList :: [EntityIdDef] -> ShowS Source #
Eq EntityIdDef |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: EntityIdDef -> EntityIdDef -> Bool Source # (/=) :: EntityIdDef -> EntityIdDef -> Bool Source #
Ord EntityIdDef |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: EntityIdDef -> EntityIdDef -> Ordering Source #

(<) :: EntityIdDef -> EntityIdDef -> Bool Source #

(<=) :: EntityIdDef -> EntityIdDef -> Bool Source #

(>) :: EntityIdDef -> EntityIdDef -> Bool Source #

(>=) :: EntityIdDef -> EntityIdDef -> Bool Source #

max :: EntityIdDef -> EntityIdDef -> EntityIdDef Source #

min :: EntityIdDef -> EntityIdDef -> EntityIdDef Source #

Lift EntityIdDef |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => EntityIdDef -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => EntityIdDef -> Code m EntityIdDef Source #

data EntityDef Source #

An `EntityDef` represents the information that `persistent` knows about an Entity. It uses this information to generate the Haskell datatype, the SQL migrations, and other relevant conversions.

#### Instances

Instances details

Read EntityDef |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS EntityDef Source # readList :: ReadS [EntityDef] Source # readPrec :: ReadPrec EntityDef Source # readListPrec :: ReadPrec [EntityDef] Source #
Show EntityDef |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> EntityDef -> ShowS Source # show :: EntityDef -> String Source # showList :: [EntityDef] -> ShowS Source #
Eq EntityDef |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: EntityDef -> EntityDef -> Bool Source # (/=) :: EntityDef -> EntityDef -> Bool Source #
Ord EntityDef |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: EntityDef -> EntityDef -> Ordering Source #

(<) :: EntityDef -> EntityDef -> Bool Source #

(<=) :: EntityDef -> EntityDef -> Bool Source #

(>) :: EntityDef -> EntityDef -> Bool Source #

(>=) :: EntityDef -> EntityDef -> Bool Source #

max :: EntityDef -> EntityDef -> EntityDef Source #

min :: EntityDef -> EntityDef -> EntityDef Source #

Lift EntityDef |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => EntityDef -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => EntityDef -> Code m EntityDef Source #

data WhyNullable Source #

The reason why a field is `nullable` is very important. A field that is nullable because of a `Maybe` tag will have its type changed from `A` to `Maybe A`. OTOH, a field that is nullable because of a `nullable` tag will remain with the same type.

Constructors

ByMaybeAttr |
ByNullableAttr |

#### Instances

Instances details

Show WhyNullable |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> WhyNullable -> ShowS Source # show :: WhyNullable -> String Source # showList :: [WhyNullable] -> ShowS Source #
Eq WhyNullable |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: WhyNullable -> WhyNullable -> Bool Source # (/=) :: WhyNullable -> WhyNullable -> Bool Source #

data IsNullable Source #

Constructors

Nullable !WhyNullable |
NotNullable |

#### Instances

Instances details

Show IsNullable |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> IsNullable -> ShowS Source # show :: IsNullable -> String Source # showList :: [IsNullable] -> ShowS Source #
Eq IsNullable |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: IsNullable -> IsNullable -> Bool Source # (/=) :: IsNullable -> IsNullable -> Bool Source #

data Checkmark Source #

A `Checkmark` should be used as a field type whenever a uniqueness constraint should guarantee that a certain kind of record may appear at most once, but other kinds of records may appear any number of times.

NOTE: You need to mark any `Checkmark` fields as `nullable` (see the following example).

For example, suppose there's a `Location` entity that represents where a user has lived:

    Location
        user    UserId
        name    Text
        current Checkmark nullable

        UniqueLocation user current

The `UniqueLocation` constraint allows any number of `Inactive` `Location`s to be `current`. However, there may be at most one `current` `Location` per user (i.e., either zero or one per user).

This data type works because of the way that SQL treats `NULL`able fields within uniqueness constraints. The SQL standard says that `NULL` values should be considered different, so we represent `Inactive` as SQL `NULL`, thus allowing any number of `Inactive` records. On the other hand, we represent `Active` as `TRUE`, so the uniqueness constraint will disallow more than one `Active` record.

Note: There may be DBMSs that do not respect the SQL standard's treatment of `NULL` values on uniqueness constraints, please check if this data type works before relying on it.

The SQL `BOOLEAN` type is used because it's the smallest data type available. Note that we never use `FALSE`, just `TRUE` and `NULL`. Provides the same behavior `Maybe ()` would if `()` was a valid `PersistField`.

Constructors

Active | When used on a uniqueness constraint, there may be at most one `Active` record.
Inactive | When used on a uniqueness constraint, there may be any number of `Inactive` records.

#### Instances

Instances details

Bounded Checkmark |
Instance details Defined in Database.Persist.Types.Base Methods minBound :: Checkmark Source # maxBound :: Checkmark Source #
Enum Checkmark |

Instance details

Defined in Database.Persist.Types.Base

Methods

succ :: Checkmark -> Checkmark Source #

pred :: Checkmark -> Checkmark Source #

toEnum :: Int -> Checkmark Source #

fromEnum :: Checkmark -> Int Source #

enumFrom :: Checkmark -> [Checkmark] Source #

enumFromThen :: Checkmark -> Checkmark -> [Checkmark] Source #

enumFromTo :: Checkmark -> Checkmark -> [Checkmark] Source #

enumFromThenTo :: Checkmark -> Checkmark -> Checkmark -> [Checkmark] Source #

Read Checkmark |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS Checkmark Source # readList :: ReadS [Checkmark] Source # readPrec :: ReadPrec Checkmark Source # readListPrec :: ReadPrec [Checkmark] Source #
Show Checkmark |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> Checkmark -> ShowS Source # show :: Checkmark -> String Source # showList :: [Checkmark] -> ShowS Source #
Eq Checkmark |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: Checkmark -> Checkmark -> Bool Source # (/=) :: Checkmark -> Checkmark -> Bool Source #
Ord Checkmark |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: Checkmark -> Checkmark -> Ordering Source #

(<) :: Checkmark -> Checkmark -> Bool Source #

(<=) :: Checkmark -> Checkmark -> Bool Source #

(>) :: Checkmark -> Checkmark -> Bool Source #

(>=) :: Checkmark -> Checkmark -> Bool Source #

max :: Checkmark -> Checkmark -> Checkmark Source #

min :: Checkmark -> Checkmark -> Checkmark Source #

FromHttpApiData Checkmark |
Instance details Defined in Database.Persist.Types.Base Methods parseUrlPiece :: Text -> Either Text Checkmark parseHeader :: ByteString -> Either Text Checkmark parseQueryParam :: Text -> Either Text Checkmark
ToHttpApiData Checkmark |
Instance details Defined in Database.Persist.Types.Base Methods toUrlPiece :: Checkmark -> Text toEncodedUrlPiece :: Checkmark -> Builder toHeader :: Checkmark -> ByteString toQueryParam :: Checkmark -> Text
PathPiece Checkmark |
Instance details Defined in Database.Persist.Types.Base Methods fromPathPiece :: Text -> Maybe Checkmark toPathPiece :: Checkmark -> Text
PersistField Checkmark |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Checkmark -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Checkmark Source #
PersistFieldSql Checkmark |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy Checkmark -> SqlType Source #

data Statement Source #

A `Statement` is a representation of a database query that has been prepared and stored on the server side.

Constructors

Statement |

Fields

- stmtFinalize :: IO ()
- stmtReset :: IO ()
- stmtExecute :: [PersistValue] -> IO Int64
- stmtQuery :: forall (m :: Type -> Type). MonadIO m => [PersistValue] -> Acquire (ConduitM () [PersistValue] m ())

data InsertSqlResult Source #

Constructors

ISRSingle Text |
ISRInsertGet Text Text |
ISRManyKeys Text [PersistValue] |

type LogFunc = Loc -> LogSource -> LogLevel -> LogStr -> IO () Source #

newtype OverflowNatural Source #

Prior to `persistent-2.11.0`, we provided an instance of `PersistField` for the `Natural` type. This was in error, because `Natural` represents an infinite value, and databases don't have reasonable types for this.

The instance for `Natural` used the `Int64` underlying type, which will cause underflow and overflow errors. This type has the exact same code in the instances, and will work seamlessly.

A more appropriate type for this is the `Word` series of types from Data.Word. These have a bounded size, are guaranteed to be non-negative, and are quite efficient for the database to store.

Since: persistent-2.11.0

Constructors

OverflowNatural |

Fields

- unOverflowNatural :: Natural

#### Instances

Instances details

Num OverflowNatural |

Instance details

Defined in Database.Persist.Class.PersistField

Methods

(+) :: OverflowNatural -> OverflowNatural -> OverflowNatural Source #

(-) :: OverflowNatural -> OverflowNatural -> OverflowNatural Source #

(*) :: OverflowNatural -> OverflowNatural -> OverflowNatural Source #

negate :: OverflowNatural -> OverflowNatural Source #

abs :: OverflowNatural -> OverflowNatural Source #

signum :: OverflowNatural -> OverflowNatural Source #

fromInteger :: Integer -> OverflowNatural Source #

Show OverflowNatural |
Instance details Defined in Database.Persist.Class.PersistField Methods showsPrec :: Int -> OverflowNatural -> ShowS Source # show :: OverflowNatural -> String Source # showList :: [OverflowNatural] -> ShowS Source #
Eq OverflowNatural |
Instance details Defined in Database.Persist.Class.PersistField Methods (==) :: OverflowNatural -> OverflowNatural -> Bool Source # (/=) :: OverflowNatural -> OverflowNatural -> Bool Source #
Ord OverflowNatural |

Instance details

Defined in Database.Persist.Class.PersistField

Methods

compare :: OverflowNatural -> OverflowNatural -> Ordering Source #

(<) :: OverflowNatural -> OverflowNatural -> Bool Source #

(<=) :: OverflowNatural -> OverflowNatural -> Bool Source #

(>) :: OverflowNatural -> OverflowNatural -> Bool Source #

(>=) :: OverflowNatural -> OverflowNatural -> Bool Source #

max :: OverflowNatural -> OverflowNatural -> OverflowNatural Source #

min :: OverflowNatural -> OverflowNatural -> OverflowNatural Source #

PersistField OverflowNatural |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: OverflowNatural -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text OverflowNatural Source #
PersistFieldSql OverflowNatural | This type uses the `SqlInt64` version, which will exhibit overflow and underflow behavior. Additionally, it permits negative values in the database, which isn't ideal. Since: persistent-2.11.0
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy OverflowNatural -> SqlType Source #

class PersistField a where Source #

This class teaches Persistent how to take a custom type and marshal it to and from a `PersistValue`, allowing it to be stored in a database.

#### Examples

Expand

##### Simple Newtype

You can use `newtype` to add more type safety/readability to a basis type like `ByteString`. In these cases, just derive `PersistField` and `PersistFieldSql`:

    {-# LANGUAGE GeneralizedNewtypeDeriving #-}

    newtype HashedPassword = HashedPassword ByteString
      deriving (Eq, Show, PersistField, PersistFieldSql)

##### Smart Constructor Newtype

In this example, we create a `PersistField` instance for a newtype following the "Smart Constructor" pattern.

    {-# LANGUAGE GeneralizedNewtypeDeriving #-}
    import qualified Data.Text as T
    import qualified Data.Char as C

    -- | An American Social Security Number
    newtype SSN = SSN ErrorMessage
     deriving (Eq, Show, PersistFieldSql)

    mkSSN :: ErrorMessage -> Either ErrorMessage SSN
    mkSSN t = if (T.length t == 9) && (T.all C.isDigit t)
     then Right $ SSN t
     else Left $ "Invalid SSN: " <> t

    instance PersistField SSN where
      toPersistValue (SSN t) = PersistText t
      fromPersistValue (PersistText t) = mkSSN t
      -- Handle cases where the database does not give us PersistText
      fromPersistValue x = Left $ "File.hs: When trying to deserialize an SSN: expected PersistText, received: " <> T.pack (show x)

Tips:

- This file contain dozens of `PersistField` instances you can look at for examples.
- Typically custom `PersistField` instances will only accept a single `PersistValue` constructor in `fromPersistValue`.
- Internal `PersistField` instances accept a wide variety of `PersistValue`s to accomodate e.g. storing booleans as integers, booleans or strings.
- If you're making a custom instance and using a SQL database, you'll also need `PersistFieldSql` to specify the type of the database column.

Methods

toPersistValue :: a -> PersistValue Source #

fromPersistValue :: PersistValue -> Either Text a Source #

#### Instances

Instances details

PersistField Int16 |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Int16 -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Int16 Source #
PersistField Int32 |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Int32 -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Int32 Source #
PersistField Int64 |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Int64 -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Int64 Source #
PersistField Int8 |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Int8 -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Int8 Source #
PersistField Rational |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Rational -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Rational Source #
PersistField Word16 |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Word16 -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Word16 Source #
PersistField Word32 |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Word32 -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Word32 Source #
PersistField Word64 |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Word64 -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Word64 Source #
PersistField Word8 |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Word8 -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Word8 Source #
PersistField Html |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Html -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Html Source #
PersistField ByteString |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: ByteString -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text ByteString Source #
PersistField OverflowNatural |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: OverflowNatural -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text OverflowNatural Source #
PersistField PersistValue |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: PersistValue -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text PersistValue Source #
PersistField Checkmark |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Checkmark -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Checkmark Source #
PersistField Text |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Text -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Text Source #
PersistField Text |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Text -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text0 Text Source #
PersistField Day |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Day -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Day Source #
PersistField UTCTime |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: UTCTime -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text UTCTime Source #
PersistField TimeOfDay |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: TimeOfDay -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text TimeOfDay Source #

(TypeError ((((('Text "The instance of PersistField for the Natural type was removed." ':$$: 'Text "Please see the documentation for OverflowNatural if you want to ") ':$$: 'Text "continue using the old behavior or want to see documentation on ") ':$$: 'Text "why the instance was removed.") ':$$: 'Text "") ':$$: 'Text "This error instance will be removed in a future release.") :: Constraint) => PersistField Natural

Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Natural -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Natural Source #
PersistField Bool |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Bool -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Bool Source #
PersistField Double |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Double -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Double Source #
PersistField Int |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Int -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Int Source #
PersistField Word |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Word -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Word Source #
PersistField v => PersistField (IntMap v) |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: IntMap v -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text (IntMap v) Source #
(Ord a, PersistField a) => PersistField (Set a) |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Set a -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text (Set a) Source #
(FromJSON a, ToJSON a) => PersistField (JSONB a) Source # | Since: 3.1.0
Instance details Defined in Database.Esqueleto.PostgreSQL.JSON.Instances Methods toPersistValue :: JSONB a -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text (JSONB a) Source #
(PersistEntity record, PersistField record, PersistField (Key record)) => PersistField (Entity record) |
Instance details Defined in Database.Persist.Class.PersistEntity Methods toPersistValue :: Entity record -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text (Entity record) Source #
PersistField a => PersistField (Vector a) |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Vector a -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text (Vector a) Source #
PersistField a => PersistField (Maybe a) |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Maybe a -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text (Maybe a) Source #
PersistField [Char] |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: [Char] -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text [Char] Source #
PersistField a => PersistField [a] |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: [a] -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text [a] Source #
HasResolution a => PersistField (Fixed a) |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Fixed a -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text (Fixed a) Source #
PersistField v => PersistField (Map Text v) |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: Map Text v -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text (Map Text v) Source #
(PersistField a, PersistField b) => PersistField (a, b) |
Instance details Defined in Database.Persist.Class.PersistField Methods toPersistValue :: (a, b) -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text (a, b) Source #

class SafeToInsert a Source #

A type class which is used to witness that a type is safe to insert into the database without providing a primary key.

The `TemplateHaskell` function `mkPersist` will generate instances of this class for any entity that it works on. If the entity has a default primary key, then it provides a regular instance. If the entity has a `Primary` natural key, then this works fine. But if the entity has an `Id` column with no `default=`, then this does a `TypeError` and forces the user to use `insertKey`.

Since: persistent-2.14.0.0

#### Instances

Instances details

(TypeError (EntityErrorMessage a) :: Constraint) => SafeToInsert (Entity a) |
Instance details Defined in Database.Persist.Class.PersistEntity
(TypeError (FunctionErrorMessage a b) :: Constraint) => SafeToInsert (a -> b) |
Instance details Defined in Database.Persist.Class.PersistEntity

class SymbolToField (sym :: Symbol) rec typ | sym rec -> typ where Source #

This type class is used with the `OverloadedLabels` extension to provide a more convenient means of using the `EntityField` type. `EntityField` definitions are prefixed with the type name to avoid ambiguity, but this ambiguity can result in verbose code.

If you have a table `User` with a `name Text` field, then the corresponding `EntityField` is `UserName`. With this, we can write `#name :: `EntityField` User Text`.

What's more fun is that the type is more general: it's actually `#name :: (`SymbolToField` "name" rec typ) => EntityField rec typ`

Which means it is *polymorphic* over the actual record. This allows you to write code that can be generic over the tables, provided they have the right fields.

Since: persistent-2.11.0.0

Methods

symbolToField :: EntityField rec typ Source #

data Entity record Source #

Datatype that represents an entity, with both its `Key` and its Haskell record representation.

When using a SQL-based backend (such as SQLite or PostgreSQL), an `Entity` may take any number of columns depending on how many fields it has. In order to reconstruct your entity on the Haskell side, `persistent` needs all of your entity columns and in the right order. Note that you don't need to worry about this when using `persistent`'s API since everything is handled correctly behind the scenes.

However, if you want to issue a raw SQL command that returns an `Entity`, then you have to be careful with the column order. While you could use `SELECT Entity.* WHERE ...` and that would work most of the time, there are times when the order of the columns on your database is different from the order that `persistent` expects (for example, if you add a new field in the middle of you entity definition and then use the migration code -- `persistent` will expect the column to be in the middle, but your DBMS will put it as the last column). So, instead of using a query like the one above, you may use `rawSql` (from the Database.Persist.Sql module) with its /entity selection placeholder/ (a double question mark `??`). Using `rawSql` the query above must be written as `SELECT ?? WHERE ..`. Then `rawSql` will replace `??` with the list of all columns that we need from your entity in the right order. If your query returns two entities (i.e. `(Entity backend a, Entity backend b)`), then you must you use `SELECT ??, ?? WHERE ...`, and so on.

Constructors

Entity |

Fields

- entityKey :: Key record
- entityVal :: record

#### Instances

Instances details

(PersistEntity rec, PersistField typ, SymbolToField sym rec typ) => HasField (sym :: Symbol) (SqlExpr (Entity rec)) (SqlExpr (Value typ)) Source #

This instance allows you to use `record.field` notation with GHC 9.2's `OverloadedRecordDot` extension.

Example:

    -- persistent model:
    BlogPost
        authorId     PersonId
        title        Text

    -- query:
    select $ do
        bp <- from $ table @BlogPost
        pure $ bp.title

This is exactly equivalent to the following:

    blogPost :: SqlExpr (Entity BlogPost)

    blogPost ^. BlogPostTitle
    blogPost ^. #title
    blogPost.title

There's another instance defined on ``SqlExpr` (`Entity` (`Maybe` rec))`, which allows you to project from a `LEFT JOIN`ed entity.

Since: 3.5.4.0

Instance details Defined in Database.Esqueleto.Internal.Internal Methods getField :: SqlExpr (Entity rec) -> SqlExpr (Value typ) Source #

(PersistEntity rec, PersistField typ, SymbolToField sym rec typ) => HasField (sym :: Symbol) (SqlExpr (Maybe (Entity rec))) (SqlExpr (Value (Maybe typ))) Source #

This instance allows you to use `record.field` notation with GC 9.2's `OverloadedRecordDot` extension.

Example:

    -- persistent model:
    Person
        name         Text

    BlogPost
        title        Text
        authorId     PersonId

    -- query:

    select $ do
        (p :& bp) <- from $
            table Person
            leftJoin table BlogPost
            on do
                \(p :& bp) ->
                    just p.id ==. bp.authorId
        pure (p.name, bp.title)

The following forms are all equivalent:

    blogPost :: SqlExpr (Maybe (Entity BlogPost))

    blogPost ?. BlogPostTitle
    blogPost ?. #title
    blogPost.title

Since: 3.5.4.0

Instance details Defined in Database.Esqueleto.Internal.Internal Methods getField :: SqlExpr (Maybe (Entity rec)) -> SqlExpr (Value (Maybe typ)) Source #
(Generic (Key record), Generic record) => Generic (Entity record) |
Instance details Defined in Database.Persist.Class.PersistEntity Associated Types type Rep (Entity record) :: Type -> Type Source # Methods from :: Entity record -> Rep (Entity record) x Source # to :: Rep (Entity record) x -> Entity record Source #
(Read (Key record), Read record) => Read (Entity record) |
Instance details Defined in Database.Persist.Class.PersistEntity Methods readsPrec :: Int -> ReadS (Entity record) Source # readList :: ReadS [Entity record] Source # readPrec :: ReadPrec (Entity record) Source # readListPrec :: ReadPrec [Entity record] Source #
(Show (Key record), Show record) => Show (Entity record) |
Instance details Defined in Database.Persist.Class.PersistEntity Methods showsPrec :: Int -> Entity record -> ShowS Source # show :: Entity record -> String Source # showList :: [Entity record] -> ShowS Source #
ToAlias (SqlExpr (Entity a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: SqlExpr (Entity a) -> SqlQuery (SqlExpr (Entity a)) Source #
ToAlias (SqlExpr (Maybe (Entity a))) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAlias Methods toAlias :: SqlExpr (Maybe (Entity a)) -> SqlQuery (SqlExpr (Maybe (Entity a))) Source #
ToAliasReference (SqlExpr (Entity a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> SqlExpr (Entity a) -> SqlQuery (SqlExpr (Entity a)) Source #
ToAliasReference (SqlExpr (Maybe (Entity a))) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToAliasReference Methods toAliasReference :: Ident -> SqlExpr (Maybe (Entity a)) -> SqlQuery (SqlExpr (Maybe (Entity a))) Source #
ToMaybe (SqlExpr (Entity a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToMaybe Associated Types type ToMaybeT (SqlExpr (Entity a)) Source # Methods toMaybe :: SqlExpr (Entity a) -> ToMaybeT (SqlExpr (Entity a)) Source #
FromPreprocess (SqlExpr (Entity val)) => From (SqlExpr (Entity val)) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods from_ :: SqlQuery (SqlExpr (Entity val)) Source #
FromPreprocess (SqlExpr (Maybe (Entity val))) => From (SqlExpr (Maybe (Entity val))) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods from_ :: SqlQuery (SqlExpr (Maybe (Entity val))) Source #
(PersistEntity val, BackendCompatible SqlBackend (PersistEntityBackend val)) => FromPreprocess (SqlExpr (Entity val)) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods fromPreprocess :: SqlQuery (PreprocessedFrom (SqlExpr (Entity val))) Source #
(PersistEntity val, BackendCompatible SqlBackend (PersistEntityBackend val)) => FromPreprocess (SqlExpr (Maybe (Entity val))) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods fromPreprocess :: SqlQuery (PreprocessedFrom (SqlExpr (Maybe (Entity val)))) Source #
PersistEntity val => LockableEntity (SqlExpr (Entity val)) Source # |
Instance details Defined in Database.Esqueleto.Internal.Internal Methods flattenLockableEntity :: SqlExpr (Entity val) -> NonEmpty LockableSqlExpr Source #
(Eq (Key record), Eq record) => Eq (Entity record) |
Instance details Defined in Database.Persist.Class.PersistEntity Methods (==) :: Entity record -> Entity record -> Bool Source # (/=) :: Entity record -> Entity record -> Bool Source #
(Ord (Key record), Ord record) => Ord (Entity record) |

Instance details

Defined in Database.Persist.Class.PersistEntity

Methods

compare :: Entity record -> Entity record -> Ordering Source #

(<) :: Entity record -> Entity record -> Bool Source #

(<=) :: Entity record -> Entity record -> Bool Source #

(>) :: Entity record -> Entity record -> Bool Source #

(>=) :: Entity record -> Entity record -> Bool Source #

max :: Entity record -> Entity record -> Entity record Source #

min :: Entity record -> Entity record -> Entity record Source #

(TypeError (EntityErrorMessage a) :: Constraint) => SafeToInsert (Entity a) |
Instance details Defined in Database.Persist.Class.PersistEntity
(PersistEntity record, PersistField record, PersistField (Key record)) => PersistField (Entity record) |
Instance details Defined in Database.Persist.Class.PersistEntity Methods toPersistValue :: Entity record -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text (Entity record) Source #
(PersistField record, PersistEntity record) => PersistFieldSql (Entity record) |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy (Entity record) -> SqlType Source #
(PersistEntity record, PersistEntityBackend record ~ backend, IsPersistBackend backend) => RawSql (Entity record) |
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> Entity record -> (Int, [Text]) Source # rawSqlColCountReason :: Entity record -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (Entity record) Source #
PersistEntity ent => ToFrom (Table ent) (SqlExpr (Entity ent)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.From Methods toFrom :: Table ent -> From (SqlExpr (Entity ent)) Source #
PersistEntity a => SqlSelect (SqlExpr (Entity a)) (Entity a) Source # | You may return an `Entity` from a `select` query.
Instance details Defined in Database.Esqueleto.Internal.Internal Methods sqlSelectCols :: IdentInfo -> SqlExpr (Entity a) -> (Builder, [PersistValue]) Source # sqlSelectColCount :: Proxy (SqlExpr (Entity a)) -> Int Source # sqlSelectProcessRow :: [PersistValue] -> Either Text (Entity a) Source # sqlInsertInto :: IdentInfo -> SqlExpr (Entity a) -> (Builder, [PersistValue]) Source #
PersistEntity a => SqlSelect (SqlExpr (Maybe (Entity a))) (Maybe (Entity a)) Source # | You may return a possibly-`NULL` `Entity` from a `select` query.

Instance details

Defined in Database.Esqueleto.Internal.Internal

Methods

sqlSelectCols :: IdentInfo -> SqlExpr (Maybe (Entity a)) -> (Builder, [PersistValue]) Source #

sqlSelectColCount :: Proxy (SqlExpr (Maybe (Entity a))) -> Int Source #

sqlSelectProcessRow :: [PersistValue] -> Either Text (Maybe (Entity a)) Source #

sqlInsertInto :: IdentInfo -> SqlExpr (Maybe (Entity a)) -> (Builder, [PersistValue]) Source #

type Rep (Entity record) |

Instance details

Defined in Database.Persist.Class.PersistEntity

type Rep (Entity record) = D1 ('MetaData "Entity" "Database.Persist.Class.PersistEntity" "persistent-2.14.6.0-EwPrwCqZZwo9tyFUGF3ac2" 'False) (C1 ('MetaCons "Entity" 'PrefixI 'True) (S1 ('MetaSel ('Just "entityKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Key record)) :*: S1 ('MetaSel ('Just "entityVal") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 record)))

type ToMaybeT (SqlExpr (Entity a)) Source # |
Instance details Defined in Database.Esqueleto.Experimental.ToMaybe type ToMaybeT (SqlExpr (Entity a)) = SqlExpr (Maybe (Entity a))

data FilterValue typ where Source #

Value to filter with. Highly dependant on the type of filter used.

Since: persistent-2.10.0

Constructors

FilterValue :: forall typ. typ -> FilterValue typ |
FilterValues :: forall typ. [typ] -> FilterValue typ |
UnsafeValue :: forall a typ. PersistField a => a -> FilterValue typ |

type family PersistEntityBackend record Source #

Persistent allows multiple different backends (databases).

data family EntityField record :: Type -> Type Source #

An `EntityField` is parameterised by the Haskell record it belongs to and the additional type of that field.

As of `persistent-2.11.0.0`, it's possible to use the `OverloadedLabels` language extension to refer to `EntityField` values polymorphically. See the documentation on `SymbolToField` for more information.

#### Instances

Instances details

SymbolToField sym rec typ => IsLabel sym (EntityField rec typ) | This instance delegates to `SymbolToField` to provide `OverloadedLabels` support to the `EntityField` type. Since: persistent-2.11.0.0
Instance details Defined in Database.Persist.Class.PersistEntity Methods fromLabel :: EntityField rec typ Source #

class (Show (BackendKey backend), Read (BackendKey backend), Eq (BackendKey backend), Ord (BackendKey backend), PersistStoreRead backend, PersistField (BackendKey backend), ToJSON (BackendKey backend), FromJSON (BackendKey backend)) => PersistStoreWrite backend where Source #

Minimal complete definition

insert, insertKey, repsert, replace, delete, update

Methods

insert :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, SafeToInsert record) => record -> ReaderT backend m (Key record) Source #

Create a new record in the database, returning an automatically created key (in SQL an auto-increment id).

### Example usage

Expand

Using schema-1 and dataset-1, let's insert a new user `John`.

    insertJohn :: MonadIO m => ReaderT SqlBackend m (Key User)
    insertJohn = insert $ User "John" 30

    johnId <- insertJohn

The above query when applied on dataset-1, will produce this:

    +-----+------+-----+
    |id   |name  |age  |
    +-----+------+-----+
    |1    |SPJ   |40   |
    +-----+------+-----+
    |2    |Simon |41   |
    +-----+------+-----+
    |3    |John  |30   |
    +-----+------+-----+

insert_ :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, SafeToInsert record) => record -> ReaderT backend m () Source #

Same as `insert`, but doesn't return a `Key`.

### Example usage

Expand

with schema-1 and dataset-1,

    insertJohn :: MonadIO m => ReaderT SqlBackend m (Key User)
    insertJohn = insert_ $ User "John" 30

The above query when applied on dataset-1, will produce this:

    +-----+------+-----+
    |id   |name  |age  |
    +-----+------+-----+
    |1    |SPJ   |40   |
    +-----+------+-----+
    |2    |Simon |41   |
    +-----+------+-----+
    |3    |John  |30   |
    +-----+------+-----+

insertMany :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, SafeToInsert record) => [record] -> ReaderT backend m [Key record] Source #

Create multiple records in the database and return their `Key`s.

If you don't need the inserted `Key`s, use `insertMany_`.

The MongoDB and PostgreSQL backends insert all records and retrieve their keys in one database query.

The SQLite and MySQL backends use the slow, default implementation of `mapM insert`.

### Example usage

Expand

with schema-1 and dataset-1,

    insertUsers :: MonadIO m => ReaderT SqlBackend m [Key User]
    insertUsers = insertMany [User "John" 30, User "Nick" 32, User "Jane" 20]

    userIds <- insertUsers

The above query when applied on dataset-1, will produce this:

    +-----+------+-----+
    |id   |name  |age  |
    +-----+------+-----+
    |1    |SPJ   |40   |
    +-----+------+-----+
    |2    |Simon |41   |
    +-----+------+-----+
    |3    |John  |30   |
    +-----+------+-----+
    |4    |Nick  |32   |
    +-----+------+-----+
    |5    |Jane  |20   |
    +-----+------+-----+

insertMany_ :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, SafeToInsert record) => [record] -> ReaderT backend m () Source #

Same as `insertMany`, but doesn't return any `Key`s.

The MongoDB, PostgreSQL, SQLite and MySQL backends insert all records in one database query.

### Example usage

Expand

With schema-1 and dataset-1,

    insertUsers_ :: MonadIO m => ReaderT SqlBackend m ()
    insertUsers_ = insertMany_ [User "John" 30, User "Nick" 32, User "Jane" 20]

The above query when applied on dataset-1, will produce this:

    +-----+------+-----+
    |id   |name  |age  |
    +-----+------+-----+
    |1    |SPJ   |40   |
    +-----+------+-----+
    |2    |Simon |41   |
    +-----+------+-----+
    |3    |John  |30   |
    +-----+------+-----+
    |4    |Nick  |32   |
    +-----+------+-----+
    |5    |Jane  |20   |
    +-----+------+-----+

insertEntityMany :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => [Entity record] -> ReaderT backend m () Source #

Same as `insertMany_`, but takes an `Entity` instead of just a record.

Useful when migrating data from one entity to another and want to preserve ids.

The MongoDB, PostgreSQL, SQLite and MySQL backends insert all records in one database query.

### Example usage

Expand

With schema-1 and dataset-1,

    insertUserEntityMany :: MonadIO m => ReaderT SqlBackend m ()
    insertUserEntityMany = insertEntityMany [SnakeEntity, EvaEntity]

The above query when applied on dataset-1, will produce this:

    +-----+------+-----+
    |id   |name  |age  |
    +-----+------+-----+
    |1    |SPJ   |40   |
    +-----+------+-----+
    |2    |Simon |41   |
    +-----+------+-----+
    |3    |Snake |38   |
    +-----+------+-----+
    |4    |Eva   |38   |
    +-----+------+-----+

insertKey :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => Key record -> record -> ReaderT backend m () Source #

Create a new record in the database using the given key.

### Example usage

Expand

With schema-1 and dataset-1,

    insertAliceKey :: MonadIO m => Key User -> ReaderT SqlBackend m ()
    insertAliceKey key = insertKey key $ User "Alice" 20

    insertAliceKey $ UserKey {unUserKey = SqlBackendKey {unSqlBackendKey = 3}}

The above query when applied on dataset-1, will produce this:

    +-----+------+-----+
    |id   |name  |age  |
    +-----+------+-----+
    |1    |SPJ   |40   |
    +-----+------+-----+
    |2    |Simon |41   |
    +-----+------+-----+
    |3    |Alice |20   |
    +-----+------+-----+

repsert :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => Key record -> record -> ReaderT backend m () Source #

Put the record in the database with the given key. Unlike `replace`, if a record with the given key does not exist then a new record will be inserted.

### Example usage

Expand

We try to explain `upsertBy` using schema-1 and dataset-1.

First, we insert Philip to dataset-1.

    insertPhilip :: MonadIO m => ReaderT SqlBackend m (Key User)
    insertPhilip = insert $ User "Philip" 42

    philipId <- insertPhilip

This query will produce:

    +-----+------+-----+
    |id   |name  |age  |
    +-----+------+-----+
    |1    |SPJ   |40   |
    +-----+------+-----+
    |2    |Simon |41   |
    +-----+------+-----+
    |3    |Philip|42   |
    +-----+------+-----+

    repsertHaskell :: MonadIO m => Key record -> ReaderT SqlBackend m ()
    repsertHaskell id = repsert id $ User "Haskell" 81

    repsertHaskell philipId

This query will replace Philip's record with Haskell's one:

    +-----+-----------------+--------+
    |id   |name             |age     |
    +-----+-----------------+--------+
    |1    |SPJ              |40      |
    +-----+-----------------+--------+
    |2    |Simon            |41      |
    +-----+-----------------+--------+
    |3    |Philip -> Haskell|42 -> 81|
    +-----+-----------------+--------+

`repsert` inserts the given record if the key doesn't exist.

    repsertXToUnknown :: MonadIO m => ReaderT SqlBackend m ()
    repsertXToUnknown = repsert unknownId $ User "X" 999

For example, applying the above query to dataset-1 will produce this:

    +-----+------+-----+
    |id   |name  |age  |
    +-----+------+-----+
    |1    |SPJ   |40   |
    +-----+------+-----+
    |2    |Simon |41   |
    +-----+------+-----+
    |3    |X     |999  |
    +-----+------+-----+

repsertMany :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => [(Key record, record)] -> ReaderT backend m () Source #

Put many entities into the database.

Batch version of `repsert` for SQL backends.

Useful when migrating data from one entity to another and want to preserve ids.

### Example usage

Expand

With schema-1 and dataset-1,

    repsertManyUsers :: MonadIO m =>ReaderT SqlBackend m ()
    repsertManyusers = repsertMany [(simonId, User "Philip" 20), (unknownId999, User "Mr. X" 999)]

The above query when applied on dataset-1, will produce this:

    +-----+----------------+---------+
    |id   |name            |age      |
    +-----+----------------+---------+
    |1    |SPJ             |40       |
    +-----+----------------+---------+
    |2    |Simon -> Philip |41 -> 20 |
    +-----+----------------+---------+
    |999  |Mr. X           |999      |
    +-----+----------------+---------+

Since: persistent-2.8.1

replace :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => Key record -> record -> ReaderT backend m () Source #

Replace the record in the database with the given key. Note that the result is undefined if such record does not exist, so you must use `insertKey` or `repsert` in these cases.

### Example usage

Expand

With schema-1 schama-1 and dataset-1,

    replaceSpj :: MonadIO m => User -> ReaderT SqlBackend m ()
    replaceSpj record = replace spjId record

The above query when applied on dataset-1, will produce this:

    +-----+------+-----+
    |id   |name  |age  |
    +-----+------+-----+
    |1    |Mike  |45   |
    +-----+------+-----+
    |2    |Simon |41   |
    +-----+------+-----+

updateGet :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => Key record -> [Update record] -> ReaderT backend m record Source #

Update individual fields on a specific record, and retrieve the updated value from the database.

Note that this function will throw an exception if the given key is not found in the database.

### Example usage

Expand

With schema-1 and dataset-1,

    updateGetSpj :: MonadIO m => [Update User] -> ReaderT SqlBackend m User
    updateGetSpj updates = updateGet spjId updates

    spj <- updateGetSpj [UserAge +=. 100]

The above query when applied on dataset-1, will produce this:

    +-----+------+-----+
    |id   |name  |age  |
    +-----+------+-----+
    |1    |SPJ   |140  |
    +-----+------+-----+
    |2    |Simon |41   |
    +-----+------+-----+

class (Show (BackendKey backend), Read (BackendKey backend), Eq (BackendKey backend), Ord (BackendKey backend), PersistCore backend, PersistField (BackendKey backend), ToJSON (BackendKey backend), FromJSON (BackendKey backend)) => PersistStoreRead backend where Source #

Minimal complete definition

get

Methods

get :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => Key record -> ReaderT backend m (Maybe record) Source #

Get a record by identifier, if available.

### Example usage

Expand

With schema-1 and dataset-1,

    getSpj :: MonadIO m => ReaderT SqlBackend m (Maybe User)
    getSpj = get spjId

    mspj <- getSpj

The above query when applied on dataset-1, will get this:

    +------+-----+
    | name | age |
    +------+-----+
    | SPJ  |  40 |
    +------+-----+

getMany :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => [Key record] -> ReaderT backend m (Map (Key record) record) Source #

Get many records by their respective identifiers, if available.

### Example usage

Expand

With schema-1 and dataset-1:

    getUsers :: MonadIO m => ReaderT SqlBackend m (Map (Key User) User)
    getUsers = getMany allkeys

    musers <- getUsers

The above query when applied on dataset-1, will get these records:

    +----+-------+-----+
    | id | name  | age |
    +----+-------+-----+
    |  1 | SPJ   |  40 |
    +----+-------+-----+
    |  2 | Simon |  41 |
    +----+-------+-----+

Since: persistent-2.8.1

class PersistCore backend Source #

Associated Types

data BackendKey backend Source #

data family BackendKey backend Source #

#### Instances

Instances details

newtype BackendKey SqlReadBackend |

Instance details

Defined in Database.Persist.Sql.Orphan.PersistStore

newtype BackendKey SqlReadBackend = SqlReadBackendKey {

- unSqlReadBackendKey :: Int64

}

newtype BackendKey SqlWriteBackend |

Instance details

Defined in Database.Persist.Sql.Orphan.PersistStore

newtype BackendKey SqlWriteBackend = SqlWriteBackendKey {

- unSqlWriteBackendKey :: Int64

}

newtype BackendKey SqlBackend |

Instance details

Defined in Database.Persist.Sql.Orphan.PersistStore

newtype BackendKey SqlBackend = SqlBackendKey {

- unSqlBackendKey :: Int64

}

type Rep (BackendKey SqlReadBackend) |
Instance details Defined in Database.Persist.Sql.Orphan.PersistStore type Rep (BackendKey SqlReadBackend) = D1 ('MetaData "BackendKey" "Database.Persist.Sql.Orphan.PersistStore" "persistent-2.14.6.0-EwPrwCqZZwo9tyFUGF3ac2" 'True) (C1 ('MetaCons "SqlReadBackendKey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unSqlReadBackendKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64)))
type Rep (BackendKey SqlWriteBackend) |
Instance details Defined in Database.Persist.Sql.Orphan.PersistStore type Rep (BackendKey SqlWriteBackend) = D1 ('MetaData "BackendKey" "Database.Persist.Sql.Orphan.PersistStore" "persistent-2.14.6.0-EwPrwCqZZwo9tyFUGF3ac2" 'True) (C1 ('MetaCons "SqlWriteBackendKey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unSqlWriteBackendKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64)))
type Rep (BackendKey SqlBackend) |
Instance details Defined in Database.Persist.Sql.Orphan.PersistStore type Rep (BackendKey SqlBackend) = D1 ('MetaData "BackendKey" "Database.Persist.Sql.Orphan.PersistStore" "persistent-2.14.6.0-EwPrwCqZZwo9tyFUGF3ac2" 'True) (C1 ('MetaCons "SqlBackendKey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unSqlBackendKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64)))

class (PersistEntity record, PersistEntityBackend record ~ backend, PersistCore backend) => ToBackendKey backend record where Source #

`ToBackendKey` converts a `PersistEntity` `Key` into a `BackendKey` This can be used by each backend to convert between a `Key` and a plain Haskell type. For Sql, that is done with `toSqlKey` and `fromSqlKey`.

By default, a `PersistEntity` uses the default `BackendKey` for its Key and is an instance of ToBackendKey

A `Key` that instead uses a custom type will not be an instance of `ToBackendKey`.

Methods

toBackendKey :: Key record -> BackendKey backend Source #

fromBackendKey :: BackendKey backend -> Key record Source #

type PersistRecordBackend record backend = (PersistEntity record, PersistEntityBackend record ~ BaseBackend backend) Source #

A convenient alias for common type signatures

class BackendCompatible sup sub where Source #

This class witnesses that two backend are compatible, and that you can convert from the `sub` backend into the `sup` backend. This is similar to the `HasPersistBackend` and `IsPersistBackend` classes, but where you don't want to fix the type associated with the `PersistEntityBackend` of a record.

Generally speaking, where you might have:

    foo ::
      ( PersistEntity record
      , PersistEntityBackend record ~ BaseBackend backend
      , IsSqlBackend backend
      )

this can be replaced with:

    foo ::
      ( PersistEntity record,
      , PersistEntityBackend record ~ backend
      , BackendCompatible SqlBackend backend
      )

This works for `SqlReadBackend` because of the `instance `BackendCompatible` `SqlBackend` `SqlReadBackend``, without needing to go through the `BaseBackend` type family.

Likewise, functions that are currently hardcoded to use `SqlBackend` can be generalized:

    -- before:
    asdf :: ReaderT SqlBackend m ()
    asdf = pure ()

    -- after:
    asdf' :: BackendCompatible SqlBackend backend => ReaderT backend m ()
    asdf' = withCompatibleBackend asdf

Since: persistent-2.7.1

Methods

projectBackend :: sub -> sup Source #

class HasPersistBackend backend => IsPersistBackend backend Source #

Class which witnesses that `backend` is essentially the same as `BaseBackend backend`. That is, they're isomorphic and `backend` is just some wrapper over `BaseBackend backend`.

Minimal complete definition

mkPersistBackend

#### Instances

Instances details

IsPersistBackend SqlReadBackend |
Instance details Defined in Database.Persist.Sql.Types.Internal Methods mkPersistBackend :: BaseBackend SqlReadBackend -> SqlReadBackend Source #
IsPersistBackend SqlWriteBackend |
Instance details Defined in Database.Persist.Sql.Types.Internal Methods mkPersistBackend :: BaseBackend SqlWriteBackend -> SqlWriteBackend Source #
IsPersistBackend SqlBackend |
Instance details Defined in Database.Persist.SqlBackend.Internal Methods mkPersistBackend :: BaseBackend SqlBackend -> SqlBackend Source #

class HasPersistBackend backend where Source #

Class which allows the plucking of a `BaseBackend backend` from some larger type. For example, `instance HasPersistBackend (SqlReadBackend, Int) where type BaseBackend (SqlReadBackend, Int) = SqlBackend persistBackend = unSqlReadBackend . fst`

Associated Types

type BaseBackend backend Source #

Methods

persistBackend :: backend -> BaseBackend backend Source #

#### Instances

Instances details

HasPersistBackend SqlReadBackend |
Instance details Defined in Database.Persist.Sql.Types.Internal Associated Types type BaseBackend SqlReadBackend Source # Methods persistBackend :: SqlReadBackend -> BaseBackend SqlReadBackend Source #
HasPersistBackend SqlWriteBackend |
Instance details Defined in Database.Persist.Sql.Types.Internal Associated Types type BaseBackend SqlWriteBackend Source # Methods persistBackend :: SqlWriteBackend -> BaseBackend SqlWriteBackend Source #
HasPersistBackend SqlBackend |
Instance details Defined in Database.Persist.SqlBackend.Internal Associated Types type BaseBackend SqlBackend Source # Methods persistBackend :: SqlBackend -> BaseBackend SqlBackend Source #

type family BaseBackend backend Source #

#### Instances

Instances details

type BaseBackend SqlReadBackend |
Instance details Defined in Database.Persist.Sql.Types.Internal type BaseBackend SqlReadBackend = SqlBackend
type BaseBackend SqlWriteBackend |
Instance details Defined in Database.Persist.Sql.Types.Internal type BaseBackend SqlWriteBackend = SqlBackend
type BaseBackend SqlBackend |
Instance details Defined in Database.Persist.SqlBackend.Internal type BaseBackend SqlBackend = SqlBackend

data SqlBackend Source #

A `SqlBackend` represents a handle or connection to a database. It contains functions and values that allow databases to have more optimized implementations, as well as references that benefit performance and sharing.

Instead of using the `SqlBackend` constructor directly, use the `mkSqlBackend` function.

A `SqlBackend` is *not* thread-safe. You should not assume that a `SqlBackend` can be shared among threads and run concurrent queries. This *will* result in problems. Instead, you should create a ``Pool` `SqlBackend``, known as a `ConnectionPool`, and pass that around in multi-threaded applications.

To run actions in the `persistent` library, you should use the `runSqlConn` function. If you're using a multithreaded application, use the `runSqlPool` function.

#### Instances

Instances details

HasPersistBackend SqlBackend |
Instance details Defined in Database.Persist.SqlBackend.Internal Associated Types type BaseBackend SqlBackend Source # Methods persistBackend :: SqlBackend -> BaseBackend SqlBackend Source #
IsPersistBackend SqlBackend |
Instance details Defined in Database.Persist.SqlBackend.Internal Methods mkPersistBackend :: BaseBackend SqlBackend -> SqlBackend Source #
newtype BackendKey SqlBackend |

Instance details

Defined in Database.Persist.Sql.Orphan.PersistStore

newtype BackendKey SqlBackend = SqlBackendKey {

- unSqlBackendKey :: Int64

}

type BaseBackend SqlBackend |
Instance details Defined in Database.Persist.SqlBackend.Internal type BaseBackend SqlBackend = SqlBackend
type Rep (BackendKey SqlBackend) |
Instance details Defined in Database.Persist.Sql.Orphan.PersistStore type Rep (BackendKey SqlBackend) = D1 ('MetaData "BackendKey" "Database.Persist.Sql.Orphan.PersistStore" "persistent-2.14.6.0-EwPrwCqZZwo9tyFUGF3ac2" 'True) (C1 ('MetaCons "SqlBackendKey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unSqlBackendKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64)))

class PersistEntity record => AtLeastOneUniqueKey record where Source #

This class is used to ensure that functions requring at least one unique key are not called with records that have 0 unique keys. The quasiquoter automatically writes working instances for appropriate entities, and generates `TypeError` instances for records that have 0 unique keys.

Since: persistent-2.10.0

Methods

requireUniquesP :: record -> NonEmpty (Unique record) Source #

type MultipleUniqueKeysError ty = ((('Text "The entity " ':<>: 'ShowType ty) ':<>: 'Text " has multiple unique keys.") ':$$: ('Text "The function you are trying to call requires only a single " ':<>: 'Text "unique key.")) ':$$: (('Text "There is probably a variant of the function with 'By' " ':<>: 'Text "appended that will allow you to select a unique key ") ':<>: 'Text "for the operation.") Source #

This is an error message. It is used when an entity has multiple unique keys, and the function expects a single unique key.

Since: persistent-2.10.0

type NoUniqueKeysError ty = (('Text "The entity " ':<>: 'ShowType ty) ':<>: 'Text " does not have any unique keys.") ':$$: ('Text "The function you are trying to call requires a unique key " ':<>: 'Text "to be defined on the entity.") Source #

This is an error message. It is used when writing instances of `OnlyOneUniqueKey` for an entity that has no unique keys.

Since: persistent-2.10.0

class PersistEntity record => OnlyOneUniqueKey record where Source #

This class is used to ensure that `upsert` is only called on records that have a single `Unique` key. The quasiquoter automatically generates working instances for appropriate records, and generates `TypeError` instances for records that have 0 or multiple unique keys.

Since: persistent-2.10.0

Methods

onlyUniqueP :: record -> Unique record Source #

class (PersistUniqueRead backend, PersistStoreWrite backend) => PersistUniqueWrite backend where Source #

Some functions in this module (`insertUnique`, `insertBy`, and `replaceUnique`) first query the unique indexes to check for conflicts. You could instead optimistically attempt to perform the operation (e.g. `replace` instead of `replaceUnique`). However,

- there is some fragility to trying to catch the correct exception and determing the column of failure;
- an exception will automatically abort the current SQL transaction.

Minimal complete definition

deleteBy

Methods

deleteBy :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => Unique record -> ReaderT backend m () Source #

Delete a specific record by unique key. Does nothing if no record matches.

### Example usage

Expand

With schema-1 and dataset-1,

    deleteBySpjName :: MonadIO m => ReaderT SqlBackend m ()
    deleteBySpjName = deleteBy UniqueUserName "SPJ"

The above query when applied on dataset-1, will produce this:

    +-----+------+-----+
    |id   |name  |age  |
    +-----+------+-----+
    |2    |Simon |41   |
    +-----+------+-----+

insertUnique :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, SafeToInsert record) => record -> ReaderT backend m (Maybe (Key record)) Source #

Like `insert`, but returns `Nothing` when the record couldn't be inserted because of a uniqueness constraint.

### Example usage

Expand

With schema-1 and dataset-1, we try to insert the following two records:

    linusId <- insertUnique $ User "Linus" 48
    spjId   <- insertUnique $ User "SPJ" 90

    +-----+------+-----+
    |id   |name  |age  |
    +-----+------+-----+
    |1    |SPJ   |40   |
    +-----+------+-----+
    |2    |Simon |41   |
    +-----+------+-----+
    |3    |Linus |48   |
    +-----+------+-----+

Linus's record was inserted to dataset-1, while SPJ wasn't because SPJ already exists in dataset-1.

insertUnique_ :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, SafeToInsert record) => record -> ReaderT backend m (Maybe ()) Source #

Same as `insertUnique` but doesn't return a `Key`.

### Example usage

Expand

With schema-1 and dataset-1, we try to insert the following two records:

    linusId <- insertUnique_ $ User "Linus" 48
    spjId   <- insertUnique_ $ User "SPJ" 90

    +-----+------+-----+
    |id   |name  |age  |
    +-----+------+-----+
    |1    |SPJ   |40   |
    +-----+------+-----+
    |2    |Simon |41   |
    +-----+------+-----+
    |3    |Linus |48   |
    +-----+------+-----+

Linus's record was inserted to dataset-1, while SPJ wasn't because SPJ already exists in dataset-1.

Since: persistent-2.14.5.0

upsert Source #

Arguments

:: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, OnlyOneUniqueKey record, SafeToInsert record) |
=> record | new record to insert
-> [Update record] | updates to perform if the record already exists
-> ReaderT backend m (Entity record) | the record in the database after the operation

Update based on a uniqueness constraint or insert:

- insert the new record if it does not exist;
- If the record exists (matched via it's uniqueness constraint), then update the existing record with the parameters which is passed on as list to the function.

### Example usage

Expand

First, we try to explain `upsert` using schema-1 and dataset-1.

    upsertSpj :: MonadIO m => [Update User] -> ReaderT SqlBackend m (Maybe (Entity User))
    upsertSpj updates = upsert (User "SPJ" 999) updates

    mSpjEnt <- upsertSpj [UserAge +=. 15]

The above query when applied on dataset-1, will produce this:

    +-----+-----+--------+
    |id   |name |age     |
    +-----+-----+--------+
    |1    |SPJ  |40 -> 55|
    +-----+-----+--------+
    |2    |Simon|41      |
    +-----+-----+--------+

    upsertX :: MonadIO m => [Update User] -> ReaderT SqlBackend m (Maybe (Entity User))
    upsertX updates = upsert (User "X" 999) updates

    mXEnt <- upsertX [UserAge +=. 15]

The above query when applied on dataset-1, will produce this:

    +-----+-----+--------+
    |id   |name |age     |
    +-----+-----+--------+
    |1    |SPJ  |40      |
    +-----+-----+--------+
    |2    |Simon|41      |
    +-----+-----+--------+
    |3    |X    |999     |
    +-----+-----+--------+

Next, what if the schema has two uniqueness constraints? Let's check it out using schema-2:

    mSpjEnt <- upsertSpj [UserAge +=. 15]

This fails with a compile-time type error alerting us to the fact that this record has multiple unique keys, and suggests that we look for `upsertBy` to select the unique key we want.

upsertBy Source #

Arguments

:: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, SafeToInsert record) |
=> Unique record | uniqueness constraint to find by
-> record | new record to insert
-> [Update record] | updates to perform if the record already exists
-> ReaderT backend m (Entity record) | the record in the database after the operation

Update based on a given uniqueness constraint or insert:

- insert the new record if it does not exist;
- update the existing record that matches the given uniqueness constraint.

### Example usage

Expand

We try to explain `upsertBy` using schema-2 and dataset-1.

    upsertBySpjName :: MonadIO m => User -> [Update User] -> ReaderT SqlBackend m (Entity User)
    upsertBySpjName record updates = upsertBy (UniqueUserName "SPJ") record updates

    mSpjEnt <- upsertBySpjName (Person "X" 999) [PersonAge += .15]

The above query will alter dataset-1 to:

    +-----+-----+--------+
    |id   |name |age     |
    +-----+-----+--------+
    |1    |SPJ  |40 -> 55|
    +-----+-----+--------+
    |2    |Simon|41      |
    +-----+-----+--------+

    upsertBySimonAge :: MonadIO m => User -> [Update User] -> ReaderT SqlBackend m (Entity User)
    upsertBySimonAge record updates = upsertBy (UniqueUserName "SPJ") record updates

    mPhilipEnt <- upsertBySimonAge (User "X" 999) [UserName =. "Philip"]

The above query will alter dataset-1 to:

    +----+-----------------+-----+
    | id |      name       | age |
    +----+-----------------+-----+
    |  1 | SPJ             |  40 |
    +----+-----------------+-----+
    |  2 | Simon -> Philip |  41 |
    +----+-----------------+-----+

    upsertByUnknownName :: MonadIO m => User -> [Update User] -> ReaderT SqlBackend m (Entity User)
    upsertByUnknownName record updates = upsertBy (UniqueUserName "Unknown") record updates

    mXEnt <- upsertByUnknownName (User "X" 999) [UserAge +=. 15]

This query will alter dataset-1 to:

    +-----+-----+-----+
    |id   |name |age  |
    +-----+-----+-----+
    |1    |SPJ  |40   |
    +-----+-----+-----+
    |2    |Simon|41   |
    +-----+-----+-----+
    |3    |X    |999  |
    +-----+-----+-----+

putMany Source #

Arguments

:: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, SafeToInsert record) |
=> [record] | A list of the records you want to insert or replace.
-> ReaderT backend m () |

Put many records into db

- insert new records that do not exist (or violate any unique constraints)
- replace existing records (matching any unique constraint)

Since: persistent-2.8.1

class PersistStoreRead backend => PersistUniqueRead backend where Source #

Queries against `Unique` keys (other than the id `Key`).

Please read the general Persistent documentation to learn how to create `Unique` keys.

Using this with an Entity without a Unique key leads to undefined behavior. A few of these functions require a single `Unique`, so using an Entity with multiple `Unique`s is also undefined. In these cases persistent's goal is to throw an exception as soon as possible, but persistent is still transitioning to that.

SQL backends automatically create uniqueness constraints, but for MongoDB you must manually place a unique index on a field to have a uniqueness constraint.

Minimal complete definition

getBy

Methods

getBy :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => Unique record -> ReaderT backend m (Maybe (Entity record)) Source #

Get a record by unique key, if available. Returns also the identifier.

### Example usage

Expand

With schema-1 and dataset-1:

    getBySpjName :: MonadIO m  => ReaderT SqlBackend m (Maybe (Entity User))
    getBySpjName = getBy $ UniqueUserName "SPJ"

    mSpjEnt <- getBySpjName

The above query when applied on dataset-1, will get this entity:

    +----+------+-----+
    | id | name | age |
    +----+------+-----+
    |  1 | SPJ  |  40 |
    +----+------+-----+

existsBy :: forall record (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend) => Unique record -> ReaderT backend m Bool Source #

Returns True if a record with this unique key exists, otherwise False.

### Example usage

Expand

With schema-1 and dataset-1:

    existsBySpjName :: MonadIO m  => ReaderT SqlBackend m Bool
    existsBySpjName = existsBy $ UniqueUserName "SPJ"

    spjEntExists <- existsBySpjName

The above query when applied on dataset-1, will return the value True.

Since: persistent-2.14.5

class (PersistQueryRead backend, PersistStoreWrite backend) => PersistQueryWrite backend where Source #

Backends supporting conditional write operations

Methods

updateWhere :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [Filter record] -> [Update record] -> ReaderT backend m () Source #

Update individual fields on any record matching the given criterion.

deleteWhere :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [Filter record] -> ReaderT backend m () Source #

Delete all records matching the given criterion.

class (PersistCore backend, PersistStoreRead backend) => PersistQueryRead backend where Source #

Backends supporting conditional read operations.

Minimal complete definition

selectSourceRes, selectKeysRes, count, exists

Methods

selectSourceRes :: forall record (m1 :: Type -> Type) (m2 :: Type -> Type). (PersistRecordBackend record backend, MonadIO m1, MonadIO m2) => [Filter record] -> [SelectOpt record] -> ReaderT backend m1 (Acquire (ConduitM () (Entity record) m2 ())) Source #

Get all records matching the given criterion in the specified order. Returns also the identifiers.

NOTE: This function returns an `Acquire` and a `ConduitM`, which implies that it streams from the database. It does not. Please use `selectList` to simplify the code. If you want streaming behavior, consider `persistent-pagination` which efficiently chunks a query into ranges, or investigate a backend-specific streaming solution.

selectFirst :: forall (m :: Type -> Type) record. (MonadIO m, PersistRecordBackend record backend) => [Filter record] -> [SelectOpt record] -> ReaderT backend m (Maybe (Entity record)) Source #

Get just the first record for the criterion.

selectKeysRes :: forall (m1 :: Type -> Type) (m2 :: Type -> Type) record. (MonadIO m1, MonadIO m2, PersistRecordBackend record backend) => [Filter record] -> [SelectOpt record] -> ReaderT backend m1 (Acquire (ConduitM () (Key record) m2 ())) Source #

Get the `Key`s of all records matching the given criterion.

type PersistStore a = PersistStoreWrite a Source #

A backwards-compatible alias for those that don't care about distinguishing between read and write queries. It signifies the assumption that, by default, a backend can write as well as read.

type PersistUnique a = PersistUniqueWrite a Source #

A backwards-compatible alias for those that don't care about distinguishing between read and write queries. It signifies the assumption that, by default, a backend can write as well as read.

type IsSqlBackend backend = (IsPersistBackend backend, BaseBackend backend ~ SqlBackend) Source #

A backend which is a wrapper around `SqlBackend`.

type SqlWriteT (m :: Type -> Type) a = forall backend. SqlBackendCanWrite backend => ReaderT backend m a Source #

Like `SqlPersistT` but compatible with any SQL backend which can handle read and write queries.

type SqlReadT (m :: Type -> Type) a = forall backend. SqlBackendCanRead backend => ReaderT backend m a Source #

Like `SqlPersistT` but compatible with any SQL backend which can handle read queries.

type SqlBackendCanWrite backend = (SqlBackendCanRead backend, PersistQueryWrite backend, PersistStoreWrite backend, PersistUniqueWrite backend) Source #

A constraint synonym which witnesses that a backend is SQL and can run read and write queries.

type SqlBackendCanRead backend = (BackendCompatible SqlBackend backend, PersistQueryRead backend, PersistStoreRead backend, PersistUniqueRead backend) Source #

A constraint synonym which witnesses that a backend is SQL and can run read queries.

newtype SqlWriteBackend Source #

An SQL backend which can handle read or write queries

The constructor was exposed in 2.10.0

Constructors

SqlWriteBackend |

Fields

- unSqlWriteBackend :: SqlBackend

#### Instances

Instances details

HasPersistBackend SqlWriteBackend |
Instance details Defined in Database.Persist.Sql.Types.Internal Associated Types type BaseBackend SqlWriteBackend Source # Methods persistBackend :: SqlWriteBackend -> BaseBackend SqlWriteBackend Source #
IsPersistBackend SqlWriteBackend |
Instance details Defined in Database.Persist.Sql.Types.Internal Methods mkPersistBackend :: BaseBackend SqlWriteBackend -> SqlWriteBackend Source #
newtype BackendKey SqlWriteBackend |

Instance details

Defined in Database.Persist.Sql.Orphan.PersistStore

newtype BackendKey SqlWriteBackend = SqlWriteBackendKey {

- unSqlWriteBackendKey :: Int64

}

type BaseBackend SqlWriteBackend |
Instance details Defined in Database.Persist.Sql.Types.Internal type BaseBackend SqlWriteBackend = SqlBackend
type Rep (BackendKey SqlWriteBackend) |
Instance details Defined in Database.Persist.Sql.Orphan.PersistStore type Rep (BackendKey SqlWriteBackend) = D1 ('MetaData "BackendKey" "Database.Persist.Sql.Orphan.PersistStore" "persistent-2.14.6.0-EwPrwCqZZwo9tyFUGF3ac2" 'True) (C1 ('MetaCons "SqlWriteBackendKey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unSqlWriteBackendKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64)))

newtype SqlReadBackend Source #

An SQL backend which can only handle read queries

The constructor was exposed in 2.10.0.

Constructors

SqlReadBackend |

Fields

- unSqlReadBackend :: SqlBackend

#### Instances

Instances details

HasPersistBackend SqlReadBackend |
Instance details Defined in Database.Persist.Sql.Types.Internal Associated Types type BaseBackend SqlReadBackend Source # Methods persistBackend :: SqlReadBackend -> BaseBackend SqlReadBackend Source #
IsPersistBackend SqlReadBackend |
Instance details Defined in Database.Persist.Sql.Types.Internal Methods mkPersistBackend :: BaseBackend SqlReadBackend -> SqlReadBackend Source #
newtype BackendKey SqlReadBackend |

Instance details

Defined in Database.Persist.Sql.Orphan.PersistStore

newtype BackendKey SqlReadBackend = SqlReadBackendKey {

- unSqlReadBackendKey :: Int64

}

type BaseBackend SqlReadBackend |
Instance details Defined in Database.Persist.Sql.Types.Internal type BaseBackend SqlReadBackend = SqlBackend
type Rep (BackendKey SqlReadBackend) |
Instance details Defined in Database.Persist.Sql.Orphan.PersistStore type Rep (BackendKey SqlReadBackend) = D1 ('MetaData "BackendKey" "Database.Persist.Sql.Orphan.PersistStore" "persistent-2.14.6.0-EwPrwCqZZwo9tyFUGF3ac2" 'True) (C1 ('MetaCons "SqlReadBackendKey" 'PrefixI 'True) (S1 ('MetaSel ('Just "unSqlReadBackendKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64)))

data ConnectionPoolConfig Source #

Values to configure a pool of database connections. See Data.Pool for details.

Since: persistent-2.11.0.0

Constructors

ConnectionPoolConfig |

Fields

- connectionPoolConfigStripes :: Int

  How many stripes to divide the pool into. See Data.Pool for details. Default: 1.

- connectionPoolConfigIdleTimeout :: NominalDiffTime

  How long connections can remain idle before being disposed of, in seconds. Default: 600

- connectionPoolConfigSize :: Int

  How many connections should be held in the connection pool. Default: 10

#### Instances

Instances details

Show ConnectionPoolConfig |
Instance details Defined in Database.Persist.Sql.Types Methods showsPrec :: Int -> ConnectionPoolConfig -> ShowS Source # show :: ConnectionPoolConfig -> String Source # showList :: [ConnectionPoolConfig] -> ShowS Source #

type ConnectionPool = Pool SqlBackend Source #

type SqlPersistM = SqlPersistT (NoLoggingT (ResourceT IO)) Source #

type SqlPersistT = ReaderT SqlBackend Source #

data PersistentSqlException Source #

Constructors

StatementAlreadyFinalized Text |
Couldn'tGetSQLConnection |

#### Instances

Instances details

Exception PersistentSqlException |
Instance details Defined in Database.Persist.Sql.Types Methods toException :: PersistentSqlException -> SomeException Source # fromException :: SomeException -> Maybe PersistentSqlException Source # displayException :: PersistentSqlException -> String Source #
Show PersistentSqlException |
Instance details Defined in Database.Persist.Sql.Types Methods showsPrec :: Int -> PersistentSqlException -> ShowS Source # show :: PersistentSqlException -> String Source # showList :: [PersistentSqlException] -> ShowS Source #

data ColumnReference Source #

This value specifies how a field references another table.

Since: persistent-2.11.0.0

Constructors

ColumnReference |

Fields

- crTableName :: !EntityNameDB

  The table name that the

  Since: persistent-2.11.0.0

- crConstraintName :: !ConstraintNameDB

  The name of the foreign key constraint.

  Since: persistent-2.11.0.0

- crFieldCascade :: !FieldCascade

  Whether or not updates/deletions to the referenced table cascade to this table.

  Since: persistent-2.11.0.0

#### Instances

Instances details

Show ColumnReference |
Instance details Defined in Database.Persist.Sql.Types Methods showsPrec :: Int -> ColumnReference -> ShowS Source # show :: ColumnReference -> String Source # showList :: [ColumnReference] -> ShowS Source #
Eq ColumnReference |
Instance details Defined in Database.Persist.Sql.Types Methods (==) :: ColumnReference -> ColumnReference -> Bool Source # (/=) :: ColumnReference -> ColumnReference -> Bool Source #
Ord ColumnReference |

Instance details

Defined in Database.Persist.Sql.Types

Methods

compare :: ColumnReference -> ColumnReference -> Ordering Source #

(<) :: ColumnReference -> ColumnReference -> Bool Source #

(<=) :: ColumnReference -> ColumnReference -> Bool Source #

(>) :: ColumnReference -> ColumnReference -> Bool Source #

(>=) :: ColumnReference -> ColumnReference -> Bool Source #

max :: ColumnReference -> ColumnReference -> ColumnReference Source #

min :: ColumnReference -> ColumnReference -> ColumnReference Source #

data Column Source #

Constructors

Column |

Fields

- cName :: !FieldNameDB
- cNull :: !Bool
- cSqlType :: !SqlType
- cDefault :: !(Maybe Text)
- cGenerated :: !(Maybe Text)
- cDefaultConstraintName :: !(Maybe ConstraintNameDB)
- cMaxLen :: !(Maybe Integer)
- cReference :: !(Maybe ColumnReference)

#### Instances

Instances details

Show Column |
Instance details Defined in Database.Persist.Sql.Types Methods showsPrec :: Int -> Column -> ShowS Source # show :: Column -> String Source # showList :: [Column] -> ShowS Source #
Eq Column |
Instance details Defined in Database.Persist.Sql.Types Methods (==) :: Column -> Column -> Bool Source # (/=) :: Column -> Column -> Bool Source #
Ord Column |
Instance details Defined in Database.Persist.Sql.Types Methods compare :: Column -> Column -> Ordering Source # (<) :: Column -> Column -> Bool Source # (<=) :: Column -> Column -> Bool Source # (>) :: Column -> Column -> Bool Source # (>=) :: Column -> Column -> Bool Source # max :: Column -> Column -> Column Source # min :: Column -> Column -> Column Source #

data BackendSpecificOverrides Source #

Record of functions to override the default behavior in `mkColumns`. It is recommended you initialize this with `emptyBackendSpecificOverrides` and override the default values, so that as new fields are added, your code still compiles.

For added safety, use the `getBackendSpecific*` and `setBackendSpecific*` functions, as a breaking change to the record field labels won't be reflected in a major version bump of the library.

Since: persistent-2.11

class PersistField a => PersistFieldSql a where Source #

Tells Persistent what database column type should be used to store a Haskell type.

#### Examples

Expand

##### Simple Boolean Alternative

    data Switch = On | Off
      deriving (Show, Eq)

    instance PersistField Switch where
      toPersistValue s = case s of
        On -> PersistBool True
        Off -> PersistBool False
      fromPersistValue (PersistBool b) = if b then Right On else Right Off
      fromPersistValue x = Left $ "File.hs: When trying to deserialize a Switch: expected PersistBool, received: " <> T.pack (show x)

    instance PersistFieldSql Switch where
      sqlType _ = SqlBool

##### Non-Standard Database Types

If your database supports non-standard types, such as Postgres' `uuid`, you can use `SqlOther` to use them:

    import qualified Data.UUID as UUID
    instance PersistField UUID where
      toPersistValue = PersistLiteralEncoded . toASCIIBytes
      fromPersistValue (PersistLiteralEncoded uuid) =
        case fromASCIIBytes uuid of
          Nothing -> Left $ "Model/CustomTypes.hs: Failed to deserialize a UUID; received: " <> T.pack (show uuid)
          Just uuid' -> Right uuid'
      fromPersistValue x = Left $ "File.hs: When trying to deserialize a UUID: expected PersistLiteralEncoded, received: "-- >  <> T.pack (show x)

    instance PersistFieldSql UUID where
      sqlType _ = SqlOther "uuid"

##### User Created Database Types

Similarly, some databases support creating custom types, e.g. Postgres' DOMAIN and ENUM features. You can use `SqlOther` to specify a custom type:

    CREATE DOMAIN ssn AS text
          CHECK ( value ~ '^[0-9]{9}$');

    instance PersistFieldSQL SSN where
      sqlType _ = SqlOther "ssn"

    CREATE TYPE rainbow_color AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet');

    instance PersistFieldSQL RainbowColor where
      sqlType _ = SqlOther "rainbow_color"

Methods

sqlType :: Proxy a -> SqlType Source #

#### Instances

Instances details

PersistFieldSql Int16 |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy Int16 -> SqlType Source #
PersistFieldSql Int32 |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy Int32 -> SqlType Source #
PersistFieldSql Int64 |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy Int64 -> SqlType Source #
PersistFieldSql Int8 |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy Int8 -> SqlType Source #
PersistFieldSql Rational |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy Rational -> SqlType Source #
PersistFieldSql Word16 |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy Word16 -> SqlType Source #
PersistFieldSql Word32 |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy Word32 -> SqlType Source #
PersistFieldSql Word64 |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy Word64 -> SqlType Source #
PersistFieldSql Word8 |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy Word8 -> SqlType Source #
PersistFieldSql Html |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy Html -> SqlType Source #
PersistFieldSql ByteString |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy ByteString -> SqlType Source #
PersistFieldSql OverflowNatural | This type uses the `SqlInt64` version, which will exhibit overflow and underflow behavior. Additionally, it permits negative values in the database, which isn't ideal. Since: persistent-2.11.0
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy OverflowNatural -> SqlType Source #
PersistFieldSql PersistValue |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy PersistValue -> SqlType Source #
PersistFieldSql Checkmark |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy Checkmark -> SqlType Source #
PersistFieldSql Text |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy Text -> SqlType Source #
PersistFieldSql Text |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy Text -> SqlType Source #
PersistFieldSql Day |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy Day -> SqlType Source #
PersistFieldSql UTCTime |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy UTCTime -> SqlType Source #
PersistFieldSql TimeOfDay |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy TimeOfDay -> SqlType Source #
PersistFieldSql Bool |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy Bool -> SqlType Source #
PersistFieldSql Double |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy Double -> SqlType Source #
PersistFieldSql Int |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy Int -> SqlType Source #
PersistFieldSql Word |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy Word -> SqlType Source #
PersistFieldSql v => PersistFieldSql (IntMap v) |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy (IntMap v) -> SqlType Source #
(Ord a, PersistFieldSql a) => PersistFieldSql (Set a) |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy (Set a) -> SqlType Source #
(FromJSON a, ToJSON a) => PersistFieldSql (JSONB a) Source # | jsonb Since: 3.1.0
Instance details Defined in Database.Esqueleto.PostgreSQL.JSON.Instances Methods sqlType :: Proxy (JSONB a) -> SqlType Source #
(PersistField record, PersistEntity record) => PersistFieldSql (Entity record) |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy (Entity record) -> SqlType Source #
PersistFieldSql a => PersistFieldSql (Vector a) |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy (Vector a) -> SqlType Source #
PersistFieldSql a => PersistFieldSql (Maybe a) |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy (Maybe a) -> SqlType Source #
PersistFieldSql [Char] |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy [Char] -> SqlType Source #
PersistFieldSql a => PersistFieldSql [a] |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy [a] -> SqlType Source #
HasResolution a => PersistFieldSql (Fixed a) |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy (Fixed a) -> SqlType Source #
PersistFieldSql v => PersistFieldSql (Map Text v) |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy (Map Text v) -> SqlType Source #
(PersistFieldSql a, PersistFieldSql b) => PersistFieldSql (a, b) |
Instance details Defined in Database.Persist.Sql.Class Methods sqlType :: Proxy (a, b) -> SqlType Source #

newtype EntityWithPrefix (prefix :: Symbol) record Source #

This newtype wrapper is useful when selecting an entity out of the database and you want to provide a prefix to the table being selected.

Consider this raw SQL query:

    SELECT ??
    FROM my_long_table_name AS mltn
    INNER JOIN other_table AS ot
       ON mltn.some_col = ot.other_col
    WHERE ...

We don't want to refer to `my_long_table_name` every time, so we create an alias. If we want to select it, we have to tell the raw SQL quasi-quoter that we expect the entity to be prefixed with some other name.

We can give the above query a type with this, like:

    getStuff :: SqlPersistM [EntityWithPrefix "mltn" MyLongTableName]
    getStuff = rawSql queryText []

The `EntityWithPrefix` bit is a boilerplate newtype wrapper, so you can remove it with `unPrefix`, like this:

    getStuff :: SqlPersistM [Entity MyLongTableName]
    getStuff = unPrefix @"mltn" <$> rawSql queryText []

The `symbol is a "type application" and requires the` TypeApplications@ language extension.

Since: persistent-2.10.5

Constructors

EntityWithPrefix |

Fields

- unEntityWithPrefix :: Entity record

#### Instances

Instances details

(PersistEntity record, KnownSymbol prefix, PersistEntityBackend record ~ backend, IsPersistBackend backend) => RawSql (EntityWithPrefix prefix record) |
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> EntityWithPrefix prefix record -> (Int, [Text]) Source # rawSqlColCountReason :: EntityWithPrefix prefix record -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (EntityWithPrefix prefix record) Source #

class RawSql a where Source #

Class for data types that may be retrived from a `rawSql` query.

Methods

rawSqlCols :: (Text -> Text) -> a -> (Int, [Text]) Source #

Number of columns that this data type needs and the list of substitutions for `SELECT` placeholders `??`.

rawSqlColCountReason :: a -> String Source #

A string telling the user why the column count is what it is.

rawSqlProcessRow :: [PersistValue] -> Either Text a Source #

Transform a row of the result into the data type.

#### Instances

Instances details

(PersistEntity record, PersistEntityBackend record ~ backend, IsPersistBackend backend) => RawSql (Entity record) |
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> Entity record -> (Int, [Text]) Source # rawSqlColCountReason :: Entity record -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (Entity record) Source #
(PersistEntity a, PersistEntityBackend a ~ backend, IsPersistBackend backend) => RawSql (Key a) |
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> Key a -> (Int, [Text]) Source # rawSqlColCountReason :: Key a -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (Key a) Source #
PersistField a => RawSql (Single a) |
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> Single a -> (Int, [Text]) Source # rawSqlColCountReason :: Single a -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (Single a) Source #
RawSql a => RawSql (Maybe a) | Since: persistent-1.0.1
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> Maybe a -> (Int, [Text]) Source # rawSqlColCountReason :: Maybe a -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (Maybe a) Source #
(PersistEntity record, KnownSymbol prefix, PersistEntityBackend record ~ backend, IsPersistBackend backend) => RawSql (EntityWithPrefix prefix record) |
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> EntityWithPrefix prefix record -> (Int, [Text]) Source # rawSqlColCountReason :: EntityWithPrefix prefix record -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (EntityWithPrefix prefix record) Source #
(RawSql a, RawSql b) => RawSql (a, b) |
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> (a, b) -> (Int, [Text]) Source # rawSqlColCountReason :: (a, b) -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b) Source #
(RawSql a, RawSql b, RawSql c) => RawSql (a, b, c) |
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> (a, b, c) -> (Int, [Text]) Source # rawSqlColCountReason :: (a, b, c) -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c) Source #
(RawSql a, RawSql b, RawSql c, RawSql d) => RawSql (a, b, c, d) |
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> (a, b, c, d) -> (Int, [Text]) Source # rawSqlColCountReason :: (a, b, c, d) -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d) Source #
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e) => RawSql (a, b, c, d, e) |
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> (a, b, c, d, e) -> (Int, [Text]) Source # rawSqlColCountReason :: (a, b, c, d, e) -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e) Source #
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f) => RawSql (a, b, c, d, e, f) |
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f) -> (Int, [Text]) Source # rawSqlColCountReason :: (a, b, c, d, e, f) -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f) Source #
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g) => RawSql (a, b, c, d, e, f, g) |
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g) -> (Int, [Text]) Source # rawSqlColCountReason :: (a, b, c, d, e, f, g) -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g) Source #
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h) => RawSql (a, b, c, d, e, f, g, h) |
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h) -> (Int, [Text]) Source # rawSqlColCountReason :: (a, b, c, d, e, f, g, h) -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h) Source #
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i) => RawSql (a, b, c, d, e, f, g, h, i) | Since: persistent-2.10.2
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i) -> (Int, [Text]) Source # rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i) -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i) Source #
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j) => RawSql (a, b, c, d, e, f, g, h, i, j) | Since: persistent-2.10.2
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j) -> (Int, [Text]) Source # rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j) -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j) Source #
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k) => RawSql (a, b, c, d, e, f, g, h, i, j, k) | Since: persistent-2.10.2
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k) -> (Int, [Text]) Source # rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k) -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k) Source #
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l) | Since: persistent-2.10.2
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l) -> (Int, [Text]) Source # rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l) -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l) Source #
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m) | Since: persistent-2.11.0
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> (Int, [Text]) Source # rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m) Source #
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n) | Since: persistent-2.11.0
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> (Int, [Text]) Source # rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source #
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) | Since: persistent-2.11.0
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> (Int, [Text]) Source # rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source #
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) | Since: persistent-2.11.0
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) -> (Int, [Text]) Source # rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) Source #
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) | Since: persistent-2.11.0
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) -> (Int, [Text]) Source # rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) Source #
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) | Since: persistent-2.11.0
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) -> (Int, [Text]) Source # rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) Source #
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) | Since: persistent-2.11.0
Instance details Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) -> (Int, [Text]) Source # rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) -> String Source # rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) Source #
(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) | Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) | Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) | Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) | Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x) | Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y) | Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) | Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2) | Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2, RawSql q2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2, RawSql q2, RawSql r2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2, RawSql q2, RawSql r2, RawSql s2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2, RawSql q2, RawSql r2, RawSql s2, RawSql t2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2, RawSql q2, RawSql r2, RawSql s2, RawSql t2, RawSql u2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2, RawSql q2, RawSql r2, RawSql s2, RawSql t2, RawSql u2, RawSql v2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2, RawSql q2, RawSql r2, RawSql s2, RawSql t2, RawSql u2, RawSql v2, RawSql w2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2, RawSql q2, RawSql r2, RawSql s2, RawSql t2, RawSql u2, RawSql v2, RawSql w2, RawSql x2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2, RawSql q2, RawSql r2, RawSql s2, RawSql t2, RawSql u2, RawSql v2, RawSql w2, RawSql x2, RawSql y2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2, RawSql q2, RawSql r2, RawSql s2, RawSql t2, RawSql u2, RawSql v2, RawSql w2, RawSql x2, RawSql y2, RawSql z2) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2, RawSql q2, RawSql r2, RawSql s2, RawSql t2, RawSql u2, RawSql v2, RawSql w2, RawSql x2, RawSql y2, RawSql z2, RawSql a3) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2, RawSql q2, RawSql r2, RawSql s2, RawSql t2, RawSql u2, RawSql v2, RawSql w2, RawSql x2, RawSql y2, RawSql z2, RawSql a3, RawSql b3) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2, RawSql q2, RawSql r2, RawSql s2, RawSql t2, RawSql u2, RawSql v2, RawSql w2, RawSql x2, RawSql y2, RawSql z2, RawSql a3, RawSql b3, RawSql c3) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2, RawSql q2, RawSql r2, RawSql s2, RawSql t2, RawSql u2, RawSql v2, RawSql w2, RawSql x2, RawSql y2, RawSql z2, RawSql a3, RawSql b3, RawSql c3, RawSql d3) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2, RawSql q2, RawSql r2, RawSql s2, RawSql t2, RawSql u2, RawSql v2, RawSql w2, RawSql x2, RawSql y2, RawSql z2, RawSql a3, RawSql b3, RawSql c3, RawSql d3, RawSql e3) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2, RawSql q2, RawSql r2, RawSql s2, RawSql t2, RawSql u2, RawSql v2, RawSql w2, RawSql x2, RawSql y2, RawSql z2, RawSql a3, RawSql b3, RawSql c3, RawSql d3, RawSql e3, RawSql f3) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3, f3)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3, f3) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3, f3) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3, f3) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2, RawSql q2, RawSql r2, RawSql s2, RawSql t2, RawSql u2, RawSql v2, RawSql w2, RawSql x2, RawSql y2, RawSql z2, RawSql a3, RawSql b3, RawSql c3, RawSql d3, RawSql e3, RawSql f3, RawSql g3) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3, f3, g3)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3, f3, g3) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3, f3, g3) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3, f3, g3) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2, RawSql q2, RawSql r2, RawSql s2, RawSql t2, RawSql u2, RawSql v2, RawSql w2, RawSql x2, RawSql y2, RawSql z2, RawSql a3, RawSql b3, RawSql c3, RawSql d3, RawSql e3, RawSql f3, RawSql g3, RawSql h3) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3, f3, g3, h3)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3, f3, g3, h3) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3, f3, g3, h3) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3, f3, g3, h3) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2, RawSql q2, RawSql r2, RawSql s2, RawSql t2, RawSql u2, RawSql v2, RawSql w2, RawSql x2, RawSql y2, RawSql z2, RawSql a3, RawSql b3, RawSql c3, RawSql d3, RawSql e3, RawSql f3, RawSql g3, RawSql h3, RawSql i3) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3, f3, g3, h3, i3)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3, f3, g3, h3, i3) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3, f3, g3, h3, i3) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3, f3, g3, h3, i3) Source #

(RawSql a, RawSql b, RawSql c, RawSql d, RawSql e, RawSql f, RawSql g, RawSql h, RawSql i, RawSql j, RawSql k, RawSql l, RawSql m, RawSql n, RawSql o, RawSql p, RawSql q, RawSql r, RawSql s, RawSql t, RawSql u, RawSql v, RawSql w, RawSql x, RawSql y, RawSql z, RawSql a2, RawSql b2, RawSql c2, RawSql d2, RawSql e2, RawSql f2, RawSql g2, RawSql h2, RawSql i2, RawSql j2, RawSql k2, RawSql l2, RawSql m2, RawSql n2, RawSql o2, RawSql p2, RawSql q2, RawSql r2, RawSql s2, RawSql t2, RawSql u2, RawSql v2, RawSql w2, RawSql x2, RawSql y2, RawSql z2, RawSql a3, RawSql b3, RawSql c3, RawSql d3, RawSql e3, RawSql f3, RawSql g3, RawSql h3, RawSql i3, RawSql j3) => RawSql (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3, f3, g3, h3, i3, j3)

Since: persistent-2.11.0

Instance details

Defined in Database.Persist.Sql.Class

Methods

rawSqlCols :: (Text -> Text) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3, f3, g3, h3, i3, j3) -> (Int, [Text]) Source #

rawSqlColCountReason :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3, f3, g3, h3, i3, j3) -> String Source #

rawSqlProcessRow :: [PersistValue] -> Either Text (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2, q2, r2, s2, t2, u2, v2, w2, x2, y2, z2, a3, b3, c3, d3, e3, f3, g3, h3, i3, j3) Source #

data FilterTablePrefix Source #

Used when determining how to prefix a column name in a `WHERE` clause.

Since: persistent-2.12.1.0

Constructors

PrefixTableName | Prefix the column with the table name. This is useful if the column name might be ambiguous. Since: persistent-2.12.1.0
PrefixExcluded | Prefix the column name with the `EXCLUDED` keyword. This is used with the Postgresql backend when doing `ON CONFLICT DO UPDATE` clauses - see the documentation on `upsertWhere` and `upsertManyWhere`. Since: persistent-2.12.1.0

newtype PersistUnsafeMigrationException Source #

An exception indicating that Persistent refused to run some unsafe migrations. Contains a list of pairs where the Bool tracks whether the migration was unsafe (True means unsafe), and the Sql is the sql statement for the migration.

Since: persistent-2.11.1.0

Constructors

PersistUnsafeMigrationException [(Bool, Sql)] |

#### Instances

Instances details

Exception PersistUnsafeMigrationException |
Instance details Defined in Database.Persist.Sql.Migration Methods toException :: PersistUnsafeMigrationException -> SomeException Source # fromException :: SomeException -> Maybe PersistUnsafeMigrationException Source # displayException :: PersistUnsafeMigrationException -> String Source #
Show PersistUnsafeMigrationException | This `Show` instance renders an error message suitable for printing to the console. This is a little dodgy, but since GHC uses Show instances when displaying uncaught exceptions, we have little choice.
Instance details Defined in Database.Persist.Sql.Migration Methods showsPrec :: Int -> PersistUnsafeMigrationException -> ShowS Source # show :: PersistUnsafeMigrationException -> String Source # showList :: [PersistUnsafeMigrationException] -> ShowS Source #

type Migration = WriterT [Text] (WriterT CautiousMigration (ReaderT SqlBackend IO)) () Source #

A `Migration` is a four level monad stack consisting of:

- ``WriterT` [`Text`]` representing a log of errors in the migrations.
- ``WriterT` `CautiousMigration`` representing a list of migrations to run, along with whether or not they are safe.
- ``ReaderT` `SqlBackend``, aka the `SqlPersistT` transformer for database interop.
- ``IO`` for arbitrary IO.

type CautiousMigration = [(Bool, Sql)] Source #

A list of SQL operations, marked with a safety flag. If the `Bool` is `True`, then the operation is *unsafe* - it might be destructive, or otherwise not idempotent. If the `Bool` is `False`, then the operation is *safe*, and can be run repeatedly without issues.

type Sql = Text Source #

insertBy :: forall record backend (m :: Type -> Type). (MonadIO m, PersistUniqueWrite backend, PersistRecordBackend record backend, AtLeastOneUniqueKey record, SafeToInsert record) => record -> ReaderT backend m (Either (Entity record) (Key record)) Source #

Insert a value, checking for conflicts with any unique constraints. If a duplicate exists in the database, it is returned as `Left`. Otherwise, the new 'Key is returned as `Right`.

### Example usage

Expand

With schema-2 and dataset-1, we have following lines of code:

    l1 <- insertBy $ User "SPJ" 20
    l2 <- insertBy $ User "XXX" 41
    l3 <- insertBy $ User "SPJ" 40
    r1 <- insertBy $ User "XXX" 100

First three lines return `Left` because there're duplicates in given record's uniqueness constraints. While the last line returns a new key as `Right`.

migrate :: [EntityDef] -> EntityDef -> Migration Source #

Given a list of old entity definitions and a new `EntityDef` in `val`, this creates a `Migration` to update the old list of definitions with the new one.

reportError :: Text -> Migration Source #

Report a single error in a `Migration`.

Since: persistent-2.9.2

rawSql Source #

Arguments

:: forall a (m :: Type -> Type) backend. (RawSql a, MonadIO m, BackendCompatible SqlBackend backend) |
=> Text | SQL statement, possibly with placeholders.
-> [PersistValue] | Values to fill the placeholders.
-> ReaderT backend m [a] |

Execute a raw SQL statement and return its results as a list. If you do not expect a return value, use of `rawExecute` is recommended.

If you're using `Entity` `s` (which is quite likely), then you must use entity selection placeholders (double question mark, `??`). These `??` placeholders are then replaced for the names of the columns that we need for your entities. You'll receive an error if you don't use the placeholders. Please see the `Entity` `s` documentation for more details.

You may put value placeholders (question marks, `?`) in your SQL query. These placeholders are then replaced by the values you pass on the second parameter, already correctly escaped. You may want to use `toPersistValue` to help you constructing the placeholder values.

Since you're giving a raw SQL statement, you don't get any guarantees regarding safety. If `rawSql` is not able to parse the results of your query back, then an exception is raised. However, most common problems are mitigated by using the entity selection placeholder `??`, and you shouldn't see any error at all if you're not using `Single`.

Some example of `rawSql` based on this schema:

    share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
    Person
        name String
        age Int Maybe
        deriving Show
    BlogPost
        title String
        authorId PersonId
        deriving Show
    |]

Examples based on the above schema:

    getPerson :: MonadIO m => ReaderT SqlBackend m [Entity Person]
    getPerson = rawSql "select ?? from person where name=?" [PersistText "john"]

    getAge :: MonadIO m => ReaderT SqlBackend m [Single Int]
    getAge = rawSql "select person.age from person where name=?" [PersistText "john"]

    getAgeName :: MonadIO m => ReaderT SqlBackend m [(Single Int, Single Text)]
    getAgeName = rawSql "select person.age, person.name from person where name=?" [PersistText "john"]

    getPersonBlog :: MonadIO m => ReaderT SqlBackend m [(Entity Person, Entity BlogPost)]
    getPersonBlog = rawSql "select ??,?? from person,blog_post where person.id = blog_post.author_id" []

Minimal working program for PostgreSQL backend based on the above concepts:

    {-# LANGUAGE EmptyDataDecls             #-}
    {-# LANGUAGE FlexibleContexts           #-}
    {-# LANGUAGE GADTs                      #-}
    {-# LANGUAGE GeneralizedNewtypeDeriving #-}
    {-# LANGUAGE MultiParamTypeClasses      #-}
    {-# LANGUAGE OverloadedStrings          #-}
    {-# LANGUAGE QuasiQuotes                #-}
    {-# LANGUAGE TemplateHaskell            #-}
    {-# LANGUAGE TypeFamilies               #-}

    import           Control.Monad.IO.Class  (liftIO)
    import           Control.Monad.Logger    (runStderrLoggingT)
    import           Database.Persist
    import           Control.Monad.Reader
    import           Data.Text
    import           Database.Persist.Sql
    import           Database.Persist.Postgresql
    import           Database.Persist.TH

    share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
    Person
        name String
        age Int Maybe
        deriving Show
    |]

    conn = "host=localhost dbname=new_db user=postgres password=postgres port=5432"

    getPerson :: MonadIO m => ReaderT SqlBackend m [Entity Person]
    getPerson = rawSql "select ?? from person where name=?" [PersistText "sibi"]

    liftSqlPersistMPool y x = liftIO (runSqlPersistMPool y x)

    main :: IO ()
    main = runStderrLoggingT $ withPostgresqlPool conn 10 $ liftSqlPersistMPool $ do
             runMigration migrateAll
             xs <- getPerson
             liftIO (print xs)

fromPersistValueText :: PersistValue -> Either Text Text Source #

fieldAttrsContainsNullable :: [FieldAttr] -> IsNullable Source #

entitiesPrimary :: EntityDef -> NonEmpty FieldDef Source #

Return the `[`FieldDef`]` for the entity keys.

entityPrimary :: EntityDef -> Maybe CompositeDef Source #

keyAndEntityFields :: EntityDef -> NonEmpty FieldDef Source #

Returns a `NonEmpty` list of `FieldDef` that correspond with the key columns for an `EntityDef`.

parseFieldAttrs :: [Text] -> [FieldAttr] Source #

Parse raw field attributes into structured form. Any unrecognized attributes will be preserved, identically as they are encountered, as `FieldAttrOther` values.

Since: persistent-2.11.0.0

isFieldNotGenerated :: FieldDef -> Bool Source #

isHaskellField :: FieldDef -> Bool Source #

Returns `True` if the `FieldDef` does not have a `MigrationOnly` or `SafeToRemove` flag from the QuasiQuoter.

Since: persistent-2.13.0.0

noCascade :: FieldCascade Source #

A `FieldCascade` that does nothing.

Since: persistent-2.11.0

renderFieldCascade :: FieldCascade -> Text Source #

Renders a `FieldCascade` value such that it can be used in SQL migrations.

Since: persistent-2.11.0

renderCascadeAction :: CascadeAction -> Text Source #

Render a `CascadeAction` to `Text` such that it can be used in a SQL command.

Since: persistent-2.11.0

setFieldAttrs :: [FieldAttr] -> FieldDef -> FieldDef Source #

Replace the `FieldDef` `FieldAttr` with the new list.

Since: persistent-2.13.0.0

overFieldAttrs :: ([FieldAttr] -> [FieldAttr]) -> FieldDef -> FieldDef Source #

Modify the list of field attributes.

Since: persistent-2.13.0.0

addFieldAttr :: FieldAttr -> FieldDef -> FieldDef Source #

Add an attribute to the list of field attributes.

Since: persistent-2.13.0.0

isFieldNullable :: FieldDef -> IsNullable Source #

Check if the field definition is nullable

Since: persistent-2.13.0.0

isFieldMaybe :: FieldDef -> Bool Source #

Check if the field is `Maybe a`

Since: persistent-2.13.0.0

getEntityUniquesNoPrimaryKey :: EntityDef -> [UniqueDef] Source #

Retrieve the list of `UniqueDef` from an `EntityDef`. This does not include a `Primary` key, if one is defined. A future version of `persistent` will include a `Primary` key among the `Unique` constructors for the `Entity`.

Since: persistent-2.14.0.0

getEntityUniques :: EntityDef -> [UniqueDef] Source #

Retrieve the list of `UniqueDef` from an `EntityDef`. As of version 2.14, this will also include the primary key on the entity, if one is defined. If you do not want the primary key, see `getEntityUniquesNoPrimaryKey`.

Since: persistent-2.13.0.0

getEntityHaskellName :: EntityDef -> EntityNameHS Source #

Retrieve the Haskell name of the given entity.

Since: persistent-2.13.0.0

getEntityDBName :: EntityDef -> EntityNameDB Source #

Return the database name for the given entity.

Since: persistent-2.13.0.0

getEntityExtra :: EntityDef -> Map Text [[Text]] Source #

setEntityDBName :: EntityNameDB -> EntityDef -> EntityDef Source #

Since: persistent-2.13.0.0

getEntityComments :: EntityDef -> Maybe Text Source #

getEntityForeignDefs :: EntityDef -> [ForeignDef] Source #

Since: persistent-2.13.0.0

getEntityFields :: EntityDef -> [FieldDef] Source #

Retrieve the list of `FieldDef` that makes up the fields of the entity.

This does not return the fields for an `Id` column or an implicit `id`. It will return the key columns if you used the `Primary` syntax for defining the primary key.

This does not return fields that are marked `SafeToRemove` or `MigrationOnly` - so it only returns fields that are represented in the Haskell type. If you need those fields, use `getEntityFieldsDatabase`.

Since: persistent-2.13.0.0

getEntityFieldsDatabase :: EntityDef -> [FieldDef] Source #

This returns all of the `FieldDef` defined for the `EntityDef`, including those fields that are marked as `MigrationOnly` (and therefore only present in the database) or `SafeToRemove` (and a migration will drop the column if it exists in the database).

For all the fields that are present on the Haskell-type, see `getEntityFields`.

Since: persistent-2.13.0.0

isEntitySum :: EntityDef -> Bool Source #

Since: persistent-2.13.0.0

getEntityId :: EntityDef -> EntityIdDef Source #

Since: persistent-2.13.0.0

getEntityIdField :: EntityDef -> Maybe FieldDef Source #

Since: persistent-2.13.0.0

setEntityId :: FieldDef -> EntityDef -> EntityDef Source #

Set an `entityId` to be the given `FieldDef`.

Since: persistent-2.13.0.0

setEntityIdDef :: EntityIdDef -> EntityDef -> EntityDef Source #

Since: persistent-2.13.0.0

getEntityKeyFields :: EntityDef -> NonEmpty FieldDef Source #

Since: persistent-2.13.0.0

overEntityFields :: ([FieldDef] -> [FieldDef]) -> EntityDef -> EntityDef Source #

Perform a mapping function over all of the entity fields, as determined by `getEntityFieldsDatabase`.

Since: persistent-2.13.0.0

tabulateEntity :: PersistEntity record => (forall a. EntityField record a -> a) -> Entity record Source #

Construct an ``Entity` record` by providing a value for each of the record's fields.

These constructions are equivalent:

    entityMattConstructor, entityMattTabulate :: Entity User
    entityMattConstructor =
        Entity
            { entityKey = toSqlKey 123
            , entityVal =
                User
                    { userName = Matt
                    , userAge = 33
                    }
            }

    entityMattTabulate =
        tabulateEntity $ \case
            UserId ->
                toSqlKey 123
            UserName ->
                Matt
            UserAge ->
                33

This is a specialization of `tabulateEntityA`, which allows you to construct an `Entity` by providing an `Applicative` action for each field instead of a regular function.

Since: persistent-2.14.0.0

entityValues :: PersistEntity record => Entity record -> [PersistValue] Source #

Get list of values corresponding to given entity.

keyValueEntityToJSON :: (PersistEntity record, ToJSON record) => Entity record -> Value Source #

Predefined `toJSON`. The resulting JSON looks like `{"key": 1, "value": {"name": ...}}`.

The typical usage is:

    instance ToJSON (Entity User) where
        toJSON = keyValueEntityToJSON

keyValueEntityFromJSON :: (PersistEntity record, FromJSON record) => Value -> Parser (Entity record) Source #

Predefined `parseJSON`. The input JSON looks like `{"key": 1, "value": {"name": ...}}`.

The typical usage is:

    instance FromJSON (Entity User) where
        parseJSON = keyValueEntityFromJSON

entityIdToJSON :: (PersistEntity record, ToJSON record) => Entity record -> Value Source #

Predefined `toJSON`. The resulting JSON looks like `{"id": 1, "name": ...}`.

The typical usage is:

    instance ToJSON (Entity User) where
        toJSON = entityIdToJSON

entityIdFromJSON :: (PersistEntity record, FromJSON record) => Value -> Parser (Entity record) Source #

Predefined `parseJSON`. The input JSON looks like `{"id": 1, "name": ...}`.

The typical usage is:

    instance FromJSON (Entity User) where
        parseJSON = entityIdFromJSON

toPersistValueJSON :: ToJSON a => a -> PersistValue Source #

Convenience function for getting a free `PersistField` instance from a type with JSON instances.

Example usage in combination with `fromPersistValueJSON`:

    instance PersistField MyData where
      fromPersistValue = fromPersistValueJSON
      toPersistValue = toPersistValueJSON

fromPersistValueJSON :: FromJSON a => PersistValue -> Either Text a Source #

Convenience function for getting a free `PersistField` instance from a type with JSON instances. The JSON parser used will accept JSON values other that object and arrays. So, if your instance serializes the data to a JSON string, this will still work.

Example usage in combination with `toPersistValueJSON`:

    instance PersistField MyData where
      fromPersistValue = fromPersistValueJSON
      toPersistValue = toPersistValueJSON

withBaseBackend :: forall backend (m :: Type -> Type) a. HasPersistBackend backend => ReaderT (BaseBackend backend) m a -> ReaderT backend m a Source #

Run a query against a larger backend by plucking out `BaseBackend backend`

This is a helper for reusing existing queries when expanding the backend type.

Since: persistent-2.12.0

withCompatibleBackend :: forall sup sub (m :: Type -> Type) a. BackendCompatible sup sub => ReaderT sup m a -> ReaderT sub m a Source #

Run a query against a compatible backend, by projecting the backend

This is a helper for using queries which run against a specific backend type that your backend is compatible with.

Since: persistent-2.12.0

liftPersist :: (MonadIO m, MonadReader backend m) => ReaderT backend IO b -> m b Source #

getJust :: forall record backend (m :: Type -> Type). (PersistStoreRead backend, PersistRecordBackend record backend, MonadIO m) => Key record -> ReaderT backend m record Source #

Same as `get`, but for a non-null (not Maybe) foreign key. Unsafe unless your database is enforcing that the foreign key is valid.

### Example usage

Expand

With schema-1 and dataset-1,

    getJustSpj :: MonadIO m => ReaderT SqlBackend m User
    getJustSpj = getJust spjId

    spj <- getJust spjId

The above query when applied on dataset-1, will get this record:

    +----+------+-----+
    | id | name | age |
    +----+------+-----+
    |  1 | SPJ  |  40 |
    +----+------+-----+

    getJustUnknown :: MonadIO m => ReaderT SqlBackend m User
    getJustUnknown = getJust unknownId

mrx <- getJustUnknown

This just throws an error.

getJustEntity :: forall record backend (m :: Type -> Type). (PersistEntityBackend record ~ BaseBackend backend, MonadIO m, PersistEntity record, PersistStoreRead backend) => Key record -> ReaderT backend m (Entity record) Source #

Same as `getJust`, but returns an `Entity` instead of just the record.

### Example usage

Expand

With schema-1 and dataset-1,

    getJustEntitySpj :: MonadIO m => ReaderT SqlBackend m (Entity User)
    getJustEntitySpj = getJustEntity spjId

    spjEnt <- getJustEntitySpj

The above query when applied on dataset-1, will get this entity:

    +----+------+-----+
    | id | name | age |
    +----+------+-----+
    |  1 | SPJ  |  40 |
    +----+------+-----+

Since: persistent-2.6.1

belongsTo :: forall ent1 ent2 backend (m :: Type -> Type). (PersistStoreRead backend, PersistEntity ent1, PersistRecordBackend ent2 backend, MonadIO m) => (ent1 -> Maybe (Key ent2)) -> ent1 -> ReaderT backend m (Maybe ent2) Source #

Curry this to make a convenience function that loads an associated model.

    foreign = belongsTo foreignId

belongsToJust :: forall ent1 ent2 backend (m :: Type -> Type). (PersistStoreRead backend, PersistEntity ent1, PersistRecordBackend ent2 backend, MonadIO m) => (ent1 -> Key ent2) -> ent1 -> ReaderT backend m ent2 Source #

Same as `belongsTo`, but uses `getJust` and therefore is similarly unsafe.

insertEntity :: forall e backend (m :: Type -> Type). (PersistStoreWrite backend, PersistRecordBackend e backend, SafeToInsert e, MonadIO m, HasCallStack) => e -> ReaderT backend m (Entity e) Source #

Like `insert`, but returns the complete `Entity`.

### Example usage

Expand

With schema-1 and dataset-1,

    insertHaskellEntity :: MonadIO m => ReaderT SqlBackend m (Entity User)
    insertHaskellEntity = insertEntity $ User "Haskell" 81

    haskellEnt <- insertHaskellEntity

The above query when applied on dataset-1, will produce this:

    +----+---------+-----+
    | id |  name   | age |
    +----+---------+-----+
    |  1 | SPJ     |  40 |
    +----+---------+-----+
    |  2 | Simon   |  41 |
    +----+---------+-----+
    |  3 | Haskell |  81 |
    +----+---------+-----+

getEntity :: forall e backend (m :: Type -> Type). (PersistStoreRead backend, PersistRecordBackend e backend, MonadIO m) => Key e -> ReaderT backend m (Maybe (Entity e)) Source #

Like `get`, but returns the complete `Entity`.

### Example usage

Expand

With schema-1 and dataset-1,

    getSpjEntity :: MonadIO m => ReaderT SqlBackend m (Maybe (Entity User))
    getSpjEntity = getEntity spjId

    mSpjEnt <- getSpjEntity

The above query when applied on dataset-1, will get this entity:

    +----+------+-----+
    | id | name | age |
    +----+------+-----+
    |  1 | SPJ  |  40 |
    +----+------+-----+

insertRecord :: forall record backend (m :: Type -> Type). (PersistEntityBackend record ~ BaseBackend backend, PersistEntity record, MonadIO m, PersistStoreWrite backend, SafeToInsert record, HasCallStack) => record -> ReaderT backend m record Source #

Like `insertEntity` but just returns the record instead of `Entity`.

### Example usage

Expand

With schema-1 and dataset-1,

    insertDaveRecord :: MonadIO m => ReaderT SqlBackend m User
    insertDaveRecord = insertRecord $ User "Dave" 50

    dave <- insertDaveRecord

The above query when applied on dataset-1, will produce this:

    +-----+------+-----+
    |id   |name  |age  |
    +-----+------+-----+
    |1    |SPJ   |40   |
    +-----+------+-----+
    |2    |Simon |41   |
    +-----+------+-----+
    |3    |Dave  |50   |
    +-----+------+-----+

Since: persistent-2.6.1

onlyOneUniqueDef :: (OnlyOneUniqueKey record, Monad proxy) => proxy record -> UniqueDef Source #

Given a proxy for a `PersistEntity` record, this returns the sole `UniqueDef` for that entity.

Since: persistent-2.13.0.0

insertUniqueEntity :: forall record backend (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, PersistUniqueWrite backend, SafeToInsert record) => record -> ReaderT backend m (Maybe (Entity record)) Source #

Like `insertEntity`, but returns `Nothing` when the record couldn't be inserted because of a uniqueness constraint.

### Example usage

Expand

We use schema-2 and dataset-1 here.

    insertUniqueSpjEntity :: MonadIO m => ReaderT SqlBackend m (Maybe (Entity User))
    insertUniqueSpjEntity = insertUniqueEntity $ User "SPJ" 50

    mSpjEnt <- insertUniqueSpjEntity

The above query results `Nothing` as SPJ already exists.

    insertUniqueAlexaEntity :: MonadIO m => ReaderT SqlBackend m (Maybe (Entity User))
    insertUniqueAlexaEntity = insertUniqueEntity $ User "Alexa" 3

    mAlexaEnt <- insertUniqueSpjEntity

Because there's no such unique keywords of the given record, the above query when applied on dataset-1, will produce this:

    +----+-------+-----+
    | id | name  | age |
    +----+-------+-----+
    |  1 | SPJ   |  40 |
    +----+-------+-----+
    |  2 | Simon |  41 |
    +----+-------+-----+
    |  3 | Alexa |   3 |
    +----+-------+-----+

Since: persistent-2.7.1

onlyUnique :: forall record backend (m :: Type -> Type). (MonadIO m, PersistUniqueWrite backend, PersistRecordBackend record backend, OnlyOneUniqueKey record) => record -> ReaderT backend m (Unique record) Source #

Return the single unique key for a record.

### Example usage

Expand

We use shcema-1 and dataset-1 here.

    onlySimonConst :: MonadIO m => ReaderT SqlBackend m (Unique User)
    onlySimonConst = onlyUnique $ User "Simon" 999

    mSimonConst <- onlySimonConst

`mSimonConst` would be Simon's uniqueness constraint. Note that `onlyUnique` doesn't work if there're more than two constraints. It will fail with a type error instead.

getByValue :: forall record (m :: Type -> Type) backend. (MonadIO m, PersistUniqueRead backend, PersistRecordBackend record backend, AtLeastOneUniqueKey record) => record -> ReaderT backend m (Maybe (Entity record)) Source #

A modification of `getBy`, which takes the `PersistEntity` itself instead of a `Unique` record. Returns a record matching one of the unique keys. This function makes the most sense on entities with a single `Unique` constructor.

### Example usage

Expand

With schema-1 and dataset-1,

getBySpjValue :: MonadIO m => ReaderT SqlBackend m (Maybe (Entity User)) getBySpjValue = getByValue $ User SPJ 999

    mSpjEnt <- getBySpjValue

The above query when applied on dataset-1, will get this record:

    +----+------+-----+
    | id | name | age |
    +----+------+-----+
    |  1 | SPJ  |  40 |
    +----+------+-----+

replaceUnique :: forall record backend (m :: Type -> Type). (MonadIO m, Eq (Unique record), PersistRecordBackend record backend, PersistUniqueWrite backend) => Key record -> record -> ReaderT backend m (Maybe (Unique record)) Source #

Attempt to replace the record of the given key with the given new record. First query the unique fields to make sure the replacement maintains uniqueness constraints.

Return `Nothing` if the replacement was made. If uniqueness is violated, return a `Just` with the `Unique` violation

Since: persistent-1.2.2.0

checkUnique :: forall record backend (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, PersistUniqueRead backend) => record -> ReaderT backend m (Maybe (Unique record)) Source #

Check whether there are any conflicts for unique keys with this entity and existing entities in the database.

Returns `Nothing` if the entity would be unique, and could thus safely be inserted. on a conflict returns the conflicting key

### Example usage

Expand

We use schema-1 and dataset-1 here.

This would be `Nothing`:

    mAlanConst <- checkUnique $ User "Alan" 70

While this would be `Just` because SPJ already exists:

    mSpjConst <- checkUnique $ User "SPJ" 60

checkUniqueUpdateable :: forall record backend (m :: Type -> Type). (MonadIO m, PersistRecordBackend record backend, PersistUniqueRead backend) => Entity record -> ReaderT backend m (Maybe (Unique record)) Source #

Check whether there are any conflicts for unique keys with this entity and existing entities in the database.

Returns `Nothing` if the entity would stay unique, and could thus safely be updated. on a conflict returns the conflicting key

This is similar to `checkUnique`, except it's useful for updating - when the particular entity already exists, it would normally conflict with itself. This variant ignores those conflicts

### Example usage

Expand

We use schema-1 and dataset-1 here.

This would be `Nothing`:

    mAlanConst <- checkUnique $ User "Alan" 70

While this would be `Just` because SPJ already exists:

    mSpjConst <- checkUnique $ User "SPJ" 60

Since: persistent-2.11.0.0

selectKeys :: forall record backend (m :: Type -> Type). (PersistQueryRead backend, MonadResource m, PersistRecordBackend record backend, MonadReader backend m) => [Filter record] -> [SelectOpt record] -> ConduitM () (Key record) m () Source #

Get the `Key`s of all records matching the given criterion.

For an example, see `selectList`.

writeToUnknown :: forall (m :: Type -> Type) a. Monad m => ReaderT SqlWriteBackend m a -> ReaderT SqlBackend m a Source #

Useful for running a write query against an untagged backend with unknown capabilities.

readToWrite :: forall (m :: Type -> Type) a. Monad m => ReaderT SqlReadBackend m a -> ReaderT SqlWriteBackend m a Source #

Useful for running a read query against a backend with read and write capabilities.

readToUnknown :: forall (m :: Type -> Type) a. Monad m => ReaderT SqlReadBackend m a -> ReaderT SqlBackend m a Source #

Useful for running a read query against a backend with unknown capabilities.

defaultConnectionPoolConfig :: ConnectionPoolConfig Source #

Initializes a ConnectionPoolConfig with default values. See the documentation of `ConnectionPoolConfig` for each field's default value.

Since: persistent-2.11.0.0

getBackendSpecificForeignKeyName :: BackendSpecificOverrides -> Maybe (EntityNameDB -> FieldNameDB -> ConstraintNameDB) Source #

If the override is defined, then this returns a function that accepts an entity name and field name and provides the `ConstraintNameDB` for the foreign key constraint.

An abstract accessor for the `BackendSpecificOverrides`

Since: persistent-2.13.0.0

setBackendSpecificForeignKeyName :: (EntityNameDB -> FieldNameDB -> ConstraintNameDB) -> BackendSpecificOverrides -> BackendSpecificOverrides Source #

Set the backend's foreign key generation function to this value.

Since: persistent-2.13.0.0

emptyBackendSpecificOverrides :: BackendSpecificOverrides Source #

Creates an empty `BackendSpecificOverrides` (i.e. use the default behavior; no overrides)

Since: persistent-2.11

defaultAttribute :: [FieldAttr] -> Maybe Text Source #

mkColumns :: [EntityDef] -> EntityDef -> BackendSpecificOverrides -> ([Column], [UniqueDef], [ForeignDef]) Source #

Create the list of columns for the given entity.

toJsonText :: ToJSON j => j -> Text Source #

A more general way to convert instances of `ToJSON` type class to strict text `Text`.

unPrefix :: forall (prefix :: Symbol) record. EntityWithPrefix prefix record -> Entity record Source #

A helper function to tell GHC what the `EntityWithPrefix` prefix should be. This allows you to use a type application to specify the prefix, instead of specifying the etype on the result.

As an example, here's code that uses this:

    myQuery :: SqlPersistM [Entity Person]
    myQuery = fmap (unPrefix @"p") $ rawSql query []
      where
        query = "SELECT ?? FROM person AS p"

Since: persistent-2.10.5

rawQuery :: forall (m :: Type -> Type) env. (MonadResource m, MonadReader env m, BackendCompatible SqlBackend env) => Text -> [PersistValue] -> ConduitM () [PersistValue] m () Source #

rawQueryRes :: forall (m1 :: Type -> Type) (m2 :: Type -> Type) env. (MonadIO m1, MonadIO m2, BackendCompatible SqlBackend env) => Text -> [PersistValue] -> ReaderT env m1 (Acquire (ConduitM () [PersistValue] m2 ())) Source #

rawExecute Source #

Arguments

:: forall (m :: Type -> Type) backend. (MonadIO m, BackendCompatible SqlBackend backend) |
=> Text | SQL statement, possibly with placeholders.
-> [PersistValue] | Values to fill the placeholders.
-> ReaderT backend m () |

Execute a raw SQL statement

rawExecuteCount Source #

Arguments

:: forall (m :: Type -> Type) backend. (MonadIO m, BackendCompatible SqlBackend backend) |
=> Text | SQL statement, possibly with placeholders.
-> [PersistValue] | Values to fill the placeholders.
-> ReaderT backend m Int64 |

Execute a raw SQL statement and return the number of rows it has modified.

getStmtConn :: SqlBackend -> Text -> IO Statement Source #

runSqlPool :: forall backend m a. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> Pool backend -> m a Source #

Get a connection from the pool, run the given action, and then return the connection to the pool.

This function performs the given action in a transaction. If an exception occurs during the action, then the transaction is rolled back.

Note: This function previously timed out after 2 seconds, but this behavior was buggy and caused more problems than it solved. Since version 2.1.2, it performs no timeout checks.

runSqlPoolWithIsolation :: forall backend m a. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> Pool backend -> IsolationLevel -> m a Source #

Like `runSqlPool`, but supports specifying an isolation level.

Since: persistent-2.9.0

runSqlPoolNoTransaction :: forall backend m a. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> Pool backend -> Maybe IsolationLevel -> m a Source #

Like `runSqlPool`, but does not surround the action in a transaction. This action might leave your database in a weird state.

Since: persistent-2.12.0.0

runSqlPoolWithHooks Source #

Arguments

:: forall backend m a before after onException. (MonadUnliftIO m, BackendCompatible SqlBackend backend) |
=> ReaderT backend m a |
-> Pool backend |
-> Maybe IsolationLevel |
-> (backend -> m before) | Run this action immediately before the action is performed.
-> (backend -> m after) | Run this action immediately after the action is completed.
-> (backend -> SomeException -> m onException) | This action is performed when an exception is received. The exception is provided as a convenience - it is rethrown once this cleanup function is complete.
-> m a |

This function is how `runSqlPool` and `runSqlPoolNoTransaction` are defined. In addition to the action to be performed and the `Pool` of conections to use, we give you the opportunity to provide three actions - initialize, afterwards, and onException.

Since: persistent-2.12.0.0

runSqlPoolWithExtensibleHooks :: forall backend m a. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> Pool backend -> Maybe IsolationLevel -> SqlPoolHooks m backend -> m a Source #

This function is how `runSqlPoolWithHooks` is defined.

It's currently the most general function for using a SQL pool.

Since: persistent-2.13.0.0

acquireSqlConn :: (MonadReader backend m, BackendCompatible SqlBackend backend) => m (Acquire backend) Source #

Starts a new transaction on the connection. When the acquired connection is released the transaction is committed and the connection returned to the pool.

Upon an exception the transaction is rolled back and the connection destroyed.

This is equivalent to `runSqlConn` but does not incur the `MonadUnliftIO` constraint, meaning it can be used within, for example, a `Conduit` pipeline.

Since: persistent-2.10.5

acquireSqlConnWithIsolation :: (MonadReader backend m, BackendCompatible SqlBackend backend) => IsolationLevel -> m (Acquire backend) Source #

Like `acquireSqlConn`, but lets you specify an explicit isolation level.

Since: persistent-2.10.5

runSqlConn :: forall backend m a. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> backend -> m a Source #

runSqlConnWithIsolation :: forall backend m a. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> backend -> IsolationLevel -> m a Source #

Like `runSqlConn`, but supports specifying an isolation level.

Since: persistent-2.9.0

runSqlPersistM :: BackendCompatible SqlBackend backend => ReaderT backend (NoLoggingT (ResourceT IO)) a -> backend -> IO a Source #

runSqlPersistMPool :: BackendCompatible SqlBackend backend => ReaderT backend (NoLoggingT (ResourceT IO)) a -> Pool backend -> IO a Source #

liftSqlPersistMPool :: forall backend m a. (MonadIO m, BackendCompatible SqlBackend backend) => ReaderT backend (NoLoggingT (ResourceT IO)) a -> Pool backend -> m a Source #

withSqlPool Source #

Arguments

:: forall backend m a. (MonadLoggerIO m, MonadUnliftIO m, BackendCompatible SqlBackend backend) |
=> (LogFunc -> IO backend) | create a new connection
-> Int | connection count
-> (Pool backend -> m a) |
-> m a |

withSqlPoolWithConfig Source #

Arguments

:: forall backend m a. (MonadLoggerIO m, MonadUnliftIO m, BackendCompatible SqlBackend backend) |
=> (LogFunc -> IO backend) | Function to create a new connection
-> ConnectionPoolConfig |
-> (Pool backend -> m a) |
-> m a |

Creates a pool of connections to a SQL database which can be used by the `Pool backend -> m a` function. After the function completes, the connections are destroyed.

Since: persistent-2.11.0.0

createSqlPool :: forall backend m. (MonadLoggerIO m, MonadUnliftIO m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> Int -> m (Pool backend) Source #

createSqlPoolWithConfig Source #

Arguments

:: (MonadLoggerIO m, MonadUnliftIO m, BackendCompatible SqlBackend backend) |
=> (LogFunc -> IO backend) | Function to create a new connection
-> ConnectionPoolConfig |
-> m (Pool backend) |

Creates a pool of connections to a SQL database.

Since: persistent-2.11.0.0

withSqlConn :: forall backend m a. (MonadUnliftIO m, MonadLoggerIO m, BackendCompatible SqlBackend backend) => (LogFunc -> IO backend) -> (backend -> m a) -> m a Source #

Create a connection and run sql queries within it. This function automatically closes the connection on it's completion.

### Example usage

Expand

    {-# LANGUAGE GADTs #-}
    {-# LANGUAGE ScopedTypeVariables #-}
    {-# LANGUAGE OverloadedStrings #-}
    {-# LANGUAGE MultiParamTypeClasses #-}
    {-# LANGUAGE TypeFamilies#-}
    {-# LANGUAGE TemplateHaskell#-}
    {-# LANGUAGE QuasiQuotes#-}
    {-# LANGUAGE GeneralizedNewtypeDeriving #-}

    import Control.Monad.IO.Class  (liftIO)
    import Control.Monad.Logger
    import Conduit
    import Database.Persist
    import Database.Sqlite
    import Database.Persist.Sqlite
    import Database.Persist.TH

    share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
    Person
      name String
      age Int Maybe
      deriving Show
    |]

    openConnection :: LogFunc -> IO SqlBackend
    openConnection logfn = do
     conn <- open "/home/sibi/test.db"
     wrapConnection conn logfn

    main :: IO ()
    main = do
      runNoLoggingT $ runResourceT $ withSqlConn openConnection (\backend ->
                                          flip runSqlConn backend $ do
                                            runMigration migrateAll
                                            insert_ $ Person "John doe" $ Just 35
                                            insert_ $ Person "Divya" $ Just 36
                                            (pers :: [Entity Person]) <- selectList [] []
                                            liftIO $ print pers
                                            return ()
                                         )

On executing it, you get this output:

    Migrating: CREATE TABLE "person"("id" INTEGER PRIMARY KEY,"name" VARCHAR NOT NULL,"age" INTEGER NULL)
    [Entity {entityKey = PersonKey {unPersonKey = SqlBackendKey {unSqlBackendKey = 1}}, entityVal = Person {personName = "John doe", personAge = Just 35}},Entity {entityKey = PersonKey {unPersonKey = SqlBackendKey {unSqlBackendKey = 2}}, entityVal = Person {personName = "Hema", personAge = Just 36}}]

close' :: BackendCompatible SqlBackend backend => backend -> IO () Source #

withRawQuery :: forall (m :: Type -> Type) a. MonadIO m => Text -> [PersistValue] -> ConduitM [PersistValue] Void IO a -> ReaderT SqlBackend m a Source #

toSqlKey :: ToBackendKey SqlBackend record => Int64 -> Key record Source #

fromSqlKey :: ToBackendKey SqlBackend record => Key record -> Int64 Source #

getTableName :: forall record (m :: Type -> Type) backend. (PersistEntity record, BackendCompatible SqlBackend backend, Monad m) => record -> ReaderT backend m Text Source #

get the SQL string for the table that a PersistEntity represents Useful for raw SQL queries

Your backend may provide a more convenient tableName function which does not operate in a Monad

tableDBName :: PersistEntity record => record -> EntityNameDB Source #

useful for a backend to implement tableName by adding escaping

getFieldName :: forall record typ (m :: Type -> Type) backend. (PersistEntity record, PersistEntityBackend record ~ SqlBackend, BackendCompatible SqlBackend backend, Monad m) => EntityField record typ -> ReaderT backend m Text Source #

get the SQL string for the field that an EntityField represents Useful for raw SQL queries

Your backend may provide a more convenient fieldName function which does not operate in a Monad

fieldDBName :: PersistEntity record => EntityField record typ -> FieldNameDB Source #

useful for a backend to implement fieldName by adding escaping

filterClause Source #

Arguments

:: PersistEntity val |
=> Maybe FilterTablePrefix | include table name or EXCLUDED
-> SqlBackend |
-> [Filter val] |
-> Text |

Render a `[`Filter` record]` into a `Text` value suitable for inclusion into a SQL query.

Since: persistent-2.12.1.0

filterClauseWithVals Source #

Arguments

:: PersistEntity val |
=> Maybe FilterTablePrefix | include table name or EXCLUDED
-> SqlBackend |
-> [Filter val] |
-> (Text, [PersistValue]) |

Render a `[`Filter` record]` into a `Text` value suitable for inclusion into a SQL query, as well as the `[`PersistValue`]` to properly fill in the `?` place holders.

Since: persistent-2.12.1.0

orderClause Source #

Arguments

:: PersistEntity val |
=> Maybe FilterTablePrefix | include table name or EXCLUDED
-> SqlBackend |
-> [SelectOpt val] |
-> Text |

Render a `[`SelectOpt` record]` made up *only* of `Asc` and `Desc` constructors into a `Text` value suitable for inclusion into a SQL query.

Since: persistent-2.13.2.0

decorateSQLWithLimitOffset :: Text -> (Int, Int) -> Text -> Text Source #

Generates sql for limit and offset for postgres, sqlite and mysql.

parseMigration :: forall (m :: Type -> Type). (HasCallStack, MonadIO m) => Migration -> ReaderT SqlBackend m (Either [Text] CautiousMigration) Source #

Given a `Migration`, this parses it and returns either a list of errors associated with the migration or a list of migrations to do.

parseMigration' :: forall (m :: Type -> Type). (HasCallStack, MonadIO m) => Migration -> ReaderT SqlBackend m CautiousMigration Source #

Like `parseMigration`, but instead of returning the value in an `Either` value, it calls `error` on the error values.

printMigration :: forall (m :: Type -> Type). (HasCallStack, MonadIO m) => Migration -> ReaderT SqlBackend m () Source #

Prints a migration.

showMigration :: forall (m :: Type -> Type). (HasCallStack, MonadIO m) => Migration -> ReaderT SqlBackend m [Text] Source #

Convert a `Migration` to a list of `Text` values corresponding to their `Sql` statements.

getMigration :: forall (m :: Type -> Type). (MonadIO m, HasCallStack) => Migration -> ReaderT SqlBackend m [Sql] Source #

Return all of the `Sql` values associated with the given migration. Calls `error` if there's a parse error on any migration.

runMigration :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m () Source #

Runs a migration. If the migration fails to parse or if any of the migrations are unsafe, then this throws a `PersistUnsafeMigrationException`.

runMigrationQuiet :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m [Text] Source #

Same as `runMigration`, but does not report the individual migrations on stderr. Instead it returns a list of the executed SQL commands.

This is a safer/more robust alternative to `runMigrationSilent`, but may be less silent for some persistent implementations, most notably persistent-postgresql

Since: persistent-2.10.2

runMigrationSilent :: forall (m :: Type -> Type). MonadUnliftIO m => Migration -> ReaderT SqlBackend m [Text] Source #

Same as `runMigration`, but returns a list of the SQL commands executed instead of printing them to stderr.

This function silences the migration by remapping `stderr`. As a result, it is not thread-safe and can clobber output from other parts of the program. This implementation method was chosen to also silence postgresql migration output on stderr, but is not recommended!

runMigrationUnsafe :: forall (m :: Type -> Type). MonadIO m => Migration -> ReaderT SqlBackend m () Source #

Like `runMigration`, but this will perform the unsafe database migrations instead of erroring out.

runMigrationUnsafeQuiet :: forall (m :: Type -> Type). (HasCallStack, MonadIO m) => Migration -> ReaderT SqlBackend m [Text] Source #

Same as `runMigrationUnsafe`, but returns a list of the SQL commands executed instead of printing them to stderr.

Since: persistent-2.10.2

reportErrors :: [Text] -> Migration Source #

Report multiple errors in a `Migration`.

Since: persistent-2.9.2

addMigration Source #

Arguments

:: Bool | Is the migration unsafe to run? (eg a destructive or non-idempotent update on the schema). If `True`, the migration is *unsafe*, and will need to be run manually later. If `False`, the migration is *safe*, and can be run any number of times.
-> Sql | A `Text` value representing the command to run on the database.
-> Migration |

Add a migration to the migration plan.

Since: persistent-2.9.2

addMigrations :: CautiousMigration -> Migration Source #

Add a `CautiousMigration` (aka a `[(`Bool`, `Text`)]`) to the migration plan.

Since: persistent-2.9.2

runSqlCommand :: SqlPersistT IO () -> Migration Source #

Run an action against the database during a migration. Can be useful for eg creating Postgres extensions:

    runSqlCommand $ rawExecute "CREATE EXTENSION IF NOT EXISTS "uuid-ossp";" []

Since: persistent-2.13.0.0

transactionSave :: forall (m :: Type -> Type). MonadIO m => ReaderT SqlBackend m () Source #

Commit the current transaction and begin a new one. This is used when a transaction commit is required within the context of `runSqlConn` (which brackets its provided action with a transaction begin/commit pair).

Since: persistent-1.2.0

transactionSaveWithIsolation :: forall (m :: Type -> Type). MonadIO m => IsolationLevel -> ReaderT SqlBackend m () Source #

Commit the current transaction and begin a new one with the specified isolation level.

Since: persistent-2.9.0

transactionUndo :: forall (m :: Type -> Type). MonadIO m => ReaderT SqlBackend m () Source #

Roll back the current transaction and begin a new one. This rolls back to the state of the last call to `transactionSave` or the enclosing `runSqlConn` call.

Since: persistent-1.2.0

transactionUndoWithIsolation :: forall (m :: Type -> Type). MonadIO m => IsolationLevel -> ReaderT SqlBackend m () Source #

Roll back the current transaction and begin a new one with the specified isolation level.

Since: persistent-2.9.0