snaplet-mysql-simple 0.1.0 → 0.1.1.2
raw patch · 4 files changed
+18/−15 lines, 4 filesdep ~containers
Dependency ranges changed: containers
Files
- resources/db/devel.cfg +2/−2
- snaplet-mysql-simple.cabal +2/−2
- src/Snap/Snaplet/Auth/Backends/MysqlSimple.hs +1/−1
- src/Snap/Snaplet/MysqlSimple.hs +13/−10
resources/db/devel.cfg view
@@ -1,8 +1,8 @@ host = "localhost" port = 3306 user = "mysql"-pass = ""-db = "testdb"+password = ""+dbname = "testdb" # Nmuber of distinct connection pools to maintain. The smallest acceptable # value is 1.
snaplet-mysql-simple.cabal view
@@ -1,5 +1,5 @@ name: snaplet-mysql-simple-version: 0.1.0+version: 0.1.1.2 synopsis: mysql-simple snaplet for the Snap Framework description: This snaplet contains support for using the MariaDB and MySQL database with a Snap Framework application via the mysql-simple@@ -38,7 +38,7 @@ base >= 4 && < 5, bytestring >= 0.9.1 && < 0.11, clientsession >= 0.7.2 && < 0.10,- containers >= 0.4 && < 0.5,+ containers >= 0.4 && < 0.6, configurator >= 0.2 && < 0.3, errors >= 1.4 && < 1.5, lens >= 3.0 && < 4.0,
src/Snap/Snaplet/Auth/Backends/MysqlSimple.hs view
@@ -77,7 +77,7 @@ key <- liftIO $ getKey (asSiteKey authSettings) let tableDesc = defAuthTable { tblName = authTable } let manager = MysqlAuthManager tableDesc $- pgPool $ db ^# snapletValue+ mysqlPool $ db ^# snapletValue -- ^ XXX liftIO $ createTableIfMissing manager rng <- liftIO mkRNG
src/Snap/Snaplet/MysqlSimple.hs view
@@ -28,7 +28,7 @@ > d <- nestSnaplet "db" db mysqlInit > return $ App ... d -Now you can use any of the postgresql-simple wrapper functions defined in this+Now you can use any of the mysql-simple wrapper functions defined in this module anywhere in your application handlers. For instance: > postHandler :: Handler App App ()@@ -48,9 +48,9 @@ > posts <- query_ "select * from blog_post" > ... -The first time you run an application with the postgresql-simple snaplet,+The first time you run an application with the mysql-simple snaplet, a configuration file @devel.cfg@ is created in the-@snaplets/postgresql-simple@ directory underneath your project root. It+@snaplets/mysql-simple@ directory underneath your project root. It specifies how to connect to your MySQL or MariaDB server and what user, password, and database to use. Edit this file and modify the values appropriately and you'll be off and running.@@ -84,7 +84,7 @@ , formatMany , formatQuery - -- Re-exported from postgresql-simple+ -- Re-exported from mysql-simple , M.Query , M.In(..) , M.Binary(..)@@ -92,12 +92,15 @@ , M.FormatError(..) , M.QueryError(..) , M.ResultError(..)+ , MB.MySQLError() , QueryResults(..) , QueryParams(..) , M.defaultConnectInfo ) where +import Debug.Trace+ import Prelude hiding ((++)) import Control.Lens -- (ASetter(), camelCaseFields, makeLensesWith, set) import Control.Monad.CatchIO (MonadCatchIO)@@ -130,10 +133,10 @@ infixr 5 ++ --------------------------------------------------------------------------------- | The state for the postgresql-simple snaplet. To use it in your app+-- | The state for the mysql-simple snaplet. To use it in your app -- include this in your application state and use pgsInit to initialize it. data Mysql = Mysql- { pgPool :: Pool M.Connection+ { mysqlPool :: Pool M.Connection -- ^ Function for retrieving the connection pool } @@ -141,9 +144,9 @@ ------------------------------------------------------------------------------ -- | Instantiate this typeclass on 'Handler b YourAppState' so this snaplet -- can find the connection source. If you need to have multiple instances of--- the postgres snaplet in your application, then don't provide this instance+-- the mysql snaplet in your application, then don't provide this instance -- and leverage the default instance by using \"@with dbLens@\" in front of calls--- to snaplet-postgresql-simple functions.+-- to snaplet-mysql-simple functions. class (MonadCatchIO m) => HasMysql m where getMysqlState :: m Mysql @@ -190,7 +193,7 @@ connInfo <- foldl modRecord (return M.defaultConnectInfo) params - return $ set connectSSL (Just sslOpts) $ set connectOptions connOpts connInfo+ trace (show connInfo) $ return $ set connectSSL (Just sslOpts) $ set connectOptions connOpts connInfo where params = [ ("host", set connectHost) , ("port", set connectPort . read)@@ -301,7 +304,7 @@ => (M.Connection -> IO b) -> m b withMysql f = do s <- getMysqlState- let pool = pgPool s+ let pool = mysqlPool s liftIO $ withResource pool f