serversession-backend-persistent-1.0.4: Storage backend for serversession using persistent and an RDBMS.

Safe HaskellNone
LanguageHaskell98

Web.ServerSession.Backend.Persistent

Description

Storage backend for serversession using persistent.

In order to use this backend, you have to include serverSessionDefs on your migration code. For example, the Yesod scaffold usually includes the following code:

-- On Model.hs
share [mkPersist sqlSettings, mkMigrate "migrateAll"]

-- On Application.hs
makeFoundation =
    ...
    runLoggingT (runSqlPool (runMigration migrateAll) pool) logFunc
    ...

You should changed those lines to:

-- On Model.hs
share [mkPersist sqlSettings, mkSave "entityDefs"]

-- On Application.hs
import qualified Data.Proxy as P -- tagged package, or base from GHC 7.10 onwards
import qualified Web.ServerSession.Core as SS
import qualified Web.ServerSession.Backend.Persistent as SS

mkMigrate "migrateAll" (SS.serverSessionDefs (P.Proxy :: P.Proxy SS.SessionMap) ++ entityDefs)

makeFoundation =
    ...
    runLoggingT (runSqlPool (runMigration migrateAll) pool) logFunc
    ...

If you're not using SessionMap, just change Proxy type above.

If you forget to setup the migration above, this session storage backend will fail at runtime as the required table will not exist.

Synopsis

Documentation

newtype SqlStorage sess Source #

SQL session storage backend using persistent.

Constructors

SqlStorage 

Fields

  • connPool :: ConnectionPool

    Pool of DB connections. You may use the same pool as your application.

Instances

(IsSessionData sess, PersistFieldSql (Decomposed sess)) => Storage (SqlStorage sess) Source # 

Associated Types

type SessionData (SqlStorage sess) :: *

type TransactionM (SqlStorage sess) :: * -> *

Methods

runTransactionM :: SqlStorage sess -> TransactionM (SqlStorage sess) a -> IO a

getSession :: SqlStorage sess -> SessionId (SessionData (SqlStorage sess)) -> TransactionM (SqlStorage sess) (Maybe (Session (SessionData (SqlStorage sess))))

deleteSession :: SqlStorage sess -> SessionId (SessionData (SqlStorage sess)) -> TransactionM (SqlStorage sess) ()

deleteAllSessionsOfAuthId :: SqlStorage sess -> AuthId -> TransactionM (SqlStorage sess) ()

insertSession :: SqlStorage sess -> Session (SessionData (SqlStorage sess)) -> TransactionM (SqlStorage sess) ()

replaceSession :: SqlStorage sess -> Session (SessionData (SqlStorage sess)) -> TransactionM (SqlStorage sess) ()

type TransactionM (SqlStorage sess) Source # 
type TransactionM (SqlStorage sess) = SqlPersistT IO
type SessionData (SqlStorage sess) Source # 
type SessionData (SqlStorage sess) = sess

serverSessionDefs :: forall sess. PersistEntity (PersistentSession sess) => Proxy sess -> [EntityDef] Source #

Entity definitions needed to generate the SQL schema for SqlStorage. Example using SessionMap:

serverSessionDefs (Proxy :: Proxy SessionMap)