Database.Persist.Sql.Types.Internal

persistent-2.6: Type-safe, multi-backend data serialization.

Safe Haskell | None
Language | Haskell98

Database.Persist.Sql.Types.Internal

Synopsis

- class HasPersistBackend backend where
  - type BaseBackend backend
- class HasPersistBackend backend => IsPersistBackend backend where
- data SqlReadBackend
- data SqlWriteBackend
- readToUnknown :: Monad m => ReaderT SqlReadBackend m a -> ReaderT SqlBackend m a
- readToWrite :: Monad m => ReaderT SqlReadBackend m a -> ReaderT SqlWriteBackend m a
- writeToUnknown :: Monad m => ReaderT SqlWriteBackend m a -> ReaderT SqlBackend m a
- type LogFunc = Loc -> LogSource -> LogLevel -> LogStr -> IO ()
- data InsertSqlResult
  - = ISRSingle Text
  - | ISRInsertGet Text Text
  - | ISRManyKeys Text [PersistValue]
- data Statement = Statement {
  - stmtFinalize :: IO ()
  - stmtReset :: IO ()
  - stmtExecute :: [PersistValue] -> IO Int64
  - stmtQuery :: forall m. MonadIO m => [PersistValue] -> Acquire (Source m [PersistValue])
  }
- data SqlBackend = SqlBackend {
  - connPrepare :: Text -> IO Statement
  - connInsertSql :: EntityDef -> [PersistValue] -> InsertSqlResult
  - connInsertManySql :: Maybe (EntityDef -> [[PersistValue]] -> InsertSqlResult)
  - connUpsertSql :: Maybe (EntityDef -> Text -> Text)
  - connStmtMap :: IORef (Map Text Statement)
  - connClose :: IO ()
  - connMigrateSql :: [EntityDef] -> (Text -> IO Statement) -> EntityDef -> IO (Either [Text] [(Bool, Text)])
  - connBegin :: (Text -> IO Statement) -> IO ()
  - connCommit :: (Text -> IO Statement) -> IO ()
  - connRollback :: (Text -> IO Statement) -> IO ()
  - connEscapeName :: DBName -> Text
  - connNoLimit :: Text
  - connRDBMS :: Text
  - connLimitOffset :: (Int, Int) -> Bool -> Text -> Text
  - connLogFunc :: LogFunc
  }
- type SqlBackendCanRead backend = (IsSqlBackend backend, PersistQueryRead backend, PersistStoreRead backend, PersistUniqueRead backend)
- type SqlBackendCanWrite backend = (SqlBackendCanRead backend, PersistQueryWrite backend, PersistStoreWrite backend, PersistUniqueWrite backend)
- type SqlReadT m a = forall backend. SqlBackendCanRead backend => ReaderT backend m a
- type SqlWriteT m a = forall backend. SqlBackendCanWrite backend => ReaderT backend m a
- type IsSqlBackend backend = (IsPersistBackend backend, BaseBackend backend ~ SqlBackend)

# Documentation

