{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module Database.Persist.SqlBackend.Internal where
import Data.List.NonEmpty (NonEmpty)
import Data.Text (Text)
import Data.Vault.Strict (Vault)
import qualified Data.Vault.Strict as Vault
import Database.Persist.Class.PersistStore
import Database.Persist.Names
import Database.Persist.SqlBackend.Internal.InsertSqlResult
import Database.Persist.SqlBackend.Internal.IsolationLevel
import Database.Persist.SqlBackend.Internal.MkSqlBackend
import Database.Persist.SqlBackend.Internal.Statement
import Database.Persist.SqlBackend.StatementCache
import Database.Persist.Types.Base
data SqlBackend = SqlBackend
{ SqlBackend -> Text -> IO Statement
connPrepare :: Text -> IO Statement
, SqlBackend -> EntityDef -> [PersistValue] -> InsertSqlResult
connInsertSql :: EntityDef -> [PersistValue] -> InsertSqlResult
, SqlBackend
-> Maybe (EntityDef -> [[PersistValue]] -> InsertSqlResult)
connInsertManySql :: Maybe (EntityDef -> [[PersistValue]] -> InsertSqlResult)
, SqlBackend
-> Maybe
(EntityDef -> NonEmpty (FieldNameHS, FieldNameDB) -> Text -> Text)
connUpsertSql :: Maybe (EntityDef -> NonEmpty (FieldNameHS, FieldNameDB) -> Text -> Text)
, SqlBackend -> Maybe (EntityDef -> Int -> Text)
connPutManySql :: Maybe (EntityDef -> Int -> Text)
, SqlBackend -> StatementCache
connStmtMap :: StatementCache
, SqlBackend -> IO ()
connClose :: IO ()
, SqlBackend
-> [EntityDef]
-> (Text -> IO Statement)
-> EntityDef
-> IO (Either [Text] [(Bool, Text)])
connMigrateSql
:: [EntityDef]
-> (Text -> IO Statement)
-> EntityDef
-> IO (Either [Text] [(Bool, Text)])
, SqlBackend
-> (Text -> IO Statement) -> Maybe IsolationLevel -> IO ()
connBegin :: (Text -> IO Statement) -> Maybe IsolationLevel -> IO ()
, SqlBackend -> (Text -> IO Statement) -> IO ()
connCommit :: (Text -> IO Statement) -> IO ()
, SqlBackend -> (Text -> IO Statement) -> IO ()
connRollback :: (Text -> IO Statement) -> IO ()
, SqlBackend -> FieldNameDB -> Text
connEscapeFieldName :: FieldNameDB -> Text
, SqlBackend -> EntityDef -> Text
connEscapeTableName :: EntityDef -> Text
, SqlBackend -> Text -> Text
connEscapeRawName :: Text -> Text
, SqlBackend -> Text
connNoLimit :: Text
, SqlBackend -> Text
connRDBMS :: Text
, SqlBackend -> (Int, Int) -> Text -> Text
connLimitOffset :: (Int,Int) -> Text -> Text
, SqlBackend -> LogFunc
connLogFunc :: LogFunc
, SqlBackend -> Maybe Int
connMaxParams :: Maybe Int
, SqlBackend -> Maybe (EntityDef -> Int -> Text)
connRepsertManySql :: Maybe (EntityDef -> Int -> Text)
, SqlBackend -> Vault
connVault :: Vault
, SqlBackend -> SqlBackendHooks
connHooks :: SqlBackendHooks
}
newtype SqlBackendHooks = SqlBackendHooks
{ SqlBackendHooks -> SqlBackend -> Text -> Statement -> IO Statement
hookGetStatement :: SqlBackend -> Text -> Statement -> IO Statement
}
emptySqlBackendHooks :: SqlBackendHooks
emptySqlBackendHooks :: SqlBackendHooks
emptySqlBackendHooks = SqlBackendHooks
{ hookGetStatement :: SqlBackend -> Text -> Statement -> IO Statement
hookGetStatement = \SqlBackend
_ Text
_ Statement
s -> Statement -> IO Statement
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Statement
s
}
mkSqlBackend :: MkSqlBackendArgs -> SqlBackend
mkSqlBackend :: MkSqlBackendArgs -> SqlBackend
mkSqlBackend MkSqlBackendArgs {IO ()
Text
IORef (Map Text Statement)
[EntityDef]
-> (Text -> IO Statement)
-> EntityDef
-> IO (Either [Text] [(Bool, Text)])
(Int, Int) -> Text -> Text
Text -> IO Statement
Text -> Text
LogFunc
FieldNameDB -> Text
EntityDef -> Text
EntityDef -> [PersistValue] -> InsertSqlResult
(Text -> IO Statement) -> IO ()
(Text -> IO Statement) -> Maybe IsolationLevel -> IO ()
connInsertSql :: MkSqlBackendArgs -> EntityDef -> [PersistValue] -> InsertSqlResult
connPrepare :: Text -> IO Statement
connInsertSql :: EntityDef -> [PersistValue] -> InsertSqlResult
connStmtMap :: IORef (Map Text Statement)
connClose :: IO ()
connMigrateSql :: [EntityDef]
-> (Text -> IO Statement)
-> EntityDef
-> IO (Either [Text] [(Bool, Text)])
connBegin :: (Text -> IO Statement) -> Maybe IsolationLevel -> IO ()
connCommit :: (Text -> IO Statement) -> IO ()
connRollback :: (Text -> IO Statement) -> IO ()
connEscapeFieldName :: FieldNameDB -> Text
connEscapeTableName :: EntityDef -> Text
connEscapeRawName :: Text -> Text
connNoLimit :: Text
connRDBMS :: Text
connLimitOffset :: (Int, Int) -> Text -> Text
connLogFunc :: LogFunc
connPrepare :: MkSqlBackendArgs -> Text -> IO Statement
connStmtMap :: MkSqlBackendArgs -> IORef (Map Text Statement)
connClose :: MkSqlBackendArgs -> IO ()
connMigrateSql :: MkSqlBackendArgs
-> [EntityDef]
-> (Text -> IO Statement)
-> EntityDef
-> IO (Either [Text] [(Bool, Text)])
connBegin :: MkSqlBackendArgs
-> (Text -> IO Statement) -> Maybe IsolationLevel -> IO ()
connCommit :: MkSqlBackendArgs -> (Text -> IO Statement) -> IO ()
connRollback :: MkSqlBackendArgs -> (Text -> IO Statement) -> IO ()
connEscapeFieldName :: MkSqlBackendArgs -> FieldNameDB -> Text
connEscapeTableName :: MkSqlBackendArgs -> EntityDef -> Text
connEscapeRawName :: MkSqlBackendArgs -> Text -> Text
connNoLimit :: MkSqlBackendArgs -> Text
connRDBMS :: MkSqlBackendArgs -> Text
connLimitOffset :: MkSqlBackendArgs -> (Int, Int) -> Text -> Text
connLogFunc :: MkSqlBackendArgs -> LogFunc
..} =
SqlBackend
{ connMaxParams :: Maybe Int
connMaxParams = Maybe Int
forall a. Maybe a
Nothing
, connRepsertManySql :: Maybe (EntityDef -> Int -> Text)
connRepsertManySql = Maybe (EntityDef -> Int -> Text)
forall a. Maybe a
Nothing
, connPutManySql :: Maybe (EntityDef -> Int -> Text)
connPutManySql = Maybe (EntityDef -> Int -> Text)
forall a. Maybe a
Nothing
, connUpsertSql :: Maybe
(EntityDef -> NonEmpty (FieldNameHS, FieldNameDB) -> Text -> Text)
connUpsertSql = Maybe
(EntityDef -> NonEmpty (FieldNameHS, FieldNameDB) -> Text -> Text)
forall a. Maybe a
Nothing
, connInsertManySql :: Maybe (EntityDef -> [[PersistValue]] -> InsertSqlResult)
connInsertManySql = Maybe (EntityDef -> [[PersistValue]] -> InsertSqlResult)
forall a. Maybe a
Nothing
, connVault :: Vault
connVault = Vault
Vault.empty
, connHooks :: SqlBackendHooks
connHooks = SqlBackendHooks
emptySqlBackendHooks
, connStmtMap :: StatementCache
connStmtMap = MkStatementCache -> StatementCache
mkStatementCache (MkStatementCache -> StatementCache)
-> MkStatementCache -> StatementCache
forall a b. (a -> b) -> a -> b
$ IORef (Map Text Statement) -> MkStatementCache
mkSimpleStatementCache IORef (Map Text Statement)
connStmtMap
, IO ()
Text
[EntityDef]
-> (Text -> IO Statement)
-> EntityDef
-> IO (Either [Text] [(Bool, Text)])
(Int, Int) -> Text -> Text
Text -> IO Statement
Text -> Text
LogFunc
FieldNameDB -> Text
EntityDef -> Text
EntityDef -> [PersistValue] -> InsertSqlResult
(Text -> IO Statement) -> IO ()
(Text -> IO Statement) -> Maybe IsolationLevel -> IO ()
connPrepare :: Text -> IO Statement
connInsertSql :: EntityDef -> [PersistValue] -> InsertSqlResult
connClose :: IO ()
connMigrateSql :: [EntityDef]
-> (Text -> IO Statement)
-> EntityDef
-> IO (Either [Text] [(Bool, Text)])
connBegin :: (Text -> IO Statement) -> Maybe IsolationLevel -> IO ()
connCommit :: (Text -> IO Statement) -> IO ()
connRollback :: (Text -> IO Statement) -> IO ()
connEscapeFieldName :: FieldNameDB -> Text
connEscapeTableName :: EntityDef -> Text
connEscapeRawName :: Text -> Text
connNoLimit :: Text
connRDBMS :: Text
connLimitOffset :: (Int, Int) -> Text -> Text
connLogFunc :: LogFunc
connPrepare :: Text -> IO Statement
connInsertSql :: EntityDef -> [PersistValue] -> InsertSqlResult
connClose :: IO ()
connMigrateSql :: [EntityDef]
-> (Text -> IO Statement)
-> EntityDef
-> IO (Either [Text] [(Bool, Text)])
connBegin :: (Text -> IO Statement) -> Maybe IsolationLevel -> IO ()
connCommit :: (Text -> IO Statement) -> IO ()
connRollback :: (Text -> IO Statement) -> IO ()
connEscapeFieldName :: FieldNameDB -> Text
connEscapeTableName :: EntityDef -> Text
connEscapeRawName :: Text -> Text
connNoLimit :: Text
connRDBMS :: Text
connLimitOffset :: (Int, Int) -> Text -> Text
connLogFunc :: LogFunc
..
}
instance HasPersistBackend SqlBackend where
type BaseBackend SqlBackend = SqlBackend
persistBackend :: SqlBackend -> BaseBackend SqlBackend
persistBackend = SqlBackend -> BaseBackend SqlBackend
SqlBackend -> SqlBackend
forall a. a -> a
id
instance IsPersistBackend SqlBackend where
mkPersistBackend :: BaseBackend SqlBackend -> SqlBackend
mkPersistBackend = BaseBackend SqlBackend -> SqlBackend
SqlBackend -> SqlBackend
forall a. a -> a
id