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 , known as a Pool
SqlBackendConnectionPool, 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.
Constructors
SqlBackendconnPrepare :: Text -> IO StatementThis function should prepare a Statement in the target database, which should allow for efficient query reuse.
connInsertSql :: EntityDef -> [PersistValue] -> InsertSqlResultThis function generates the SQL and values necessary for performing an insert against the database.
connInsertManySql :: Maybe (EntityDef -> [[PersistValue]] -> InsertSqlResult)SQL for inserting many rows and returning their primary keys, for backends that support this functionality. If Nothing, rows will be inserted one-at-a-time using connInsertSql.
connUpsertSql :: Maybe (EntityDef -> NonEmpty (FieldNameHS, FieldNameDB) -> Text -> Text)Some databases support performing UPSERT _and_ RETURN entity in a single call.
This field when set will be used to generate the UPSERT+RETURN sql given * an entity definition * updates to be run on unique key(s) collision
When left as Nothing, we find the unique key from entity def before * trying to fetch an entity by said key * perform an update when result found, else issue an insert * return new entity from db
connPutManySql :: Maybe (EntityDef -> Int -> Text)Some databases support performing bulk UPSERT, specifically "insert or replace many records" in a single call.
This field when set, given * an entity definition * number of records to be inserted should produce a PUT MANY sql with placeholders for records
When left as Nothing, we default to using
defaultPutMany.connStmtMap :: StatementCacheconnClose :: IO ()Close the underlying connection.
connMigrateSql :: [EntityDef] -> (Text -> IO Statement) -> EntityDef -> IO (Either [Text] [(Bool, Text)])connBegin :: (Text -> IO Statement) -> Maybe IsolationLevel -> IO ()A function to begin a transaction for the underlying database.
connCommit :: (Text -> IO Statement) -> IO ()A function to commit a transaction to the underlying database.
connRollback :: (Text -> IO Statement) -> IO ()A function to roll back a transaction on the underlying database.
connEscapeFieldName :: FieldNameDB -> TextA function to extract and escape the name of the column corresponding to the provided field.
connEscapeTableName :: EntityDef -> TextA function to extract and escape the name of the table corresponding to the provided entity. PostgreSQL uses this to support schemas.
connEscapeRawName :: Text -> TextA function to escape raw DB identifiers. MySQL uses backticks, while PostgreSQL uses quotes, and so on.
connNoLimit :: TextconnRDBMS :: TextA tag displaying what database the SqlBackend is for. Can be used to differentiate features in downstream libraries for different database backends.
connLimitOffset :: (Int, Int) -> Text -> TextAttach a 'LIMIT/OFFSET' clause to a SQL query. Note that LIMIT/OFFSET is problematic for performance, and indexed range queries are the superior way to offer pagination.
connLogFunc :: LogFuncA log function for the SqlBackend to use.
connMaxParams :: Maybe IntSome databases (probably only Sqlite) have a limit on how many question-mark parameters may be used in a statement
connRepsertManySql :: Maybe (EntityDef -> Int -> Text)Some databases support performing bulk an atomic+bulk INSERT where constraint conflicting entities can replace existing entities.
This field when set, given * an entity definition * number of records to be inserted should produce a INSERT sql with placeholders for primary+record fields
When left as Nothing, we default to using
defaultRepsertMany.connVault :: VaultCarry arbitrary payloads for the connection that may be used to propagate information into hooks.
connHooks :: SqlBackendHooksInstrumentation hooks that may be used to track the behaviour of a backend.
Instances32PersistQueryRead, PersistQueryWrite, HasPersistBackend, IsPersistBackend, PersistCore, PersistStoreRead, …
PersistQueryRead SqlBackendDefined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistQuery · orphanPersistQueryWrite SqlBackendDefined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistQuery · orphanHasPersistBackend SqlBackendDefined in persistent-2.14.6.3 · Database.Persist.SqlBackend.InternalIsPersistBackend SqlBackendDefined in persistent-2.14.6.3 · Database.Persist.SqlBackend.InternalPersistCore SqlBackendDefined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanPersistStoreRead SqlBackendDefined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanPersistStoreWrite SqlBackendDefined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanPersistUniqueRead SqlBackendDefined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistUnique · orphanPersistUniqueWrite SqlBackendDefined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistUnique · orphanBackendCompatible SqlBackend SqlReadBackendDefined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanBackendCompatible SqlBackend SqlWriteBackendDefined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanBackendCompatible SqlBackend SqlBackendDefined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanBounded (BackendKey SqlBackend)Defined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanEnum (BackendKey SqlBackend)Defined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanEq (BackendKey SqlBackend)Defined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanIntegral (BackendKey SqlBackend)Defined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanNum (BackendKey SqlBackend)Defined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanOrd (BackendKey SqlBackend)Defined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanRead (BackendKey SqlBackend)Defined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanReal (BackendKey SqlBackend)Defined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanShow (BackendKey SqlBackend)Defined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanGeneric (BackendKey SqlBackend)Defined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanFromJSON (BackendKey SqlBackend)Defined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanToJSON (BackendKey SqlBackend)Defined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanFromHttpApiData (BackendKey SqlBackend)Defined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanToHttpApiData (BackendKey SqlBackend)Defined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanPathPiece (BackendKey SqlBackend)Defined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanPersistField (BackendKey SqlBackend)Defined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphanPersistFieldSql (BackendKey SqlBackend)Defined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphantype Rep (BackendKey SqlBackend) = D1 ('MetaDataDefined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphan"BackendKey"
"Database.Persist.Sql.Orphan.PersistStore"
"persistent-2.14.6.3-31NeHlMbZ2g6XoXmn516lt"
'True) (C1 ('MetaCons"SqlBackendKey"
'PrefixI 'True) (S1 ('MetaSel ('Just"unSqlBackendKey"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64)))data BackendKey SqlBackendDefined in persistent-2.14.6.3 · Database.Persist.Sql.Orphan.PersistStore · orphantype BaseBackend SqlBackend = SqlBackendDefined in persistent-2.14.6.3 · Database.Persist.SqlBackend.Internal