class HasPersistBackend backend where #

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`

Minimal complete definition

persistBackend

Associated Types

type BaseBackend backend #

Methods

persistBackend :: backend -> BaseBackend backend #

Instances

HasPersistBackend SqlWriteBackend # |
Associated Types type BaseBackend SqlWriteBackend :: * # Methods persistBackend :: SqlWriteBackend -> BaseBackend SqlWriteBackend #
HasPersistBackend SqlReadBackend # |
Associated Types type BaseBackend SqlReadBackend :: * # Methods persistBackend :: SqlReadBackend -> BaseBackend SqlReadBackend #
HasPersistBackend SqlBackend # |
Associated Types type BaseBackend SqlBackend :: * # Methods persistBackend :: SqlBackend -> BaseBackend SqlBackend #

class HasPersistBackend backend => IsPersistBackend backend where #

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

Methods

mkPersistBackend :: BaseBackend backend -> backend #

This function is how we actually construct and tag a backend as having read or write capabilities. It should be used carefully and only when actually constructing a `backend`. Careless use allows us to accidentally run a write query against a read-only database.

Instances

IsPersistBackend SqlWriteBackend # |
Methods mkPersistBackend :: BaseBackend SqlWriteBackend -> SqlWriteBackend #
IsPersistBackend SqlReadBackend # |
Methods mkPersistBackend :: BaseBackend SqlReadBackend -> SqlReadBackend #
IsPersistBackend SqlBackend # |
Methods mkPersistBackend :: BaseBackend SqlBackend -> SqlBackend #

data SqlReadBackend #

An SQL backend which can only handle read queries

Instances

IsPersistBackend SqlReadBackend # |
Methods mkPersistBackend :: BaseBackend SqlReadBackend -> SqlReadBackend #
HasPersistBackend SqlReadBackend # |
Associated Types type BaseBackend SqlReadBackend :: * # Methods persistBackend :: SqlReadBackend -> BaseBackend SqlReadBackend #
data BackendKey SqlReadBackend # |
data BackendKey SqlReadBackend = SqlReadBackendKey { unSqlReadBackendKey :: Int64 }
type BaseBackend SqlReadBackend # |
type BaseBackend SqlReadBackend = SqlBackend

data SqlWriteBackend #

An SQL backend which can handle read or write queries

Instances

IsPersistBackend SqlWriteBackend # |
Methods mkPersistBackend :: BaseBackend SqlWriteBackend -> SqlWriteBackend #
HasPersistBackend SqlWriteBackend # |
Associated Types type BaseBackend SqlWriteBackend :: * # Methods persistBackend :: SqlWriteBackend -> BaseBackend SqlWriteBackend #
data BackendKey SqlWriteBackend # |
data BackendKey SqlWriteBackend = SqlWriteBackendKey { unSqlWriteBackendKey :: Int64 }
type BaseBackend SqlWriteBackend # |
type BaseBackend SqlWriteBackend = SqlBackend

readToUnknown :: Monad m => ReaderT SqlReadBackend m a -> ReaderT SqlBackend m a #

Useful for running a read query against a backend with unknown capabilities.

readToWrite :: Monad m => ReaderT SqlReadBackend m a -> ReaderT SqlWriteBackend m a #

Useful for running a read query against a backend with read and write capabilities.

writeToUnknown :: Monad m => ReaderT SqlWriteBackend m a -> ReaderT SqlBackend m a #

Useful for running a write query against an untagged backend with unknown capabilities.

type LogFunc = Loc -> LogSource -> LogLevel -> LogStr -> IO () #

data InsertSqlResult #

Constructors

ISRSingle Text |
ISRInsertGet Text Text |
ISRManyKeys Text [PersistValue] |

data Statement #

Constructors

Statement |
Fields stmtFinalize :: IO () stmtReset :: IO () stmtExecute :: [PersistValue] -> IO Int64 stmtQuery :: forall m. MonadIO m => [PersistValue] -> Acquire (Source m [PersistValue])

data SqlBackend #

Constructors

SqlBackend |
Fields connPrepare :: Text -> IO Statement connInsertSql :: EntityDef -> [PersistValue] -> InsertSqlResult table name, column names, id name, either 1 or 2 statements to run connInsertManySql :: Maybe (EntityDef -> [[PersistValue]] -> InsertSqlResult) SQL for inserting many rows and returning their primary keys, for backends that support this functioanlity. If `Nothing`, rows will be inserted one-at-a-time using `connInsertSql`. connUpsertSql :: Maybe (EntityDef -> Text -> Text) connStmtMap :: IORef (Map Text Statement) connClose :: IO () connMigrateSql :: [EntityDef] -> (Text -> IO Statement) -> EntityDef -> IO (Either [Text] [(Bool, Text)]) connBegin :: (Text -> IO Statement) -> IO () connCommit :: (Text -> IO Statement) -> IO () connRollback :: (Text -> IO Statement) -> IO () connEscapeName :: DBName -> Text connNoLimit :: Text connRDBMS :: Text connLimitOffset :: (Int, Int) -> Bool -> Text -> Text connLogFunc :: LogFunc

Instances

IsPersistBackend SqlBackend # |
Methods mkPersistBackend :: BaseBackend SqlBackend -> SqlBackend #
HasPersistBackend SqlBackend # |
Associated Types type BaseBackend SqlBackend :: * # Methods persistBackend :: SqlBackend -> BaseBackend SqlBackend #
data BackendKey SqlBackend # |
data BackendKey SqlBackend = SqlBackendKey { unSqlBackendKey :: Int64 }
type BaseBackend SqlBackend # |
type BaseBackend SqlBackend = SqlBackend

type SqlBackendCanRead backend = (IsSqlBackend backend, PersistQueryRead backend, PersistStoreRead backend, PersistUniqueRead backend) #

A constraint synonym which witnesses that a backend is SQL and can run read queries.

type SqlBackendCanWrite backend = (SqlBackendCanRead backend, PersistQueryWrite backend, PersistStoreWrite backend, PersistUniqueWrite backend) #

A constraint synonym which witnesses that a backend is SQL and can run read and write queries.

type SqlReadT m a = forall backend. SqlBackendCanRead backend => ReaderT backend m a #

Like `SqlPersistT` but compatible with any SQL backend which can handle read queries.

type SqlWriteT m a = forall backend. SqlBackendCanWrite backend => ReaderT backend m a #

Like `SqlPersistT` but compatible with any SQL backend which can handle read and write queries.

type IsSqlBackend backend = (IsPersistBackend backend, BaseBackend backend ~ SqlBackend) #

A backend which is a wrapper around `SqlBackend`.